简体   繁体   中英

Highcharts column fit/adjust on chart

I write because I go back to being stuck in a problem with Highcharts. I have a monthly chart that works fine except for one thing. The zoom level. The X axis is always shown me a value of 0 (today), so that the zoom level is incorrect. I am attaching a picture to try to explain it better. I need this column set in the graph. I appreciate your help! Thank you!

The json returned by PHP is (correct results):

{"data":[[1401580800000,2],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0],[1400025600000,0]]}

And Javascript file:

chart = new Highcharts.Chart({
chart: {
    renderTo: 'divStatsGrupo',
    plotBackgroundColor: null,
    plotBorderWidth: null,
    plotShadow: false
    },
    title: {
    text: tituloMes
    },

    tooltip: {
            formatter: function() {
            return Highcharts.dateFormat('%d/%m/%Y',new Date(this.x)) + '<br/>' +'Alarmas: ' + this.y                               
            }   
        },      
    xAxis: {    
    type: 'datetime',
    dateTimeLabelFormats : {
    day: '%e. %b',
    labels: {
        style: {
            width: '200px','min-width': '100px'
                    },
        useHTML : true, 

                }
                }   
            },

yAxis: {
title: {
    text: 'Total alarmas'
    },
    allowDecimals: false,
    min: 0
    },

     series : [{
    showInLegend: false,   
            name : 'Grafica Mensual',
            type : 'column',
            data: data.data,    
    dataLabels: {
                enabled: true,
                rotation: 0,
                color: '#000000',
                align: 'center',
                y: 0,
                style: {
                    fontSize: '14px',
                    fontFamily: 'Verdana, sans-serif',
                }} 
                }]
        });
}); ///cierra get 

EDIT: I need a graphic for month (user select), but, the white area and Xaxis only appers info for the month selected. The PHP file return a correct JSON chain, but highcharts not fit the columns fine. Sorry for my english!

在此处输入图片说明

The problem is with your JSON, where you have duplicated values for the same timestamp. Just remove them.

Then! You have unsorted data, it should be sorted ascending by timestamp.

After fixed, it works fine, see: http://jsfiddle.net/4nCx3/

var data = {
    "data": [
        [1400025600000, 0],
        [1401580800000, 2]
    ]
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM