Flot Bar Chart design

匿名 (未验证) 提交于 2019-12-03 01:23:02

问题:

I've made this bar chart http://imageshack.com/a/img901/7186/cnOfhh.png, and the code for it is:

//compute & mark average color for (var i = 0; i = zdata[i].TimePlayed) {         zdata[i]['Color'] = 'green';     } else {         zdata[i]['Color'] = 'red';     } } //localsitelist var element = {     rt: 'D',     Id: rid,     courselist: clist,     selcourseId: selCid,     selcourse: selCname,     cartlist: wData,     selSiteId: lsid,     selsite: sitename,     dataList: zdata }; //, carts: _mVM.availableCarts()}; // //if rid exists, is update, else its new var found = -1; for (var k = 0; k 

and the BarChart function:

function BarChart(id, data) {      $.plot(id, data, {         series: {             bars: {                 show: true,                 barWidth: 0.6,                 align: "center"             }         },         stack: true,         xaxis: {             mode: "categories",             tickLength: 0         }     }); } 

The problem is that I can't manage to get something like this https://imageshack.us/i/expGGpOkp, the little line should be zdata[i].TargetTime. I've tried something using stacked bar chart idea but the result was way different... What am I doing wrong? Can anyone help me with a suggestion to start with to get the same bar chart like in the last image?

回答1:

Here is something like your second picture using another bar dataseries where the start and end of the bars are the same thereby reducing them to lines, you don't need to stack any of the bars just give them the right y-values (fiddle):

$(function () {      var dataBarsRed = {         data: [             [2, 3], ],         label: 'Bars in Red',         color: 'red'     };     var dataBarsGreen = {         data: [             [1, 2],             [3, 1],             [4, 3]         ],         label: 'Bars in Green',         color: 'green'     };     var dataLines = {         data: [             [1, 3, 3],             [2, 3.5, 3.5],             [3, 1.5, 1.5],             [4, 2.5, 2.5]         ],         label: 'Lines',         color: 'navy',         bars: {             barWidth: 0.5         }     };      var plot = $.plot("#placeholder", [dataBarsRed, dataBarsGreen, dataLines], {         points: {             show: false         },         lines: {             show: false         },         bars: {             show: true,             align: 'center',             barWidth: 0.6         },         grid: {             hoverable: true,             autoHighlight: true         },         xaxis: {             min: 0,             max: 5         },         yaxis: {             min: 0,             max: 5         }     });  }); 


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