【问题标题】:Gradient background bars in Highchart bar chartHighchart条形图中的渐变背景条
【发布时间】:2016-04-13 06:24:14
【问题描述】:

我的问题是更改高图条形图中的背景条。我可以将条形更改为如下所示的特定颜色,但我想让它渐变。

在这段代码中,我在图表选项中使用了红色 (FF0000)。渐变背景怎么改?

HTML:

<div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>

JS:

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'bar'
        },
        title: {
            text: 'Historic World Population by Region'
        },
        colors: [
            '#ff0000'
            ],
        xAxis: {
            categories: ['Africa', 'America', 'Asia', 'Europe', 'Oceania'],
            title: {
                text: null
            }
        },
        yAxis: {
            min: 0,
            max: 100,
            title: {
                text: 'Percentage',
                align: 'high'
            },
            labels: {
                overflow: 'justify'
            }
        },
        tooltip: {
            valueSuffix: ' millions'
        },
        plotOptions: {
            bar: {
                dataLabels: {
                    enabled: true
                }
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -40,
            y: 80,
            floating: true,
            borderWidth: 1,
            backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
            shadow: true
        },
        credits: {
            enabled: false
        },
        series: [{
            name: 'Year 1800',
            data: [10, 31, 63, 3, 28]
        }]
    });
});

JSFiddle

【问题讨论】:

  • 也许this question可以帮助你
  • 这对我有帮助,谢谢@SimonM。

标签: javascript html css highcharts gradient


【解决方案1】:

JsFiddle

请参考上面的小提琴来检查结果

首先,根据 Highcharts 声明一个渐变

const color_grad1 = {
                    linearGradient: { x1: 0, x2: 0, y1: 0, y2: 1 },
                    stops: [
                    [0, '#fdfc47'],
                    [1, '#24fe41']
                                    ]
                        };

然后使用渐变如下:

data: [{y: 10, color: color_grad1}, 31, 63, 3, 28]

【讨论】:

    猜你喜欢
    • 2020-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 2011-07-14
    相关资源
    最近更新 更多