如何使用角度为7的amcharts 4将y轴格式化为货币

时间:2019-03-30 20:23:07

标签: amcharts amcharts4

我已经浏览了amcharts版本4(https://www.amcharts.com/javascript-charts/)的文档,但似乎无法找出如何将y轴格式化为货币。有文档以其他方式设置y轴的格式,但货币似乎不是其中一种。任何人都知道如何或从哪里开始?

https://www.amcharts.com/javascript-charts/

到目前为止,我有上面的图表,只需要知道如何或在何处将y轴格式化为货币。当您将鼠标悬停在格式化为货币罚款的行上时,我现在有了标签,因为这很简单。这是我创建轴的功能:

function createAxisAndSeries(field, name, opposite) {
          const valueAxis = chart.yAxes.push(new am4charts.ValueAxis());

          const series = chart.series.push(new am4charts.LineSeries());
          series.dataFields.valueY = field;
          series.dataFields.dateX = 'date';
          series.strokeWidth = 2;
          series.yAxis = valueAxis;
          series.name = name;
          series.tooltipText = '{name}: [bold]${valueY}[/]';
          series.tensionX = 0.8;

          const interfaceColors = new am4core.InterfaceColorSet();

          valueAxis.renderer.line.strokeOpacity = 1;
          valueAxis.renderer.line.strokeWidth = 2;
          valueAxis.renderer.line.stroke = series.stroke;
          valueAxis.renderer.labels.template.fill = series.stroke;
          valueAxis.renderer.opposite = opposite;
          valueAxis.renderer.grid.template.disabled = true;

          }

1 个答案:

答案 0 :(得分:2)

经过一些研发,这为我解决了这个问题:

valueAxis.numberFormatter = new am4core.NumberFormatter();
valueAxis.numberFormatter.numberFormat = '$#,###.##';

希望它可以帮助其他人搜索一天。