how to change the constant barwidth in JQuery flot bar char to variable barwidth

≡放荡痞女 提交于 2019-12-12 05:12:39

问题


I am plotting a dynamic barchart using flot. I have managed to plot with constant barwidth. Now I want the barwidth to vary based on the output of my analysis. I set var options = { series: { bars:{show:true, barWidth: BarWidth, fillColor: "lightgreen", fill: true } In this code, BarWidth is a javascript variable. My bar starts to plot and gets overlapped when my BarWidth changes. Does anyone has any clue how I can solve my problem?

Thank you in advance!

@DNS This is my plot function

function plot_status(statusData, no_strips)
        {
                new_data =  new_data.concat([statusData]);  

                var options = {
                series: {
                bars:{show:true,
                barWidth: no_strips*72,
                fillColor: "lightgreen",
             fill: true
                }
                },
                grid: {clickable: true, hoverable: true, borderWidth: 1 }   
            };
                $(document).ready(function() {

                  chart1 = $.plot($("#placeholder"),
                  [{
                    data:  new_data,
                    threshold: {
                            below: 0,
                            color: "red"
                        },
                    color:  "black",
                    xaxis: {ticks:8,minTickSize: 1},
                    yaxis: {min:-1,max:3,tickSize:1},
                    grid: { borderWidth: 1  }
                    }],options)

                 });    

Every four seconds, statusData and no_strips change. new_data contains a series of data that is plotted. The barchar grows with time as long as statusData is concatenated to new_data. no_strips determine the barWidth of each plot of the barchart. I will also include sample of barchart I would like to produce.

With a constant barWidth this is what I produce

This is my data: [[0, 1], [1200, 1], [2400, -1], [3600, 1], ... ]; rather I was sending it for my above plot.

This is the the data I want to plot [[0, 1], [72, 1], [144, -1], [432, 1],[504,1],...]every[a,b]` is added every four seconds.

来源:https://stackoverflow.com/questions/17147081/how-to-change-the-constant-barwidth-in-jquery-flot-bar-char-to-variable-barwidth

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