高程图的条形和线形问题

Highcharts bar and line issue

本文关键字:问题 高程图      更新时间:2023-09-26

我正在使用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'
            }
        }]
    });
});

因为你有两个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'
        }
    }]
});
});