簡體   English   中英

如何更改圖例點的顏色?

[英]How can I change the color of legend points?

如果您查看下面的示例,項目 1 和項目 2 的點在圖例中都是灰色的。 但是,在我的情況下,這些點應該與相關系列具有相同的顏色。 有沒有一些簡單的方法可以實現這一目標? 我找不到任何例子。

示例: https://jsfiddle.net/0rdwm1ax/

//possibly relevant code:
series: [
     name: 'Test Series',
     color: '#00FF00' //Setting color in my project did not work, though
     ...
    ]

我已經嘗試過的:

  • Browsing through online examples and HighCharts Gantt JS API Reference ( https://api.highcharts.com/gantt )
  • 尋找一種設置系列顏色的方法(在 Highcharts-Gantt 中不起作用)
  • 看看 PointFormatter,但是我不確定它在 Highcharts-Gantt 中是如何工作的(而且我找不到任何工作示例)

和這里的情況一樣: http://jsfiddle.net/BlackLabel/1w0yx8m4/

在甘特圖中, colorByPoint選項默認啟用,因此您可以禁用它: https://jsfiddle.net/BlackLabel/mdbqnaxy/或添加以下插件來更改項目的顏色。

(function(H) {
    var colors = ['red', 'blue'];

    H.wrap(H.Legend.prototype, 'colorizeItem', function(proceed, item) {
        item.color = colors[item.index];
        proceed.apply(this, Array.prototype.slice.call(arguments, 1));
        item.color = null;
    });
}(Highcharts));

現場演示: https://jsfiddle.net/BlackLabel/mjock9uw/

文檔: https://www.highcharts.com/docs/extending-highcharts/extending-highcharts

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM