我在角度6中使用Amcharts 4 我将使用多个数据创建折线图 当用户单击按钮从服务器获取数据并添加到系列并显示在图表上时 我的数据是月份名称和值 首先,我定义全局图表变量
private chart: am4charts.XYChart;
i配置图表
let chart = am4core.create("chartdiv", am4charts.XYChart);
chart.paddingRight = 20;
let monthAxis = chart.xAxes.push(new am4charts.CategoryAxis());
monthAxis.renderer.grid.template.location = 0;
monthAxis.dataFields.category = "month";
monthAxis.title.text = 'ماه'
let valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.tooltip.disabled = true;
valueAxis.renderer.minWidth = 35;
chart.cursor = new am4charts.XYCursor();
并且通过从服务器获取数据来添加系列
this.adminService.getSaleReport(this.fillterValues).subscribe((res) => {
let series1 = chart.series.push(new am4charts.LineSeries());
series1.data = res;
series1.name = "فروش";
series1.dataFields.valueY = "count";
series1.dataFields.categoryX = "month";
chart.invalidateData();
});