blue-sky
blue-sky

Reputation: 53826

Customizing point popup of highcharts

In this fiddle :

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

The series labels are not being displayed correctly. If hover over a data point the x data point is being displayed as time in milliseconds.

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));
    });


});

If I use line plot http://jsfiddle.net/LLExL/5123/ the date is being displayed.

How to display x axis values on hover formatted as dd/mm/yyyy hh:mm:ss ?

Can popup x and y labels be renamed ?

Upvotes: 2

Views: 446

Answers (1)

duffn
duffn

Reputation: 3760

You can use the tooltip formatter options and Highcharts.dateFormat to format to your needs.

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

http://jsfiddle.net/nicholasduffy/sm42x9u8/2/

http://api.highcharts.com/highcharts#tooltip.formatter http://api.highcharts.com/highcharts#Highcharts.dateFormat

Upvotes: 3

Related Questions