我想创建特定于列的系列,例如A列只有两个系列,B列只有三个系列。我已经通过数据完成了此操作,但是它为没有值序列留了空白。它将在A列中为系列3创建空白。 我在屏幕截图中定义了我的问题,请参考。 预先谢谢你。
var data = JSON.parse(document.getElementById("chartdata").innerHTML);
var dataprovider = data.data;
var serieslist = data.test_type_list;
var chart = am4core.create("chartdiv", am4charts.XYChart);
chart.data = dataprovider;
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "suject";
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.renderer.minGridDistance = 30;
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
for (var i = 0; i < serieslist.length; i++) {
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueY = serieslist[i];
series.dataFields.categoryX = "suject";
series.name = serieslist[i];
series.columns.template.tooltipText = serieslist[i] + ":[bold]{valueY}[/]";
series.columns.template.fillOpacity = .8;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//www.amcharts.com/lib/4/core.js"></script>
<script src="//www.amcharts.com/lib/4/charts.js"></script>
<div id="chartdiv"></div>
<div id="chartdata">{"data":[{"suject":"maths","fa1":"70"},{"suject":"maths","fa2":"20"},{"suject":"science","fa4":"10"},{"suject":"science","fa3":"80"}],"test_type_list":["fa1","fa2","fa3","fa4"]}</div>