AreaSpline Graph中的负填充颜色

时间:2014-04-15 10:33:17

标签: highcharts

我想在区域样条图中填充样条曲线上方的区域颜色。 我试图设置负填充颜色但没有结果。 任何人都可以让我知道如何填充样条曲线上方的区域颜色而不是下方? 任何帮助将不胜感激。

$(function () {
        $('#container').highcharts({
            chart: {
                type: 'areaspline'
            },
            title: {
                text: 'Average fruit consumption during one week'
            },
            legend: {
                layout: 'vertical',
                align: 'left',
                verticalAlign: 'top',
                x: 150,
                y: 100,
                floating: true,
                borderWidth: 1,
                backgroundColor: '#FFFFFF'
            },
            xAxis: {
                categories: [
                    'Monday',
                    'Tuesday',
                    'Wednesday',
                    'Thursday',
                    'Friday',
                    'Saturday',
                    'Sunday'
                ],
                plotBands: [{ // visualize the weekend
                    from: 4.5,
                    to: 6.5,
                    color: 'rgba(68, 170, 213, .2)',
                }]
            },
            yAxis: {
                title: {
                    text: 'Fruit units'
                }
            },
            tooltip: {
                shared: true,
                valueSuffix: ' units'
            },
            credits: {
                enabled: false
            },
            plotOptions: {
                areaspline: {
                    fillOpacity: 0.5
                }
            },
            series: [{
                name: 'John',
                data: [3, 4, 3, 5, 4, 10, 12],
                negativeFillColor: '#000000'
            }, {
                name: 'Jane',
                data: [1, 3, 4, 3, 3, 5, 4],
                negativeFillColor: '#000000'
            }]
        });
    })

谢谢, 中号

1 个答案:

答案 0 :(得分:1)

嗯,门槛应该有效。只需要设置

  • endOnTick: false
  • maxPadding: 0
  • threshold: max_value_in_data

请参阅:http://jsfiddle.net/3bQne/1076/

代码:

var data = [3, 4, 3, 5, 4, 10, 12];

Array.prototype.max = function() {
    return Math.max.apply(null, this);
}

$('#container').highcharts({
    chart: {
        type: 'areaspline'
    },
    yAxis: {
        endOnTick: false,
        maxPadding: 0
    },
    plotOptions: {
        areaspline: {
            threshold: data.max(),
        }
    },
    series: [{
        data: data,
        negativeFillColor: 'rgba(255, 0, 0, 0.5)'
    }]
});