自定义高级图表的弹出窗口

时间:2015-08-29 17:13:19

标签: jquery highcharts

在这个小提琴中:

http://jsfiddle.net/LLExL/5122/

系列标签未正确显示。如果将鼠标悬停在数据点上,则x数据点将以毫秒显示为时间。

src:

<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
<div id="chart-grid"></div>

.chart {
    width: 350px; 
    height: 300px;
}

var json = [
    {
        "header": "test1",
        "children": [
            {
                "date": "2015-01-02",
                "count": "36"
            },
            {
                "date": "2015-01-03",
                "count": "29"
            }
        ]
    },
    {
        "header": "test2",
        "children": [
            {
                "date": "2015-01-02",
                "count": "36"
            },
            {
                "date": "2015-01-03",
                "count": "129"
            }
        ]
    }
];

$(document).ready(function () {

    var options = {
        chart: {
            type: 'scatter'
        },
        title: {
            text: 'test' // Title for the chart
        },
        subtitle: {},
        legend: {
            enabled: true
        },
        tooltip: {},
        plotOptions: {
            series: {
                //pointStart: pointStart,
                pointInterval: 24 * 3600 * 1000 * 30
            }
        },
        xAxis: {

            type: 'datetime'
        },
        yAxis: {
            minPadding: 0,
            maxPadding: 0,
            gridLineColor: 'rgba(204,204,204,.25)',
            gridLineWidth: 0.5,
            title: {
                text: 'Access Count',
                rotation: 0,
                textAlign: 'right',
                style: {
                    color: 'rgba(0,0,0,.9)',
                }
            },
            labels: {
                style: {
                    color: 'rgba(0,0,0,.9)',
                    fontSize: '9px'
                }
            },
            lineWidth: .5,
            lineColor: 'rgba(0,0,0,.5)',
            tickWidth: .5,
            tickLength: 3,
            tickColor: 'rgba(0,0,0,.75)'
        },
        series:[]
    };

    var $chartGrid = $('#chart-grid'),
        title = [],
        serie,
        date,
        name;

    $.each(json, function(i, item) {
        name = 'container-' + i;
        $chartGrid.append('<div id="'+name+'" class="chart"></div>');   

        serie = [{
            data: []
        }];

        $.each(item.children, function(j, points) {
            date = points.date.split('-'); //Date.parse doens't work in FF and IE

            serie[0].data.push({
                x: Date.UTC(date[0],date[1],date[2]),
                y: parseFloat(points.count)
            });
        });


        options.title.text = item.header;
        options.series = serie;
        $('#' + name).highcharts($.extend({}, options));
    });


});

如果我使用线图http://jsfiddle.net/LLExL/5123/,则显示日期。

如何在格式为dd/mm/yyyy hh:mm:ss的悬停时显示x轴值?

可以重命名弹出的x和y标签吗?

1 个答案:

答案 0 :(得分:3)

您可以使用工具提示格式化程序选项和Highcharts.dateFormat格式化您的需求。

tooltip: {
    formatter: function () {
        return 'x: ' + Highcharts.dateFormat('%d/%m/%Y %H:%M:%S', this.x) + '<br>' + 'y: ' + this.y;
    }
},

SOURCE

http://jsfiddle.net/nicholasduffy/sm42x9u8/2/ http://api.highcharts.com/highcharts#tooltip.formatter