amcharts - 将选项传递给图表
问题描述
使用 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;
有没有办法将所有选项放入单个对象并将该对象传递进去?在这种情况下,如果我想添加另一个选项,我只需要更新对象,而不是添加一行代码。
解决方案
您可以使用 JSON 配置来做到这一点:https ://www.amcharts.com/docs/v4/concepts/json-config/ 但是,如果您想在构建图表后进行更改,那么您使用的方法会更有效,与 JSON 配置一样,您必须重建图表,而不是仅更改您需要的东西。
推荐阅读
- java - Java 类不必匹配源文件中编写的包
- algorithm - 在每次调用的范围内获取唯一的随机数
- powershell - 在 Powershell 中从 PC 名称获取 UPN
- linux - 如何在树莓派上成功运行 valgrind(callgrind)?
- attributes - 如何在 Magento 2 中同步两个产品属性?
- excel - 查找功能未按预期在所有工作表中工作
- ios - 使用 UICollectionLayoutListConfiguration 的特定部分的部分标题
- javascript - How Can I get element from <> (td tag's child) in JavaScript DOM
- python - 如何编写路由以使用 Flask 接收内容安全策略报告而不会收到 400 Bad Request 错误(flask_wtf.csrf.CSRFError)?
- swift - SwiftUI:调用-StateObject 中缺少参数