jqPlot - 有没有办法只标记特定的条形图?

时间:2012-04-27 15:45:56

标签: jqplot

我的jqPlot图包含200个垂直条。我将短路条的颜色设为绿色,最长的是红色,其他颜色为黄色。

如果我这样做

pointLabels: {
    show: true
}

然后我得到200个点标签,这些标签都被压扁在一起而且不可读。

是否可以仅标记最短和最长的条形图?

我已阅读此页但未找到解决方案:

http://www.jqplot.com/docs/files/plugins/jqplot-pointLabels-js.html#$.jqplot.PointLabels.seriesLabelIndex

3 个答案:

答案 0 :(得分:2)

为什么不在将'ticks'传递给图表时将一些刻度线设置为空字符串""。 另外,我建议您使用此设置旋转刻度线的标签:

tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickOptions: {
  angle: -45
}

答案 1 :(得分:1)

如果有人感兴趣,这就是我所做的:

var shortest = 5; // find shortest somehow
var longest = 10; // find longest somehow

var myLabels = [];
for (var i = 0; i < histogramData.length; i++) {
    myLabels[i] = "";
}

myLabels[shortest] = shortest;
myLabels[longest] = longest;    

然后设置以下jqPlot选项:

pointLabels: {
    show: true,
    labels: myLabels,
    hideZeros: true
}

唯一的缺点是这会使缩放比较慢当你有许多像我的情况一样的x轴条目时。

答案 2 :(得分:0)

据说jqplot不支持智能轴渲染,这意味着截断标签,使相邻标签不会碰撞在一起。但您可以使用角度选项,以便标签不会发生冲突。但对于大量数据,它也无法正常工作。 jqplot仅计算必要的轴刻度,而不管图表将要绘制的容器大小。

 If you have worked with Google chart or like thing you can see they are not prioritizing axis ticks or something, they calculate the axis according to data and the plot area both. So the answer is even if you angle the tick labels you will come up with a limit. I'm not saying cheers! for this

抱歉!..

相关问题