I am not able to align bars with labels. This happens because I have multiple series.
我无法将条形与标签对齐。这是因为我有多个系列。
I need:
1) bar charts with 5 boxes
1)带有5个方框的条形图
2) each box represents seperate item, should have seperate color
2)每个盒子代表单独的项目,应该有单独的颜色
3) legend should have 5 items in it
3)传说中应该有5个项目
4) bar charts shoudl be aligned with labels (in the best sollution bar charts would be wide)
4)条形图应与标签对齐(在最佳溶胶条形图中会很宽)
I have achieved first three, but I cannot achive fourth.
我已经取得了前三名,但我无法取得第四名。
Here is what I have:
这是我有的:
var chartData = [
[['Portfolio Risk', 1]],
[['Model Risk', 4]],
[['Recovery Risk', 3]],
[['Capability Risk', 1]],
[['Forward flow risk', 5]]
];
var ticks = ['Portfolio Risk', 'Model Risk', 'Recovery Risk', 'Capability Risk', 'Forward flow risk'];
plot2 = $.jqplot('chart1', chartData, {
seriesColors: ['#85802b', '#00749F', '#73C774', '#C7754C', '#17BDB8'],
seriesDefaults: {
renderer: $.jqplot.BarRenderer,
},
axesDefaults: {
tickRenderer: $.jqplot.CanvasAxisTickRenderer,
},
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
tickOptions: {
angle: 90
},
},
yaxis: {
tickOptions: {
formatString: '%d'
},
max: 5,
min: 0
}
},
legend: {
show: true,
placement: 'outside',
labels: ticks
},
});
JSFiddle: http://jsfiddle.net/renatevidruska/27EPk/
As you see bars are not aligned.
如您所见,条形图未对齐。
1 个解决方案
#1
6
This can be done by simply adding a few options to your seriesDefaults, like so:
这可以通过简单地向seriesDefaults添加一些选项来完成,如下所示:
seriesDefaults: {
renderer: $.jqplot.BarRenderer,
rendererOptions: {
barWidth: 60,
barPadding: -60
}
Note that if you want to center the bars, simply make the barPadding value the negative of the barWidth value. In this case, I set the width to 60, so I then set the padding to -60. Here is the fiddle.
请注意,如果要使条形图居中,只需将barPadding值设为barWidth值的负数即可。在这种情况下,我将宽度设置为60,因此我将填充设置为-60。这是小提琴。
#1
6
This can be done by simply adding a few options to your seriesDefaults, like so:
这可以通过简单地向seriesDefaults添加一些选项来完成,如下所示:
seriesDefaults: {
renderer: $.jqplot.BarRenderer,
rendererOptions: {
barWidth: 60,
barPadding: -60
}
Note that if you want to center the bars, simply make the barPadding value the negative of the barWidth value. In this case, I set the width to 60, so I then set the padding to -60. Here is the fiddle.
请注意,如果要使条形图居中,只需将barPadding值设为barWidth值的负数即可。在这种情况下,我将宽度设置为60,因此我将填充设置为-60。这是小提琴。