将数据从数组传递到 amchart 雷达图表系列

Passing data from array to amchart radar chart series

我想传递来自数据的数据 table 我已添加到数组,但我看不到如何应用它。我已经查看了文档来执行此操作,但无济于事。

代码如下:

/* START AMCHART CODE*/ 
//////////////////////////////////////////////////////////////////////////////
/* Set themes */
am4core.useTheme(am4themes_dark);
am4core.useTheme(am4themes_animated);

/* Create chart instance */
var chart = am4core.create("js_chart", am4charts.RadarChart);

/* Add data */
chart.data = [{
  "region": "National",
  "value1": 501,
  "value2": 250,
  "value3": 250

}, {
  "region": "Region",
  "value1": 301,
  "value2": 222,
  "value3": 250
}, {
  "region": "PJ Lowrie",
  "value1": 266,
  "value2": 179,
  "value3": 250
}, {
  "region": "Tameside",
  "value1": 165,
  "value2": 298,
  "value3": 250
}, {
  "region": "Salford",
  "value1": 139,
  "value2": 299,
  "value3": 250
}, {
  "region": "Manchester",
  "value1": 336,
  "value2": 185,
  "value3": 250
}];

/* Read data from chartdata */
console.log(chartdata);

var chartData2 = new Array();
    for (var i = 0; i < chartdata.length; i++) {
    var category= new Object();
    category.category=chartdata[i].items[0];
    category.Done=chartdata[i].items[1];
    category.Begun=chartdata[i].items[2];
    category.None=chartdata[i].items[3];
    chartData2.push(category);  
}
/* End Read data from chartdata */
//chart.data =chartData2;

/* Create axes */
chart.dataProvider=chartData2;
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "region";

var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());

valueAxis.min = 0;
valueAxis.max = 1000; 

/* Create and configure series */
var series1 = chart.series.push(new am4charts.RadarColumnSeries());
series1.dataFields.valueY = "value1";
series1.dataFields.categoryX = "region";
series1.name = "None";
series1.strokeWidth = 0;
series1.columns.template.tooltipText = "Series: {name}\nCategory: {categoryX}\nValue: {valueY}";
series1.sequencedInterpolation = true;
series1.sequencedInterpolationDelay = 100;
series1.stacked = true;
series1.fill = "red";

var series2 = chart.series.push(new am4charts.RadarColumnSeries());
series2.dataFields.valueY = "value2";
series2.dataFields.categoryX = "region";
series2.name = "Begun";
series2.strokeWidth = 0;
series2.columns.template.tooltipText = "Series: {name}\nCategory: {categoryX}\nValue: {valueY}";
series2.sequencedInterpolation = true;
series2.sequencedInterpolationDelay = 100;
series2.stacked = true;
series2.fill = "gold";

var series3 = chart.series.push(new am4charts.RadarColumnSeries());
series3.dataFields.valueY = "value3";
series3.dataFields.categoryX = "region";
series3.name = "Done";
series3.strokeWidth = 0;
series3.columns.template.tooltipText = "Series: {name}\nCategory: {categoryX}\nValue: {valueY}";
series3.sequencedInterpolation = true;
series3.sequencedInterpolationDelay = 100;
series3.stacked = true;
series3.fill = "green";

/* Add legend */
chart.legend = new am4charts.Legend();

/* Add cursor */
chart.cursor = new am4charts.RadarCursor();

    /*END AMCHART CODE*/

我有一个雷达图,使用硬编码数据可以完美地工作,但我想传递数组中的数据。 谢谢 J

感谢您的回复。我已经通过这个演示为自己解决了这个问题并应用了一些其他逻辑 amcharts.com/demos/line-graph/

/* Read data from chartdata */

var chartData2 = [];
var region=0;
var Done=0;
var None ='';
    for (var i = 0; i < chartdata.length; i++) {
    region=chartdata[i].items[0];
    Done=chartdata[i].items[1];
    Begun=chartdata[i].items[2];
    None=chartdata[i].items[3];
    chartData2.push({region:region, Done: Done, Begun: Begun, None: None}); 
}

chart.data = chartData2;`