简体   繁体   English

Stackbar图表在浮动图表中重叠

[英]Stackbar chart is overlapping in flot chart

Need help in properly plotting a stacked bar chart in flot chart. 在浮点图中正确绘制堆积的条形图时需要帮助。 Not sure why my bars are not stacking, I am preparing my dataset dynamically. 不知道为什么我的酒吧不堆叠,我正在动态地准备我的数据集。 Below is my data format. 以下是我的数据格式。

[{
     "data": [
         [1415491200000, 1],
         [1415577600000, 2],
         [1415750400000, 1]
     ],
     "label": "MANG",
     "bars": {
         "show": "true",
         "barWidth": 36000000,
         "fillColor": "#FFEE11",
         "order": 1,
         "align": "center"
     },
     "stack": true
 }]

Chart options 图表选项

{
    xaxis: {
        mode: "time",
        timeformat: "%m/%d/%y",
        minTickSize: [1, "day"]
    },
    grid: {
        labelMargin: 10,
        hoverable: true,
        borderWidth: 0
    },
    series: {
        stack: true
    },
    colors: colorCodes,
    tooltip: true,
    legend: {
        show: true,
        noColumns: 0, // number of colums in legend table
        labelFormatter: null, // fn: string -> string
        labelBoxBorderColor: "#888", // border color for the little label boxes
        container: "#adoptionLegendContainer", // container (as jQuery object) to put legend in, null means default on top of graph
        position: "nw", // position of default legend container within plot
        margin: [5, 10], // distance from grid edge to default legend container within plot
        backgroundOpacity: 0 // set to 0 to avoid background
    }
}

Please help. 请帮忙。 here is a plunker link 这是一个塞子链接

Note : In 11/26/14 there are 2 tasks of 2 and 3 counts respectively, so basically bar should plot till 5 in yaxis, but it is overlapped. 注意 :在11/26/14中有2个任务,分别是2个和3个计数,因此基本上,条形图应在y轴上绘制到5,但是它是重叠的。

I spent alot of time on this question and can finally a post solution to all of your problems. 我花了很多时间在这个问题上,最终可以为您解决所有问题。

Firstly you forgot to include <script src="http://cdnjs.cloudflare.com/ajax/libs/flot/0.8.2/jquery.flot.stack.min.js"></script> in your index. 首先,您忘记在索引中包含<script src="http://cdnjs.cloudflare.com/ajax/libs/flot/0.8.2/jquery.flot.stack.min.js"></script> This meant that stacked charts werent really getting drawn. 这意味着堆积图并没有真正绘制出来。 Secondly I cleaned up your data a bit and removed unnecessary double declarations in your data. 其次,我稍微清理了您的数据,并删除了数据中不必要的重复声明。 I then fixed your mouseover displaying the incorrect amount of tasks after I included the stack script. 然后,在包含堆栈脚本之后,我修复了鼠标悬停时显示的任务数量不正确的问题。

Lastly I tried to find out why flot was overlapping and came to the following conclusion: flot does not know how to handle data series with varying length. 最后,我试图找出为什么flot重叠,并得出以下结论:flot不知道如何处理长度可变的数据序列。 This means that if you have 3 data series each with a different length, the bars overwright each other seemingly random. 这意味着,如果您有3个数据系列,每个数据系列的长度不同,则这些条看上去似乎是随机的,彼此重叠。 If however you make sure that all series are the same length, the bars stack without problems. 但是,如果您确保所有系列的长度均相同,则条形图堆叠不会出现问题。

The best solution for this in my opinion is to make sure on the server side, that all your series are the same length and have a value at every data tick . 我认为最好的解决方案是在服务器端确保所有系列的长度相同,并且每个数据滴答处都有一个值。 Ideally you would add zero values into all series that have missing values at data ticks and make sure that all series are the same length this way. 理想情况下,您应在所有系列中添加零值,这些系列在数据滴答处缺少值,并确保所有系列的长度相同。

Here is the code for my solution: 这是我的解决方案的代码:

Data and options: 数据和选项:

    $scope.tasksRunChartOptions = {

      xaxis: {
        mode: "time",
        timeformat: "%m/%d/%y",
        minTickSize: [1, "day"]
      },
      grid: {
        labelMargin: 10,
        hoverable: true,
        borderWidth: 0
      },
      series: {
        stack: true,
        "bars":{
                "show":"true",
                "barWidth":36000000,
                "order":1,
                "align":"center"
            }
      },
      colors: colorCodes,
      tooltip: true,
            legend: {
                show: true,
                noColumns: 0, // number of colums in legend table
                labelFormatter: null, // fn: string -> string
                labelBoxBorderColor: "#888", // border color for the little label boxes
                container: "#adoptionLegendContainer", // container (as jQuery object) to put legend in, null means default on top of graph
                position: "nw", // position of default legend container within plot
                margin: [5, 10], // distance from grid edge to default legend container within plot
                backgroundOpacity: 0 // set to 0 to avoid background
            }
    };

    $scope.translate = function(value) {
      var monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
      var myDate = new Date(value);
      return myDate.getDate() + " " + monthNames[myDate.getMonth()] + " " + myDate.getFullYear();
    }

    $scope.reportTasksRunRange = {
      min: 1415059200000,
      max: 1418342400000, 
      floor: 1415059200000,
      ceil: 1418342400000,
      step: (1412467200000 - 1412380800000)
    };


   $scope.tasksRunData = [
    {
        "data":
        [[1415491200000,1],[1415577600000,3],[1415664000000,2],[1415750400000,1],[1415836800000,3],[1415923200000,1],[1416009600000,7],[1416096000000,2],[1416268800000,2],[1416441600000,1],[1416528000000,12],[1416787200000,1],[1416873600000,1],[1416960000000,3],[1417046400000,2],[1417132800000,2],[1417392000000,4],[1417478400000,3],[1417737600000,1],[1417910400000,4],[1417996800000,6],[1418083200000,2],[1418169600000,4],[1418256000000,3]],
        "label":"ICS-MANG"
    },
  {
        "data":
        [[1415491200000,2],[1415577600000,3],[1415664000000,3],[1415750400000,1],[1415836800000,1],[1415923200000,2],[1416009600000,15],[1416096000000,4],[1416268800000,1],[1416441600000,3],[1416528000000,1],[1416787200000,1],[1416873600000,1],[1416960000000,3],[1417046400000,3],[1417132800000,2],[1417392000000,4],[1417478400000,3],[1417737600000,3],[1417910400000,1],[1417996800000,6],[1418083200000,5],[1418169600000,4],[1418256000000,3]],
        "label":"Neeraj_secure"
    },
    {
        "data":
        [[1415491200000,2],[1415577600000,3],[1415664000000,3],[1415750400000,1],[1415836800000,1],[1415923200000,3],[1416009600000,1],[1416096000000,2],[1416268800000,4],[1416441600000,1],[1416528000000,1],[1416787200000,1],[1416873600000,1],[1416960000000,3],[1417046400000,4],[1417132800000,2],[1417392000000,4],[1417478400000,3],[1417737600000,7],[1417910400000,20],[1417996800000,6],[1418083200000,4],[1418169600000,4],[1418256000000,3]],
        "label":"Bkrishna",
    }];

And a plnkr displaying my solution is here. 这里显示了我的解决方案的plnkr

There's a report opened on Google Code, describing the issue and possible fixes: 有一份关于Google Code的报告,描述了该问题和可能的解决方法:

https://code.google.com/p/flot/issues/detail?id=247 https://code.google.com/p/flot/issues/detail?id=247

In my case it was also neccessary to sort the data ticks . 以我为例,也有必要对数据滴答进行排序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM