首页 > 解决方案 > 将选项传递给图表

问题描述

使用 AM Charts 4,直到现在我一直使用图表的方式是我做类似的事情

var categoryAxis = this.__chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.dataFields.category = "category";
categoryAxis.renderer.minGridDistance = 120;

var valueAxis = this.__chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.title.text = 'Y-AXIS:;
valueAxis.cursorTooltipEnabled = false;

有没有办法将所有选项放入单个对象并将该对象传递进去?在这种情况下,如果我想添加另一个选项,我只需要更新对象,而不是添加一行代码。

标签: amchartsamcharts4

解决方案


您可以使用 JSON 配置来做到这一点:https ://www.amcharts.com/docs/v4/concepts/json-config/ 但是,如果您想在构建图表后进行更改,那么您使用的方法会更有效,与 JSON 配置一样,您必须重建图表,而不是仅更改您需要的东西。


推荐阅读