如何绘制Highcharts的最大高度(区域样条曲线)

时间:2014-07-11 12:32:53

标签: jquery svg highcharts

如何绘制每周最大高度的线条?

这是我的js代码:

$(function () {
$('#container').highcharts({
    chart: {
        type: 'areaspline'
    },
    title: {
        text: 'CPM, IMPS, SPEND, etc'
    },
    legend: {
        layout: 'vertical',
        align: 'left',
        verticalAlign: 'top',
        x: 150,
        y: 100,
        floating: true,
        borderWidth: 1,
        backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
    },
    xAxis: {
        categories: [
            'Week 1',
            'Week 2',
            'Week 3',
            'Week 4',
            'Week 5',
            'Week 6',
            'Week 7',
            'Week 8']
    },
    yAxis: {
        title: {
            text: 'No title required'
        }
    },
    tooltip: {
        shared: true,
        valueSuffix: ' units'
    },
    credits: {
        enabled: false
    },
    plotOptions: {
        areaspline: {
            fillOpacity: 0.5
        }
    },
    series: [{
        name: 'CPM',
        data: [6, 3, 4, 3, 5, 4, 10, 12]
    }, {
        name: 'IMPS',
        data: [1, 1, 3, 4, 3, 3, 5, 4]
    }]

}, function (chart) { // on complete
    chart.renderer.rect(117, 195, 3, 168, 0).attr({fill: 'red', zIndex:3}).add();

});
});

这是我问题的一个小提琴:

Fiddle

先谢谢你

1 个答案:

答案 0 :(得分:0)

<强> DEMO 您必须在plotLine上添加x-axis,例如:

plotLines: [{
                color: '#FF0000',
                width: 3,
                value: 0.2
            }]

参考xAxis.plotLines documentation

以下是完整的代码:

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'areaspline'
        },
        title: {
            text: 'CPM, IMPS, SPEND, etc'
        },
        legend: {
            layout: 'vertical',
            align: 'left',
            verticalAlign: 'top',
            x: 150,
            y: 100,
            floating: true,
            borderWidth: 1,
            backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
        },
        xAxis: {
            categories: [
                'Week 1',
                'Week 2',
                'Week 3',
                'Week 4',
                'Week 5',
                'Week 6',
                'Week 7',
                'Week 8'],
            plotLines: [{
                color: '#FF0000',
                width: 3,
                value: 0.2
            }]
        },
        yAxis: {
            title: {
                text: 'No title required'
            }
        },
        tooltip: {
            shared: true,
            valueSuffix: ' units'
        },
        credits: {
            enabled: false
        },
        plotOptions: {
            areaspline: {
                fillOpacity: 0.5
            }
        },
        series: [{
            name: 'CPM',
            data: [6, 3, 4, 3, 5, 4, 10, 12]
        }, {
            name: 'IMPS',
            data: [1, 1, 3, 4, 3, 3, 5, 4]
        }]

    });
});