echarts格式工具提示四舍五入小数

Edu*_*o G 5 javascript tooltip echarts

我正在使用 echarts 来绘制浮点值的图表,并且我想将系列工具提示中的小数四舍五入到小数点后两位(保持当前工具提示样式)。

我的选项变量是:

var truckTurnAroundTimeOption = {
  color: ['dodgerblue', '#e67e22'],
  title: {
    text: 'Truck Turnaround Time',
    show: false,
    textStyle: {
      fontFamily: 'Roboto',
      fontSize: 14
    }
  },
  tooltip: {
    trigger: 'axis'
  },
  calculable: true,
  xAxis: [
    {
      type: 'category',
      boundaryGap: false,
      axisLabel: {
        formatter: function (value, index) {
          return value.slice(0,5);
        }
      },
      data: truckTurnaroundTimes.map(item => item.hour)
    }
  ],
  yAxis: [
    {
      type: 'value',
      name: 'mins',
      nameLocation: 'middle',
      nameGap: 30,
      
      splitLine: {
        //remove grid lines
        show: false
      }
    }
  ],
  grid: {
    left: 68,
    top: 8,
    right: 28,
    bottom: 38
  },
  legend: {
    show: true,
    icon: 'circle',
    orient: 'vertical',
    top: -4,
    right: 26,
    itemHeight: 12,
    textStyle: {
      fontSize: 11,
    }
  },
  series: [
    {
      name: 'current',
      type: 'line',
      smooth: false,
      data: data.map(item => parseFloat(item.current_truck_turnaround_time)) /* Values like 12.2343443, 5.123452 */
    },
    {
      name: 'improved',
      type: 'line',
      smooth: false,
      data: data.map(item => parseFloat(item.improved_truck_turnaround_time)) /* Values like 12.2343443, 5.123452 */
    }
  ]
};
Run Code Online (Sandbox Code Playgroud)

数组数据集中的数据包含以下值:12.2343443、5.123452 等。

PD:我不想在绘制图表之前对系列数据进行四舍五入

小智 2

使用这里toFixed()的-方法parseFloat()

data.map(item => parseFloat(item.current_truck_turnaround_time).toFixed(2))
Run Code Online (Sandbox Code Playgroud)