简体   繁体   English

用线绘制透明条形图?

[英]Flot transparent bar graph with lines?

I've had great success getting flot to create line graphs, in part due to the quality of responses on this forum! 在创建线形图方面,我取得了很大的成功,部分原因是该论坛上的回复质量很高!

However either I'm trying to do something special, or can't figure out the search terms. 但是,或者我正在尝试做一些特别的事情,或者无法弄清楚搜索词。 I'm trying to plot two datasets on the same graph: 我正在尝试在同一张图上绘制两个数据集:

Line graphs that represent temperatures Bar graphs that represent when a device is active (it is either a 1 or a 0 value in the RRD). 代表温度的线形图代表设备处于活动状态(RRD中的值为1或0)的条形图。 I want these as transparent background bars so I can see if the device is triggering properly and how long it is on for. 我希望将它们作为透明的背景条,以便我可以查看设备是否正确触发以及其开启时间。

I have two problems; 我有两个问题;

  • I can't get the device data to show as transparent graphs. 我无法将设备数据显示为透明图形。 Just line data 只是行数据
  • I haven't tried merging the two datasets into a single graph yet. 我还没有尝试将两个数据集合并为一个图形。 I'd like the device bar data to show as a full vertical bar, right now the y-axis is from 0 to 1.2, so there is a gap at the top of the graph. 我希望设备条数据显示为完整的垂直条,现在y轴的范围是0到1.2,因此图形顶部有一个间隙。 When I try and use a second axis, I get the numbers on the right hand side, but the the line graph doesn't show it's axis correctly. 当我尝试使用第二条轴时,我会在右侧获得数字,但折线图无法正确显示其轴。

Here is a snippet of the data that I'm working with: 这是我正在使用的数据的摘要:

"data" : [
     {
        "bars" : {
           "fillColor" : {
              "colors" : [
                 {
                    "opacity" : 1
                 },
                 {
                    "opacity" : 1
                 }
              ]
           },
           "lineWidth" : 0,
           "show" : "true"
        },
        "color" : "blue",
        "data" : [
           [
              "1421280000000",
              "0"
           ],
           [
              "1421452800000",
              "0"
           ],
           [
              "1421625600000",
              "0"
           ],
           [
              "1421798400000",
              "1"
           ],
           [
              "1421971200000",
              "1"
           ],
           [
              "1422144000000",
              "1"
           ],
           [
              "1422316800000",
              "0"
           ],
           [
              "1422489600000",
              "0"
           ],
           [
              "1422662400000",
              "0"
           ],
           [
              "1422835200000",
              "0"
           ]
        ]
    }
        "label" : "D1",
        "yaxes" : 1
     },
     {
        "bars" : {
           "fillColor" : {
              "colors" : [
                 {
                    "opacity" : 1
                 },
                 {
                    "opacity" : 1
                 }
              ]
           },
           "lineWidth" : 0,
           "show" : "true"
        },
        "color" : "red",
        "data" : [
           ]
              "1421280000000",
              "1"
           ],
           [
              "1421452800000",
              "1"
           ],
           [
              "1421625600000",
              "1"
           ],
           [
              "1421798400000",
              "0"
           ],
           [
              "1421971200000",
              "1"
           ],
           [
              "1422144000000",
              "0"
           ],
           [
              "1422316800000",
              "0"
           ],
           [
              "1422489600000",
              "0"
           ],
           [
              "1422662400000",
              "1"
           ],
           [
              "1422835200000",
              "0"
           ]
        ],
        "label" : "D2",
        "yaxes" : 1
     }  
  ],

Your bars have the default width of 1 x axis unit and since your x values are so big this means that the bars have a width of 0 pixels. 条形图的默认宽度为1 x轴单位,由于x值太大,这意味着条形图的宽度为0像素。 Add something like this to your bars options to make them wider and proceed from there: 在您的bars选项中添加类似的内容,以使其更宽并从此处继续:

"barWidth": 24 * 60 * 60 * 1000, // 1 day in milliseconds

Here is a fiddle with the full example. 这是完整示例的摆弄 You will see that some bars hide each other, to counter this look at the side-by-side or stacked-bars plugins on the flot site. 您会看到一些酒吧相互隐藏起来,以对抗在flot网站上并排或堆叠的酒吧插件

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

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