How to render this bar chart with flot

2019-03-27 13:28发布

Can you render a bar chart like this using flot?

Example chart

Do I need to create the dataset manually to get this result, instead of using mode: 'time' ?

标签: flot
1条回答
淡お忘
2楼-- · 2019-03-27 14:25

Actually pretty easy to produce using flot.

var options = {
     series: {
         bars: {
             show: true,
             barWidth: 15778463000, // 1/2 year in milliseconds
             align: 'center'
         },
     },
     yaxes: {
         min: 0
     },
     xaxis: {
         mode: 'time',
         timeformat: "%y",
         tickSize: [1, "year"],
         autoscaleMargin: .10 // allow space left and right
     }
 };

 $(function() {
     $.plot($('#placeholder'), [[[1230768000*1000, 100], //[seconds * 1000 = milli, y value]
                                [1262304000*1000, 200],
                                [1293840000*1000, 300]]], options);
 });

Produces:

enter image description here

查看更多
登录 后发表回答