javascript - Highchart 条形图中的渐变背景条

标签 javascript html css highcharts gradient

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

在此代码中,我在图表选项中使用了红色 (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

最佳答案

JsFiddle

请引用上面的 fiddle 检查结果

首先,按照 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]

关于javascript - Highchart 条形图中的渐变背景条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36590225/

相关文章:

javascript - 颜色选择器没有按预期工作

javascript - 在 AngularJS 的 ionic 框架中使用 ui-router

html - 如何实现 2 列等高的布局,第一列有 1 个元素,第二列有 2 个元素,没有 float ?

php - 使用 jQuery 插入数据库并获取反馈

css:如何在表格中选择第一个 anchor 标记

css - IE vs.Chrome CSS 优先级

javascript - 如何使用 Javascript 提交 2 个表格和 1 个提交? 1 表单使用 "GET"& 其他用途 "POST"

javascript - 使用 javascript 拆分名称和根名称

javascript - 在 django 模板中使用 javascript 变量

html - 为什么我们要在 html 中向内容图像添加 alt 属性?