我正在使用flot.js和flot的类别插件来创建使用类别而不是x轴刻度的数值的条形图。
当我只使用一个系列时,它非常出色:http://jsfiddle.net/tFy46/1/。
然而,当我使用多个系列时,结果会叠加在一起而不是并排。
我的代码:
var graphCanvas = $('#graph-canvas'),
graphData = [
{
"color": "#f00",
"data": [
["1st Nov to 3rd Nov", 5.304752, 4.04044192]
]
},
{
"color": "#0f0",
"data": [
["1st Nov to 3rd Nov", 8.80990656, 3.86548928],
["11th Nov to 15th Nov", 37.89327872, -2.1734158399999997]
]
}
],
graphOptions = {
legend: {
show: false
},
series: {
bars: {
align: 'center',
fill: 0.7,
show: true
}
},
xaxis: {
mode: 'categories'
}
};
$.plot(graphCanvas, graphData, graphOptions);
(之前曾在how to draw multiple bar charts grouped by category with flot js提出此问题,但接受“使用flot'类别'插件”的答案并不是一个有用的答案。)
答案 0 :(得分:7)
不“使用flot'类别'插件”是一个有用的答案吗? :)
我放弃它并且只是自己标记数据(无论如何这都是插件下的所有插件):
graphData = [
{
"color": "#f00",
"data": [
[0, 5.304752, 4.04044192]
]
},
{
"color": "#0f0",
"data": [
[0.5, 8.80990656, 3.86548928],
[1.5, 37.89327872, -2.1734158399999997]
]
}
],
graphOptions = {
legend: {
show: false
},
series: {
bars: {
align: 'center',
fill: 0.7,
show: true,
barWidth: 0.45
}
},
xaxis: {
ticks: [[0.25,"1st Nov to 3rd Nov"],[1.5,"11th Nov to 15th Nov"]]
}
};
更新了fiddle。