列之间的空间为空xAxis点的空间

时间:2015-11-18 15:50:56

标签: charts highcharts

如果Highcharts中的图表具有x个列,并且图表中每列的每个xAxis点都不一定有数据,那么有没有办法折叠为数据点存在的列它们之间没有空格(没有列数据)?

https://jsfiddle.net/anth_3/bmfbpxme/1/

$(function () {
    $('#container').highcharts({
        chart: {
            zoomType: 'xy'
        },
        title: {
            text: ''
        },
        xAxis: [{
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
            crosshair: true,
            reversed: false,
            labels: {
                step: 1,
                rotation: 45
            },
            type: 'datetime',
            tickLength: 7,
            showEmpty: false,
            tickPositions: [0, 7, 14, 21, 28, 35, 42, 49, 56],
            tickmarkPlacement: 'on'
        }],
        yAxis: [{ // Primary yAxis
            labels: {
                format: '{value}°F'
            },
            title: {
                text: 'Temperature'
            }
        }, { // Secondary yAxis
            title: {
                text: 'Precipitation'
            },
            labels: {
                format: '{value} in'
            },
            opposite: true
        }, { // Tertiary yAxis
            title: {
                text: ''
            },
            labels: {
                enabled: false
            },
            opposite: false
        }],
        tooltip: {
            shared: true
        },
        legend: {
            layout: 'vertical',
            align: 'left',
            x: 80,
            verticalAlign: 'top',
            y: 2,
            floating: true,
            backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
        },
        plotOptions: {
            column: {
                marker: {
                    enabled: false
                },
                yAxis: 2,
                showInLegend: false
            },
            area: {
                color: 'rgb(74, 134, 232)',
                lineWidth: 3,
                fillOpacity: 0.3,
                marker: {
                    enabled: false,
                    symbol: 'circle',
                    radius: 2
                },
                yAxis: 1,
                tooltip: {
                    valueSuffix: ' in'
                }
            },
            line: {
                tooltip: {
                    valueSuffix: ' °F'
                },
                lineWidth: 3,
                marker: {
                    enabled: false,
                    symbol: 'circle',
                    radius: 2
                }
            }
        },
        series: [{
            name: 'Harvest',
            color: 'rgb(255, 140, 0)',
            type: 'column',
            data: [100, null, null, null, null, null, null, null, null, null, 100, null]
        },{
            name: 'Tillage',
            color: 'rgb(139, 69, 19)',
            type: 'column',
            data: [null, 100, null, null, null, null, null, null, null, null, null, 100]
        },{
            name: 'Irrigation',
            color: 'rgb(0, 179, 238)',
            type: 'column',
            data: [100, 100, null, null, null, null, null, 100, null, null, null, null]
        }, {
            name: 'Rainfall',
            type: 'area',
            data: [49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
        }, {
            name: 'Air Temperature',
            color: 'rgb(206, 101, 95)',
            type: 'line',
            data: [9.0, 7.9, 5.4, 12.5, 19.2, 17.8, 24.2, 28.5, 29.3, 32.3, 18.9, 15.6]
        }, {
            name: 'Soil Temperature',
            color: 'rgb(51, 51, 51)',
            type: 'line',
            data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6]
        }]
    });
});

0 个答案:

没有答案