在flotchart上发布工具提示以获取日期格式

use*_*416 1 charts tooltip flot

我正面临着工具提示在x轴上显示日期的问题.任何人都可以帮忙吗?

小提琴代码

         grid: {
                hoverable: true //IMPORTANT! this is needed for tooltip to work
            },
            tooltip: true,
            tooltipOpts: {
                content: "<h4>%s</h4><ul><li>Date is %x</li><li>Total Count: %y</li></ul>",         
            defaultTheme: false
        },
         points:
        {
                show: true
        },
        series: {

            bars: {
                show: true,
                barWidth: 0.1,
                order: 1
            }
        }
Run Code Online (Sandbox Code Playgroud)

Rai*_*ica 5

您需要一个函数将x值(只是一个数字/时间戳)转换为实际日期.

使用这样的东西:

tooltipOpts: {
    content: function (label, x, y) {
        var date = new Date(+x);
        var tooltip = '<h4>' + label + '</h4><ul>';
        tooltip += '<li>Date is ' + date.toLocaleDateString() + '</li>';
        tooltip += '<li>Total Count: ' + y + '</li></ul>';
        return tooltip;
    },
Run Code Online (Sandbox Code Playgroud)

看到这个更新小提琴.