JScharting Angular y 轴精度为 7

JScharting Angular 7 precision for y-Axes

我正在使用 chart.js 和 Angular 7。我正在提供数组并渲染图表。

正在初始化。

import * as JSC from 'jscharting';

 this.phLiveChart = JSC.chart('phChart', {
      debug: false,
      type: 'step',
      chartArea_boxVisible: false,
      legend_visible: false,
      defaultTooltip_enabled: false,
      xAxis: {
        scale: {
          range: { min: 0, max: 100, padding: 0.1 }
        }
      },
      defaultSeries: {
        opacity: 0.7
      },
      defaultPoint_label_text: '%yValue',
      series: [{
        name: 'pH',
        points: []
      }]
    });

当数据来自服务器时。

for (let i = 0; i < records.length; i++) {
      if (this.device.sensors.ph == true) {
        records[i].ph  = Number(records[i].ph.toFixed(3));
        this.phLiveChart.series(0).points.add([new Date(records[i].recorded_at), records[i].ph]);
      }
}

问题: 有时图表会更精确地显示我提供的值。在控制台日志中它显示正确的精度但在图表中它显示错误。

在 JSCharting 中通过指定格式字符串和选项可以很容易地控制精度,例如:

yAxis_formatString:'n3' 

这将使所有与 y 轴相关的值都为小数点后 3 位的数字。

或者,您可以单独为标签应用格式

defaultPoint_label_text: '{%yValue:n3}'

希望对您有所帮助。