当 xaxis 为文本时,如何显示 jqplot 堆积条形图?
我似乎无法让我的 jqplot 条形图堆叠起来。我有以下代码:
// Pass/Fail rates per request
$.jqplot('passFailPerRequestStats', [passRate, failRate], {
title: 'Automation Pass Count Per Test Plan',
//stackSeries: true,
seriesDefaults: {
renderer: $.jqplot.BarRenderer,
renderOptions: { barMargin: 25 },
pointLabels: { show: true, stackedValue: true }
},
axesDefaults: {
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickOptions: {
angle: -30,
fontSize: '10pt'
}
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer
}
}
});
这成功地显示了两个系列的并排条形图。但是,当我尝试通过取消注释 stackSeries: true 来堆叠它们时,所有条形图都将从图表中取出(并且所有点标签都显示在 Y 轴标签上)。
我做错了什么?
I can't seem to get my jqplot bar graph to stack. I have the following code:
// Pass/Fail rates per request
$.jqplot('passFailPerRequestStats', [passRate, failRate], {
title: 'Automation Pass Count Per Test Plan',
//stackSeries: true,
seriesDefaults: {
renderer: $.jqplot.BarRenderer,
renderOptions: { barMargin: 25 },
pointLabels: { show: true, stackedValue: true }
},
axesDefaults: {
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
tickOptions: {
angle: -30,
fontSize: '10pt'
}
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer
}
}
});
This is successfully displaying a side by side bar graph for both series. However, when I try to stack them by uncommenting out the stackSeries: true,
all bar graphs are taken off the graph (and all point labels are displayed on the Y axis labels).
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在 rendererOptions 对象中包含 barDirection。
如果后面有更多选项,请务必在最后一个括号后包含逗号。
堆栈还要求指定 xaxis。
你的数据结构应该是这样的。每个项目中的前导数字表示 X 轴。
在“ticks:”选项中使用月份(或任何您想要的文本),如下所示。
You need to include barDirection in your rendererOptions object.
Be sure to include the comma after the last bracket, if more options follow this.
The stack requires the xaxis to be specified also.
Your data structure should look like this. with the leading number in each item indicating the X axis.
Use the months (or whatever text you want) in the ticks: option like so.
我添加这个解决方案是因为我发现之前发布的解决方案在我的环境中不起作用(尽管它确实让我走上了正轨,所以感谢@Jack) - 以下内容在运行 jqPlot 1.0 的 ASP.NET MVC3 网站上为我工作.8r1250 与 JQuery 1.9.1 和 JQuery UI 1.1O.3:
对我来说,添加渲染
rendererOptions{...}
是不必要的。我还发现
seriesDefaults > 下的
节点没有任何效果,相反,我必须取消根节点下的stackedValue: true
pointLabelsstackSeries: true
注释。我的最终代码:
还要确保包含以下链接:
希望这对将来的人有帮助
I am adding this solution as I found the previously posted one to not work in my environment (although it did put me on the right track, so thanks @Jack) - The following worked for me on an ASP.NET MVC3 site running jqPlot 1.0.8r1250 with JQuery 1.9.1 and JQuery UI 1.1O.3:
For me adding render
rendererOptions{...}
turned out to be unnecessary.I also found that
stackedValue: true
under theseriesDefaults > pointLabels
node had no effect, instead I had to uncommentstackSeries: true
under the root node.My final code:
Also make sure you include the following links:
Hope this of help to someone in the future