简体   繁体   English

多个系列的高图表

[英]HighCharts with Multiple Series

Below is my table data and I have converted the same to JSON and linked it to HighCharts . 以下是我的表格数据,我已将其转换为JSON并将其链接到HighCharts。 But I'm not sure how to show the different series in the spline .My series will be "LIST" and on X axis the "Time" and Y will carry Status of each series 0 and 1 respectively. 但是我不确定如何在样条曲线中显示不同的序列。我的序列将是“ LIST”,在X轴上,“ Time”和Y将分别携带每个序列0和1的状态。

The series "LIST" can be any as of now it shows "A" ,"B","C" respectively , it can have more or less.Based on the available series the chart should be plotted.I have pasted the JSON data of the table too. 系列“ LIST”现在可以是任何一个,它分别显示“ A”,“ B”,“ C”,可以有更多或更少。应根据可用系列绘制图表。我粘贴了JSON数据桌子的

LIST  Time   Status
 A     22:05   0
 B     22:10   1
 C     22:30   1
 A     22:40   0
 C     22:50   1
 B     22:60   1

 [{"LIST":"A","Status":"0","Time":"22:05"},{"LIST":"B","Status":"1","Time":"22:10"},
 {"LIST":"C","Status":"1","Time":"22:30"},{"LIST":"A","Status":"0","Time":"22:40"},
 {"LIST":"C","Status":"1","Time":"22:50"},{"LIST":"B","Status":"1","Time":"22:60"}]

I have tried the following in the code but to no avail. 我已经在代码中尝试了以下内容,但无济于事。 Below is the code 下面是代码

 var handlerURL = "http://localhost:50687/Handler.ashx;
         $.ajax({
             url: handlerURL,
             type: "GET",
             datatype: "json",
             contentType: 'application/json',
             complete: function (json) {
                 var jsonData = jQuery.parseJSON(json.responseText);
                 var List = _.pluck(jsonData, 'List');
                 period = _.pluck(jsonData, 'Time');
                 status = _.pluck(jsonData, 'Status');
                 //                     var dateTime = [];
                 //                     for (i = 0; i < period.length; i++) {
                 //                         dateTime = (period[i]);
                 //                     }
             }

         });
          options = {
             chart: {
                 renderTo: 'container',
                 type: 'spline',
                 marginRight: 130,
                 marginBottom: 50
             },

             setOptions: ({
                 global: { useUTC: true }
             }),

             title: {
                 text: 'Live Data',
                 x: -20
             },
             subtitle: {
                 text: '',
                 x: -30
             },
             xAxis: {
                 categories: period,
                 type: 'datetime',
                 tickPixelInterval: 100,
                 plotLines: [{
                     width: 5,
                     color: '#808080'
                 }]
             },
             yAxis: {
                 min: 0, max: 1,
                 title: {
                     text: 'Status'
                 },
                 plotLines: [{
                     value: 0,
                     width: 1,
                     color: '#808080'
                 }]
             },
             tooltip: {
                 formatter: function () {
                     return '<b>' + this.series.name + '</b><br/>' +
                        this.x + ': ' + this.y;
                 }
             },
             legend: {
                 layout: 'vertical',
                 align: 'right',
                 verticalAlign: 'top',
                 x: -10,
                 y: 100,
                 borderWidth: 0
             },
             series: [{
                 data: status
             }]
         }

         options.xAxis.categories = period;
         chart = new Highcharts.Chart(options);

In general there is a couple of advices: 通常,有一些建议:

  • you can use or categorized axis, or datetime, not both in the same time: 您可以同时使用或分类轴或日期时间,但不能同时使用:

      xAxis: { // categories: period, - remove that? type: 'datetime', tickPixelInterval: 100, plotLines: [{ width: 5, color: '#808080' }] }, 
  • to create multiple series, you need multiple series objects in array, just like this: 要创建多个系列,您需要数组中的多个系列对象,如下所示:

      series: [{ data: status_1 }, { data: status_2 }] 
  • status_1/status_2 etc. should be that format: status_1 / status_2等应采用以下格式:

      [[timestamp1, value1], [timestamp2, value2], ... , [timestampN, vlaueN]] 

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

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