jQuery FLOT多轴工具提示%x的值是数据刻度号而不是xval

时间:2019-06-21 00:46:55

标签: jquery tooltip axis flot

使用多轴时,通常会在工具提示中使用%x显示yaxis的xaxis值,但是y2axis的%x具有刻度数输出实例xaxis。

我希望得到的结果是工具提示的值是0000-00-00 00:00:00,但是现在y2axis标记为0、1、2

有没有办法解决存储在工具提示中的数据数组中的值?

flot y2axis http://101.101.160.29/sdr/y2.png

(function($, window, document, undefined) {

    var demos = {
        lineCharts_sy: function(target) {
            var data = [{
                    data: [
                        [0, 100.1],
                        [1, 100.2],
                        [2, 100.3]
                    ],
                    label: "temp",
                    color: '#CC2B36',
                    lines: {
                        show: true,
                        fill: true,
                        lineWidth: 1,
                        steps: false,
                        fillColor: {
                            colors: [{
                                opacity: 0.25
                            }, {
                                opacity: 0
                            }]
                        }
                    },
                    points: {
                        show: false,
                        radius: 1
                    }
                }, {
                    data: [
                        [0, 0.01],
                        [1, 0.02],
                        [2, 0.03]
                    ],
                    label: "pres",
                    color: '#115b74',
                    lines: {
                        show: true,
                        fill: true,
                        lineWidth: 1,
                        steps: false,
                        fillColor: {
                            colors: [{
                                opacity: 0.25
                            }, {
                                opacity: 0
                            }]
                        }
                    },
                    points: {
                        show: false,
                        radius: 1
                    },
                    yaxis: 2
                }],


                options = {
                    xaxis: {
                        show: true,
                        tickColor: 'transparent',
                        ticks: [
                            [0, 2019 - 01 - 01 00: 00: 00],
                            [0, 2019 - 01 - 01 00: 01: 00],
                            [0, 2019 - 01 - 01 00: 02: 00]
                        ]
                    },
                    yaxis: {
                        ticks: [
                            [0, "0°C"],
                            [50, "50°C"],
                            [100, "100°C"],
                            [150, "150°C"],
                            [200, "200°C"]
                        ]
                    },
                    y2axis: {
                        ticks: [
                            [0.00, "0Mpa"],
                            [0.50, "0.5Mpa"],
                            [1.00, "1.0Mpa"],
                            [1.50, "1.5Mpa"],
                            [2.00, "2.0Mpa"]
                        ],
                        position: "right"
                    },
                    grid: {
                        borderWidth: 1,
                        hoverable: true

                    },
                    legend: {
                        position: 'ne'
                    },
                    tooltip: {
                        show: true,
                        content: function(label, xval, yval, flotItem) {
                            if (flotItem.seriesIndex == 0) { // you could also use the label
                                return '%x : %y.1 °C';
                            } else {
                                return '%x : %y.2 Mpa';
                            }
                        }
                    }
                };

            $.plot(target, data, options);
        }
    };
    $(window).load(function() {});
    $(document).ready(function() {
        if ($.plot) {
            demos.lineCharts_sy($('#demo-charts-02'), false);
        }
    });
})(jQuery, window, document);

0 个答案:

没有答案