Flot.js 设置y轴标签格式显示两位小数

a_m*_*687 2 javascript jquery flot

如何格式化我的 y 轴标签以显示两个小数位我检查了我的代码,结果是,不是显示 14.59,而是显示 15.00,这是我的代码如下:

$.plot("#placeholder", data, {
                xaxis: {
                    min: minDate,
                    max: maxDate,
                    mode: "time",
                    tickSize: setTickSize,
                    monthNames: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]
                },
                yaxis: {
                    min: yMin,
                    max: yMax,
                    ticks: 1,
                    tickSize: 1,
                    tickDecimals:2
                },
                series: {
                    lines: {
                        show: true,
                        fill: true
                    },
                    points: {
                        show: false
                    }
                },
                grid: {
                    borderWidth: 1,
                    hoverable: true
                }
            });
Run Code Online (Sandbox Code Playgroud)

我读过我可以使用 tickFormatter 函数,但我也不知道该把它放在哪里。

Bla*_*ake 5

您可以使用 y 轴数据点构建刻度数组,因为它是动态的并将其传递给 yaxis 刻度。

yaxis: {
         ticks: [25.49, 28.49, 31.49, 34.49, 37.49, 40.49],
               
         tickDecimals:2
       }
Run Code Online (Sandbox Code Playgroud)

yaxis: {
         ticks: [25.49, 28.49, 31.49, 34.49, 37.49, 40.49],
               
         tickDecimals:2
       }
Run Code Online (Sandbox Code Playgroud)
var data = [];
data = [
  [3, 36.86],
  [5, 29.66],
  [8, 33.47]
];



dataLine = [];
dataLine.push(data);

$.plot($("#placeholder"), dataLine, {


  grid: {
    backgroundColor: "#E5E5E5",
    hoverable: true
  },

  points: {
    show: true,
    radius: 4
  },

  lines: {
    show: true
  },
  yaxis: {

    ticks: [25.49, 28.49, 31.49, 34.49, 37.49, 40.49],

    tickDecimals: 2
  }
});
Run Code Online (Sandbox Code Playgroud)