1

我只是从 jqplot 切换到 highcharts,因为我找不到 jqplot 问题的答案。

我的问题:我想从 json 字符串中绘制以下结果。此字符串包含以下格式的数据对:(yyyy00kw年份为 4 位,00 用于填充,周数为 2 位)和一个值(可以格式化为浮点数)。因为该x对的值可能会更改为yyyymmdd(year month day) 或yyyywwdd(year week day) 它必须是一个字符串。

我的 json 字符串包含以下内容:

[
  [
    ["20050043",12.800000190735],
    ["20050044",17.39999961853],
    ["20050045",10.10000038147],
    ["20050046",5.9000000953674],
    ["20050048",4.6999998092651],
    ["20050049",9.8999996185303],
    ["20050050",9.1999998092651],
    ["20050051",8.3999996185303],
    ["20050052",2.0999999046326],
    ["20060001",2.7000000476837],
    ["20060002",-1.1000000238419],
    ["20060004",2],
    ["20060005",4.9000000953674],
    ["20060006",6.8000001907349],
    ["20060007",6.0999999046326],
    ["20060009",4.3000001907349],
    ["20060010",3.4000000953674],
    ["20060011",8.1999998092651],
    ["20060012",7],
    ["20060017",11.60000038147],
    ["20060018",21.60000038147],
    ["20060019",24.799999237061],
    ["20060020",16.700000762939],
    ["20060021",0],
    ["20060022",0],
    ["20060024",0],
    ["20060025",18.10000038147],
    ["20060026",20.200000762939],
    ["20060052",2.9000000953674],
    ["20070001",0],
    ["20070019",0],
    ["20070020",0],
    ["20070024",0],
    ["20070025",0],
    ["20070026",0],
    ["20070027",0],
    ["20070028",0],
    ["20070029",0],
    ["20070030",0],
    ["20070031",0],
    ["20070032",0],
    ["20070033",0],
    ["20070034",0],
    ["20070035",0],
    ["20070036",0],
    ["20070037",0],
    ["20070038",0],
    ["20070039",0],
    ["20070040",0],
    ["20070041",0],
    ["20070042",0],
    ["20070043",0],
    ["20070044",0],
    ["20070045",0],
    ["20070046",0],
    ["20070047",0],
    ["20070048",0],
    ["20070049",0],
    ["20070050",0],
    ["20070051",0],
    ["20070052",0],
    ["20080001",0],
    ["20080002",0],
    ["20080003",0],
    ["20080004",0],
    ["20080005",0],
    ["20080006",0],
    ["20080007",0],
    ["20080008",0],
    ["20080009",0],
    ["20080010",0],
    ["20080012",0],
    ["20080013",0],
    ["20080017",0],
    ["20080018",0],
    ["20080019",0],
    ["20080020",0],
    ["20080021",0],
    ["20080022",0],
    ["20080023",0],
    ["20080024",0],
    ["20080025",0],
    ["20080026",0],
    ["20080027",0],
    ["20080028",0],
    ["20080029",0],
    ["20080030",0],
    ["20080031",0],
    ["20080034",0],
    ["20080035",0],
    ["20080036",0],
    ["20080037",0],
    ["20080038",0],
    ["20080039",0],
    ["20080040",0],
    ["20080041",0],
    ["20080042",0],
    ["20080043",0],
    ["20080044",0],
    ["20080045",0],
    ["20080046",0],
    ["20080047",0],
    ["20080048",0],
    ["20080049",0],
    ["20080050",0],
    ["20080051",0],
    ["20080052",0],
    ["20090001",0],
    ["20090002",0],
    ["20090003",0],
    ["20090004",0],
    ["20090005",0],
    ["20090006",0],
    ["20090024",0],
    ["20090025",0],
    ["20090026",0],
    ["20090028",0],
    ["20090029",0],
    ["20090030",0],
    ["20090031",0],
    ["20090032",0],
    ["20090033",0],
    ["20090034",0],
    ["20090035",0],
    ["20090036",0],
    ["20090037",0],
    ["20090038",0],
    ["20090039",0],
    ["20090040",0],
    ["20090041",0],
    ["20090042",0],
    ["20090043",0],
    ["20090044",0],
    ["20090045",0],
    ["20090046",0],
    ["20090047",0],
    ["20090048",0],
    ["20090049",0],
    ["20090050",0],
    ["20090051",0],
    ["20090052",0],
    ["20090053",0],
    ["20100001",0],
    ["20100002",0],
    ["20100003",0],
    ["20100004",0],
    ["20100005",0],
    ["20100006",0],
    ["20100007",0],
    ["20100008",0],
    ["20100009",0],
    ["20100010",0],
    ["20100011",0],
    ["20100012",0],
    ["20100013",0],
    ["20100014",0],
    ["20100015",0],
    ["20100016",0],
    ["20100017",0],
    ["20100018",0],
    ["20100019",0],
    ["20100020",0],
    ["20100021",0],
    ["20100022",0],
    ["20100023",0],
    ["20100024",0],
    ["20100025",0],
    ["20100026",0],
    ["20100027",0],
    ["20100028",0],
    ["20100029",0],
    ["20100030",0],
    ["20100031",0],
    ["20100032",0],
    ["20100033",0],
    ["20100034",0],
    ["20100035",0],
    ["20100036",0],
    ["20100037",0],
    ["20100038",0],
    ["20100039",0],
    ["20100040",0],
    ["20100041",0],
    ["20100042",0],
    ["20100043",0],
    ["20100044",0],
    ["20100045",0],
    ["20100046",0],
    ["20100047",0],
    ["20100048",0],
    ["20100049",0],
    ["20100050",0],
    ["20100051",0],
    ["20100052",0],
    ["20100053",0],
    ["20110001",0],
    ["20110002",0],
    ["20110003",0],
    ["20110004",0],
    ["20110005",0],
    ["20110006",0],
    ["20110007",0],
    ["20110008",0],
    ["20110009",0],
    ["20110010",0],
    ["20110014",0],
    ["20110015",0],
    ["20110016",0],
    ["20110017",0],
    ["20110018",0],
    ["20110019",0],
    ["20110020",0],
    ["20110021",0],
    ["20110022",0],
    ["20110023",0],
    ["20110024",0],
    ["20110025",0],
    ["20110026",0],
    ["20110027",0],
    ["20110028",0],
    ["20110029",0],
    ["20110030",0],
    ["20110031",0],
    ["20110032",0],
    ["20110033",0],
    ["20110034",0],
    ["20110035",0],
    ["20110036",0],
    ["20110039",0],
    ["20110043",0],
    ["20110044",0],
    ["20110045",0],
    ["20110046",0],
    ["20110047",0],
    ["20110048",0],
    ["20110049",0],
    ["20110052",0],
    ["20120001",0],
    ["20120002",0],
    ["20120003",0],
    ["20120004",0],
    ["20120005",0],
    ["20120006",0],
    ["20120007",0],
    ["20120009",0],
    ["20120010",0],
    ["20120013",0],
    ["20120014",0],
    ["20120015",0],
    ["20120016",0],
    ["20120017",0]
  ]
]

