Flot - bar chart with individual colors and labels

大憨熊 提交于 2019-12-24 20:28:20

问题


I use flot to display simple bar charts. I have single dataset like [ [0,5], [1,6], [2,3], [4,1] ] and I am using this simple code:

myChart = $.plot($('#graphFlot'), [{
        data: mdata,
        bars: { show: true, fill: 0.9 }
    }]
   );

Now I would like to display various colors and labels for each bar. Example bar chart here is how it should look like.

I've browsed through many examples and documentation and still do not know how to set this. Is this possible?


回答1:


Put each bar in its own series and give each series a different label.




回答2:


var mdata = [ [0,5], [1,6], [2,3], [4,1]]; var bar_array = [];

$.each(mdata, function(i, bar) { bar_array.push({ data: [bar], bars: { show: true, fill:0.9 } }); });

myChart = $.plot($('#graphFlot'), bar_array);




回答3:


To my knowledge there's no setting in Flot or Flotr2 that allows you to do this. I managed to get this done by making changes to the code that renders the barchart in flotr2.js



来源:https://stackoverflow.com/questions/11827404/flot-bar-chart-with-individual-colors-and-labels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!