2015-04-21 73 views
0

我使用漸變添加了自定義顏色停止點,但工具提示點顏色是objetcs,沒有rgb,也沒有在pointFormat中顯示基礎顏色。圖例顯示基本顏色,沒有標籤問題。highcharts自定義顏色和tootip點顏色

pointFormat : '<span style="color:{point.color}">\u25CF</span>'+ 
' {series.name} {series.color} - {point.color}: <b>{point.y}</b><br/>' } 

海關顏色圖表 Custom Colors

默認顏色圖表 Default Colors

這裏我的樣品http://jsfiddle.net/castocolina/2mdt9rhb/ 試評,並取消對自定義顏色塊

如何解決這個問題?

回答

3

出現這種情況有兩個原因:

  1. 新的自定義顏色不是純色,而是一個漸變,因此當您嘗試提取「series.color」獲得了漸變,樣式=「color」值需要顯示純色。
  2. 根據點格式化文檔(http://api.highcharts.com/highcharts#tooltip.pointFormat)着色似乎在「pointFormat」字段上完成,但我不確定它爲什麼不能在那裏工作......希望它適用於「格式化程序」字段。也許HighCharts上的錯誤?

這是新的「格式化」字段:

formatter: function() { 
    var s = '<b>'+ this.x +'</b>'; 

    $.each(this.points, function(i, point) { 
    s += '<br/><span style="color:'+ point.series.color.stops[1][1] +'">\u25CF</span>: ' + point.series.name + ': ' + point.y; 
    }); 

    return s; 
} 

這裏是一個有顏色的工作演示:https://jsfiddle.net/adelriosantiago/pL0yzfsx/3/

注意的一點不能因此漸變被格式化我選擇了對應於「point.series.color.stops [1] [1]」的顏色的高亮部分「

+0

謝謝@adelriosantiago,這是很好的解決方案,但是會產生Pie mouseover事件錯誤,可能是工具提示過程。 在鉻: _Uncaught類型錯誤:無法讀取undefined_ jQuery的1.9.1.js的屬性 '長度':622 在FF _TypeError:obj是undefined_ jquery的-1.9.1.js:622:3 痕量該錯誤是由高層圖產生的。 我嘗試與其他版本的jQuery和問題仍然存在。嘗試啓用工具提示餅圖,但沒有成功。我認爲要啓用標籤以上的情節。 – ccolina

2

非常感謝@adelriosantiago,我添加了一個條件來檢查點或點屬性取決於s eries或派。 highcharts的最新版本(4.1.5)有問題,顯示嵌入式餡餅的提示,我只好用以前的版本(4.0.4)

formatter : function() { 
    var s = '<b>' + this.x + '</b>'; 
    var color = null; 

    if (typeof this.points != 'undefined') { 
     $.each(this.points, function(i, point) { 
      color = point.series.color.stops[1][1]; 
      if (i == 3) { 
       s += '<br/><span style="color:' + color + '">\u00A2</span> '; 
       s += point.series.name + ': ' + Highcharts.numberFormat(point.y, 2); 
      } else { 
       s += '<br/><span style="color:' + color + '">\u25CF</span> '; 
       s += point.series.name + ': ' + Highcharts.numberFormat(point.y, 0); 
      } 
     }); 
    } else { 
     color = this.point.color.stops[1][1]; 
     s = '<h3 style="color:' + color + '; font-weight: bold;">' + this.point.name + '</h3>'; 
     s += '<br/><span style="color:' + color + '">\u25CF</span> '; 
     s += Highcharts.numberFormat(this.point.y, 2) + ' (' + Highcharts.numberFormat(this.point.percentage, 2) + '%)'; 
    } 

    return s; 
} 

這裏全部修復http://jsfiddle.net/castocolina/2mdt9rhb/4/