0

我有一些数据要连接到我的 highcharts。

到目前为止,我在 z3s.js 中获取数据

KpiChartTrendForZxController = function($scope, $http, LocationService) {
  var GetKpiChartTrendForZx, dates;
  GetKpiChartTrendForZx = function(containerId) {
    var serviceUrl;
    serviceUrl = iSee.ServiceLocator.KpiChartTrendZxForContainer(containerId);
    return $http.get(serviceUrl).success(function(data) {
      return $scope.trendForZx = data;
    });
  };

我的数据看起来像: series: [ { name: "Z3 from ZB - Sum", data: [["04/04/2013 08:00", 5], ["05/04/2013 08:00", 5 ], ["06/04/2013 08:00", 5], ["07/04/2013 08:00", 5], ["08/04/2013 08:00", 5], ["09 /04/2013 08:00", 5], ["10/04/2013 08:00", 5], ["11/04/2013 08:00", 5], ["12/04/2013 08 :00", 5], ["13/04/2013 08:00", 5], ["14/04/2013 08:00", 5], ["15/04/2013 08:00", 5 ], ["16/04/2013 08:00", 5], ["17/04/2013 08:00", 5], ["18/04/2013 08:00", 5]]

如何将它们添加到我的系列中?数据:值[i]:名称[i],数据[i]

数据[i]:时间[j],值[j]

谢谢

4

2 回答 2

0

您的数据应该是时间戳,即以毫秒为单位的时间。所以代替这个

 ["04/04/2013 08:00", 5],

它应该是

 [Date.UTC(2014,3,4,8), 5],

返回正确的格式。

于 2013-06-28T11:02:23.023 回答
0

我找到了答案:

var dateEndLabel, dateStartLabel, i, j, lastDate, seriesData, x, y;
  i = 0;
  seriesData = new Array();
  lastDate = data[i].Values.length - 1;
  dateStartLabel = data[i].Values[0].Time;
  dateEndLabel = data[i].Values[lastDate].Time;
  while (i < data.length) {
    seriesData[i] = [];
    j = 0;
    x = [];
    y = [];
    while (j < data[i].Values.length) {
      x = data[i].Values[j].Time;
      y = data[i].Values[j].Value;
      seriesData[i].push([x, y]);
      j++;
    }
    i++;
  }

然后将它们添加到我的 highchart 系列中:

 series: [
      {
        name: data[0].Name,
        data: seriesData[0]
      }, {
        name: data[1].Name,
        data: seriesData[1]
      }, {
        name: data[2].Name,
        data: seriesData[2]
      }, {
        name: data[3].Name,
        data: seriesData[3]
      }, {
        name: data[4].Name,
        data: seriesData[4]
      }, {
        name: data[5].Name,
        data: seriesData[5]
      }
    ],  

我的问题现在已经解决了,但我想我可以将我的代码缩减为一个更小的系列。无论如何,它现在可以工作了,我在 highcharts 中还有另一个 callenges :)

于 2013-07-03T16:53:22.817 回答