0

我目前正在使用下面的图表来显示数据。该图表当前读取json嵌入到javascript.

我需要能够从文件any.json而不是嵌入json对象中读取。我一直在寻找某种类型的文档,但一无所获。

任何帮助表示赞赏。

any.json看起来像这样:

[{x: "January", value: 10000},{x: "February", value: 12000},{x: "March", value: 18000}]

这是当前的html:

anychart.onDocumentReady(function() {
  chart = anychart.fromJson({
    chart: {
      type: "line",
      series: [{
        seriesType: "spline",
        data: [{
            x: "January",
            value: 10000
          },
          {
            x: "February",
            value: 12000
          },
          {
            x: "March",
            value: 18000
          },
          {
            x: "April",
            value: 11000
          },
          {
            x: "May",
            value: 9000
          }
        ]
      }],
      container: "container"
    }
  }).draw();
});
html,
body,
#container {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}
<script src="https://cdn.anychart.com/js/7.13.1/anychart-bundle.min.js"></script>
<link rel="stylesheet" href="https://cdn.anychart.com/css/7.13.1/anychart-ui.min.css" />
<div id="container"></div>
<script src="https://cdn.anychart.com/js/7.13.1/anychart-bundle.min.js"></script>
<link rel="stylesheet" href="https://cdn.anychart.com/css/latest/anychart-ui.min.css">

4

1 回答 1

0

您可以使用https://api.anychart.com/7.13.1/anychart.data#loadJsonFile方法。有一个示例:https ://playground.anychart.com/api/7.13.1/modules/anychart.data.loadJsonFile-plain

于 2017-05-21T09:47:51.720 回答