这是我的javascript代码:

<script class="code" type="text/javascript">
  var data = [];
  var chart;
  $(document).ready(function() {
    //hier geht es los
    $.getJSON("120925_sql_bauen.php", function(json) {
      chart = new Highcharts.Chart({
        chart: {
          renderTo: 'chart1',
          type: 'line'
        },
        title: {
          text: 'Wetterdatenprojekt'
        },
        xAxis: {
          //categories: []
        },
        yAxis: {
          title: {
            text: 'aktuelle Wetterwerte'
          },
          plotLines: [{
            value: 0,
            width: 1
          }]
        },
        series: json
      });
    });
  });
</script>

不幸的是,highcharts 没有显示任何情节。我希望,highcharts 在字符串方面没有与 jqplot 相同的问题 :-(

4

2 回答 2

3

问题是您尝试直接使用您的回复。您需要“删除”一层数组。那data应该是json[0]

我更新了我的例子:http: //jsfiddle.net/GgNmY/2/

关于前面的注意,值应该是数字仅适用于 Y 轴(至少在早期版本的 Highcharts 中)。

编辑:这里是提取数据点(值)和类别。

var data = [];
var cats = [];
json[0].forEach(function(point){
    data.push(point[1]);
    cats.push(point[0]);
});

这是一个运行示例:http: //jsfiddle.net/GgNmY/3/

于 2013-04-28T08:20:47.457 回答
0

在 Highchart 中,您可以以 JSON 输入的形式设置您的系列:数据对象。在这种情况下,如果 JSON 输入采用以下形式:

[
[1,12],
[2,5],
[3,18],
....
[10,22]
]

然后可以在图表定义中添加以下属性:

series:[{
       data: json
}]

这是正在运行的JSFiddle示例

于 2015-03-29T18:36:23.283 回答