javascript - 在 Highchart 条形图上设置颜色选项

标签 javascript highcharts

我正在研究 this demo .为什么绘图选项颜色没有从颜色选项(两种颜色)中获取条形颜色?如您所见,两种颜色都只取一种颜色。

$(function () {
    chart1 = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
          type: 'bar'
        },
        plotOptions: {
            column: {
                colorByPoint: true
            },
              series: {
                pointWidth: 50
            }
        },
        colors: [
            '#D9844B',
            '#3F4539'],
        credits: {
            enabled: false
        },
        title: {
            text: 'Test',
            style: {
                color: '#2d2d2d',
                fontWeight: 'normal',
                fontSize: '11',
                marginBottom: '30'
            }
        },

        xAxis: {
            categories: ['Ecology & Economics', 'Economics Only'],

        },
        yAxis: {
            tickInterval: 50,
            max: 300,
            title: {
                text: 'Number of ROR Facilities'
            }
        },
        legend: {
            enabled: false
        },
        tooltip: {
            formatter: function () {
                return this.x + '  <b> : ' + this.y + '</b>';
            }
        },
        series: [{
            data: [29.9, 71.5],
            dataLabels: {
                enabled: true,

                color: '#2d2d2d',
                align: 'right',
                x: -40,
                y: 0,
                style: {
                    fontSize: '12px',
                    fontFamily: 'Verdana, sans-serif'
                }
            }
        }]
    });
});

最佳答案

我认为文档有误。它说 colorByPoint 是一个栏/列选项,但你是对的,它不起作用。将其移至系列选项,它确实有效:

    plotOptions: {            
          series: {
            pointWidth: 50,
            colorByPoint: true
        }
    },

已更新 fiddle .

关于javascript - 在 Highchart 条形图上设置颜色选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25587566/

相关文章:

javascript - Highchart map 饼图 : clic and hide specific pie

javascript - 带有标签(数据名称)和百分比年龄的半圆形 donut 饼图......以及鼠标悬停时的数据编号

javascript - $.post() 是否加载新页面?

javascript - 如何为 Bootstrap 的 Affix 添加 "fade out"效果?

javascript - 使用 Underscore(或 Lodash),如何从另一个数组中删除一个数组的每个成员?

javascript - 删除 Highcharts 上的导出和打印按钮插件

php - 无法在 Highcharts 中的多列 mysql 数组上显示 x 轴标签

javascript - 表格出现在我的下拉菜单前面

javascript - 如何在将新项目发布到服务器后更新 ng-repeat

javascript - 如何从 Javascript 中的字符串中提取 Id