使用默认颜色更改高图中列的颜色

时间:2016-12-18 04:04:55

标签: javascript angularjs highcharts highcharts-ng

我必须更改highcharts中其中一列的颜色。我看到我们可以为整个系列改变它,但是我们已经能够找到只改变它的一列。这是我的系列制作方式:

var dates = [];
var scores = [];
vm.data.values.forEach(function (item) {
    dates.push(datefilter(item.date, 'yyyy-MM'));

    if (item.isCurrent) {
        scores.push({
            y: item.score || 0,
            marker: {
                fillColor: '#FF0000',
                lineWidth: 5,
                lineColor: "#FF0000"
                }
            });
    }
    else {
        scores.push(item.score || 0);
    }
});

vm.chartConfig = {
            options: {
                chart: {
                    type: 'column'
                },
                plotOptions: {
                    series: {
                        cursor: 'pointer'
                        },
                        marker: {
                            lineWidth: 1,
                            symbol: 'circle'
                        }
                    }
                }
            },
            title: {
                text: "Scores"
            },
            xAxis: {
                categories: dates
            },
            yAxis: {
                title: {
                    text: null
                }
            },
            series: [
                {
                    name: 'Scores',
                    data: scores,
                    color: "#249858"
                }
            ]
        };
    };

组件的html如下所示:

<highchart config="vm.chartConfig"></highchart>

使用此代码,我只能看到我在chartConfig对象中设置的1种颜色。我在foreach循环中创建系列数据时设置的那个永远不会生效。任何指针或plunkr链接都会非常棒。

1 个答案:

答案 0 :(得分:0)

对于有类似问题的人,我设置的颜色是错误的。改变

<强> OLD

if (item.isCurrent) {
    scores.push({
        y: item.score || 0,
        marker: {
            fillColor: '#FF0000',
            lineWidth: 5,
            lineColor: "#FF0000"
            }
        });
}
else {
    scores.push(item.score || 0);
}

新代码

if (item.isCurrent) {
    scores.push({
        y: item.score || 0,
        marker: {
            fillColor: '#FF0000',
            lineWidth: 5,
            lineColor: "#FF0000"
            }, 
        color: '#FF0000'
        });
}
else {
    scores.push(item.score || 0);
}

为我做了诀窍。

注意:我保留的标记颜色是因为我正在渲染折线图和柱形图。并且颜色适用于列,而标记适用于折线图。

相关问题