Highcharts酒吧和线路问题

时间:2014-03-18 17:26:00

标签: javascript highcharts

我使用highcharts创建条形图和折线图以显示预算与实际

之间的差异

我得到的问题是,当我用条形图制作样条图时,这些点似乎与它们应该在哪里无关。所以对于2月份,预算是20.​​9但是酒吧显示在30以上。

即使在工具提示中显示正确的数据,所有条形图(列)似乎都应该达到高位,

http://jsfiddle.net/ktcle/kSLGL/

$(function () {
    $('#container').highcharts({
        chart: {
            zoomType: 'xy'
        },
        title: {
            text: null
        },

        xAxis: [{
            categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
                'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
        }],
        yAxis: [{ // Primary yAxis
            labels: {
                format: '{value}£m',
                style: {
                    color: '#666666'
                }
            },
            title: {
                text: null,
                style: {
                    color: '#45C2C5'
                }
            }
        }, { // Secondary yAxis
            title: {
                text: 'Budget',
                text: null

            },
            labels: {
                 enabled: false
            },
            opposite: true,

        }],
        tooltip: {
            shared: true
        },
        legend: {
            layout: 'vertical',
            align: 'left',
            x: 120,
            verticalAlign: 'top',
            y: 170,
            floating: true,
            backgroundColor: '#FFFFFF'
        },
        series: [{
            name: 'Budget',
            color: '#4A3950',
            type: 'column',
            yAxis: 1,
            data: [23.9, 20.9, 22.7, 23.8, 25.7, 23.3, 26.7, 23.4, 26.8, 27.5, 25.5, 26.5],
            tooltip: {
                valueSuffix: '£'
            }

        }, {
            name: 'Actual',
            color: '#45C2C5',
            type: 'spline',
            data: [24.5, 22.5, 30 ],
            tooltip: {
                valueSuffix: '£'
            },

            marker: {
                lineWidth: 2,
                lineColor: Highcharts.getOptions().colors[3],
                fillColor: 'white'
            }
        }]
    });

});

1 个答案:

答案 0 :(得分:1)

因为您有两个y轴,所以删除第二个y轴并在系列中删除属性yAxis: 1或更改yAxis: 0

Jsfiddle

$(function () {
$('#container').highcharts({
    chart: {
        zoomType: 'xy'
    },
    title: {
        text: null
    },

    xAxis: [{
        categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
            'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
    }],
    yAxis: [{ // Primary yAxis
        labels: {
            format: '{value}£m',
            style: {
                color: '#666666'
            }
        },
        title: {
            text: null,
            style: {
                color: '#45C2C5'
            }
        }
    }],
    tooltip: {
        shared: true
    },
    legend: {
        layout: 'vertical',
        align: 'left',
        x: 120,
        verticalAlign: 'top',
        y: 170,
        floating: true,
        backgroundColor: '#FFFFFF'
    },
    series: [{
        name: 'Budget',
        color: '#4A3950',
        type: 'column',
        yAxis: 0,
        data: [23.9, 20.9, 22.7, 23.8, 25.7, 23.3, 26.7, 23.4, 26.8, 27.5, 25.5, 26.5],
        tooltip: {
            valueSuffix: '£'
        }

    }, {
        name: 'Actual',
        color: '#45C2C5',
        type: 'spline',
        data: [24.5, 22.5, 30 ],
        tooltip: {
            valueSuffix: '£'
        },

        marker: {
            lineWidth: 2,
            lineColor: Highcharts.getOptions().colors[3],
            fillColor: 'white'
        }
    }]
});

});