繁体   English   中英

Stackbar图表在浮动图表中重叠

[英]Stackbar chart is overlapping in flot chart

在浮点图中正确绘制堆积的条形图时需要帮助。 不知道为什么我的酒吧不堆叠,我正在动态地准备我的数据集。 以下是我的数据格式。

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

图表选项

{
    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
    }
}

请帮忙。 这是一个塞子链接

注意 :在11/26/14中有2个任务,分别是2个和3个计数,因此基本上,条形图应在y轴上绘制到5,但是它是重叠的。

我花了很多时间在这个问题上,最终可以为您解决所有问题。

首先,您忘记在索引中包含<script src="http://cdnjs.cloudflare.com/ajax/libs/flot/0.8.2/jquery.flot.stack.min.js"></script> 这意味着堆积图并没有真正绘制出来。 其次,我稍微清理了您的数据,并删除了数据中不必要的重复声明。 然后,在包含堆栈脚本之后,我修复了鼠标悬停时显示的任务数量不正确的问题。

最后,我试图找出为什么flot重叠,并得出以下结论:flot不知道如何处理长度可变的数据序列。 这意味着,如果您有3个数据系列,每个数据系列的长度不同,则这些条看上去似乎是随机的,彼此重叠。 但是,如果您确保所有系列的长度均相同,则条形图堆叠不会出现问题。

我认为最好的解决方案是在服务器端确保所有系列的长度相同,并且每个数据滴答处都有一个值。 理想情况下,您应在所有系列中添加零值,这些系列在数据滴答处缺少值,并确保所有系列的长度相同。

这是我的解决方案的代码:

数据和选项:

    $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",
    }];

这里显示了我的解决方案的plnkr

有一份关于Google Code的报告,描述了该问题和可能的解决方法:

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

以我为例,也有必要对数据滴答进行排序

暂无
暂无

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

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