如何在amchart的图形中插入字符串

时间:2019-01-11 05:19:25

标签: amcharts

我有一个字符串变量myGraph

newarr.push({"type": "smoothedLine", 
             "valueField": selected_ids1[i]});

var myGraph ='[' + newarr.map(JSON.stringify).join() + ']';
myGraph = myGraph.replace(/\s/g, '');   

我如何将此变量插入到amchart图形中

    var NewChart = AmCharts.makeChart("chartdiv", {
  "type": "serial",
  "addClassNames": true,
  "startDuration": 0.4,
  "theme": "light",
  "dataDateFormat": "HH:mm:ss",
  "trendLines": [],
  "applyGapValue": 0,


  "graphs": myGraph.charAt,
  "guides": [],
    "categoryField": "date

",

1 个答案:

答案 0 :(得分:0)

如文档中所述,

graphsan array。您不能直接给它分配一个字符串。您需要将字符串解析回数组:

AmCharts.makeChart("chartdiv", {
  // ...
  graphs: JSON.parse(myGraphs),
  // ...
});

我不明白为什么您会遇到麻烦,为什么您只能将其直接分配给自己,却无法将项目推入newArr并将其字符串化为一个单独的变量。

AmCharts.makeChart("chartdiv", {
  // ...
  graphs: newarr,
  // ...
});