2016-02-26 87 views
1

我有一个返回图表列表的WebService。这是我的类图的结构:Highstock不同的时间值区间

public class Point 
{ 
    public string Date { get; set; } 
    public float Value { get; set; } 
} 

public class Serie 
{ 
    public string Port { get; set; } 
    public string Name { get; set; } 
    public string Unit { get; set; } 
    public List<Point> Data { get; set; } 
} 

public class Chart 
{ 
    public string Unit { get; set; } 

    public List<Serie> Series { get; set; } 
} 

public List<Chart> charts; 

我用HighStock,在JS脚本来显示从我图的列表我的所有图表。 我希望按单位分组我的系列,并为每个单元创建一个新的yAxis以显示相同的单元系列(请参见下面的图像)。

这是从js文件的代码:

<script type="text/javascript"> 
    $(document).ready(function() { 
     $.ajax({ 
      type: "POST", 
      contentType: "application/json; charset=utf-8", 
      url: "WebService.asmx/Channels", 
      data: "{}", 
      dataType: "json", 
      success: function (Charts) { 
       document.getElementById("debug").innerHTML = Charts.d; 
       Charts = Charts.d; 

       var margin = 40, 
       top = 100, 
       height = 160, 
       count = 0; 

       // Generals options for chart 
       var options = { 
        credits: { enabled: false }, 
        chart: { 
         renderTo: chart, 
         zoomType: 'x', 
         alignTicks: false 
        }, 
        legend: { 
         enabled: true 
        }, 
        title: { 
         text: 'Values' 
        }, 
        tooltip: { 
         valueDecimals: 2, 
         shared: true 
        }, 
        xAxis: {  
         ordinal: false 
        }, 
        yAxis: [], 
        series: [] 
       }; 

       // Go through Charts 
       for (var i in Charts) { 

         // Infos for the yAxis of the serie 
         // ------------------- 
         options.yAxis.push({ 
          title: { 
           text: "[" + Charts[i].Unit + "]" 
          }, 
          labels: { 
           x: 30, 
           y: 4, 
           align: "right", 
           format: '{value} ' + Charts[i].Unit 
          }, 
          offset: 0, 
          top: top, 
          height: height, 
          opposite: true 
         }); 

         // Go through Series in a Charts 
         for (var j in Charts[i].Series) { 


          // Infos for the serie 
          // ------------------- 
          var data = []; 

          // Go through Data in Series of a Charts 
          for (var k in Charts[i].Series[j].Data) { 
           var point = new Array(new Date(Charts[i].Series[j].Data[k].Date).getTime(), Charts[i].Series[j].Data[k].Value); 
           data.push(point); 
          }// End: Go through Data in Series of a Charts 

          count = Number(i); 

          // Add a serie and these attributes 
          options.series.push({ 
           name: Charts[i].Series[j].Name, 
           data: data, 
           tooltip: { 
            valueSuffix: ' ' + Charts[i].Series[j].Unit, 
            valueDecimals: 3 
           }, 
           yAxis: count 
          }); 

         }// End: Go through Series in a Charts 

         count++; 
         top += height + margin; 

       }// End: Go through Charts 

       options.chart.height = top + 190; 

       Highcharts.StockChart(options); 
      }, 
      error: function (xhr, thrownError) { 
       //alert("Error : " + xhr.status + "\nMessage : \n" + xhr.responseText); 
       document.getElementById("debug").innerHTML = "Error : " + xhr.status + "\nMessage : \n" + xhr.responseText; 
      } 
     }); 
    }); 
</script> 

如果我运行代码:

Blank page no chart

,我有错误是:

Uncaught TypeError: Cannot read property 'clientX' of undefined -> highstock.js:177

和也(有时)这个错误:

Uncaught TypeError: Cannot read property 'info' of undefined -> highstock.js:342 (not sur about the #line)

如果我删除意甲与不同的时间间隔,或者如果取消勾选V batt的系列(与不同的间隔意甲)工作原理:

All my charts are displayed

我花了很多时间互联网上和StackOverflow上找到我的问题,但...没什么问题...

编辑

- >我们可以在同一个图表上绘制的最大意义是什么?
- >我们可以在同一个图表上绘制的最大点是多少?

非常感谢您的反馈。

最好的问候,

吊杆

问题解决了!

问题是由我的web服务发送的时代数据在后台,HighStock需要毫秒级。

+0

没有像系列或点的数量这样的限制(除非它不会是浏览器的矫枉过正)。你可以试试Highstock的主分支吗?见http://github.highcharts.com/highstock.src.js - 我想我遇到过类似的问题。此外,任何机会重新jsfiddle问题?您可以使用静态数据,而不是AJAX。 –

回答

1

问题解决!

问题是由我的web服务发送的时代数据在后台,HighStock需要毫秒级。