Javascript highcharts自定义颜色和tootip点颜色

Javascript highcharts自定义颜色和tootip点颜色,javascript,jquery,charts,colors,highcharts,Javascript,Jquery,Charts,Colors,Highcharts,我使用渐变添加自定义颜色,但工具提示点颜色是objetcs,没有rgb,并且在点格式中没有显示基础颜色。图例显示底色,标签没有问题 pointFormat : '<span style="color:{point.color}">\u25CF</span>'+ ' {series.name} {series.color} - {point.color}: <b>{point.y}</b><br/>' } pointFormat:'\u

我使用渐变添加自定义颜色,但工具提示点颜色是objetcs,没有rgb,并且在点格式中没有显示基础颜色。图例显示底色,标签没有问题

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

默认颜色图表

这是我的样品 尝试注释和取消注释自定义颜色块


如何解决此问题?

发生这种情况有两个原因:

  • 新的自定义颜色不是纯色,而是渐变色,因此当您尝试提取“series.color”渐变色时,style=“color”值需要显示纯色
  • 根据关于点格式()的文档,着色似乎是在“pointFormat”字段上完成的,但我不确定为什么它在那里不起作用。。。希望它能在“格式化程序”字段上工作。也许是海图上的错误
  • 以下是新的“格式化程序”字段:

    格式化程序:函数(){
    var s=''+此.x+'';
    $.each(this.points,function(i,point){
    s+='
    \u25CF:'+point.series.name+':'+point.y; }); 返回s; }
    以下是使用颜色的工作演示:


    请注意,无法使用渐变设置点的格式,因此我选择了与“point.series.color.stops[1][1]”相对应的突出显示部分的颜色。

    发生这种情况有两个原因:

  • 新的自定义颜色不是纯色,而是渐变色,因此当您尝试提取“series.color”渐变色时,style=“color”值需要显示纯色
  • 根据关于点格式()的文档,着色似乎是在“pointFormat”字段上完成的,但我不确定为什么它在那里不起作用。。。希望它能在“格式化程序”字段上工作。也许是海图上的错误
  • 以下是新的“格式化程序”字段:

    格式化程序:函数(){
    var s=''+此.x+'';
    $.each(this.points,function(i,point){
    s+='
    \u25CF:'+point.series.name+':'+point.y; }); 返回s; }
    以下是使用颜色的工作演示:


    请注意,该点不能使用渐变设置格式,因此我选择了颜色的高亮部分,该部分对应于“point.series.color.stops[1][1]”。

    非常感谢@adelriosantiago,我为检查点或点属性添加了一个条件,该条件取决于序列或饼图。highcharts的最新版本(4.1.5)在显示内嵌饼图的工具提示时出现问题,我不得不使用以前的版本(4.0.4)

    格式化程序:函数(){
    var s=''+此.x+'';
    var color=null;
    if(typeof this.points!=“未定义”){
    $.each(this.points,function(i,point){
    color=point.series.color.stops[1][1];
    如果(i==3){
    s+='
    \u00A2'; s+=point.series.name+':'+Highcharts.numberFormat(point.y,2); }否则{ s+='
    \u25CF'; s+=point.series.name+':'+Highcharts.numberFormat(point.y,0); } }); }否则{ color=this.point.color.stops[1][1]; s=''+this.point.name+''; s+='
    \u25CF'; s+=Highcharts.numberFormat(this.point.y,2)+'('+Highcharts.numberFormat(this.point.percentage,2)+'); } 返回s; }

    这里的完整修复

    非常感谢@adelriosantiago,我添加了一个条件来检查点或点属性是否依赖于序列或饼图。highcharts的最新版本(4.1.5)在显示内嵌饼图的工具提示时出现问题,我不得不使用以前的版本(4.0.4)

    格式化程序:函数(){
    var s=''+此.x+'';
    var color=null;
    if(typeof this.points!=“未定义”){
    $.each(this.points,function(i,point){
    color=point.series.color.stops[1][1];
    如果(i==3){
    s+='
    \u00A2'; s+=point.series.name+':'+Highcharts.numberFormat(point.y,2); }否则{ s+='
    \u25CF'; s+=point.series.name+':'+Highcharts.numberFormat(point.y,0); } }); }否则{ color=this.point.color.stops[1][1]; s=''+this.point.name+''; s+='
    \u25CF'; s+=Highcharts.numberFormat(this.point.y,2)+'('+Highcharts.numberFormat(this.point.percentage,2)+'); } 返回s; }

    这里是完整的修复

    谢谢@adelriosantiago,这是一个很好的解决方案,但是Pie mouseover事件会产生错误,可能是工具提示过程。在Chrome中:Uncaught TypeError:无法读取ff TypeError中未定义的jquery-1.9.1.js:622的属性'length'。错误:obj是未定义的jquery-1.9.1.js:622:3跟踪错误并由highcharts生成。我尝试使用其他版本的jQuery,但问题仍然存在。尝试为饼图启用工具提示,但未成功。我想在绘图上启用标签。谢谢@adelriosantiago,这是一个很好的解决方案,但是在Pie mouseover事件中会产生错误,可能是工具提示过程。在Chrome中:Uncaught TypeError:无法读取ff TypeError中未定义的jquery-1.9.1.js:622的属性'length'。错误:obj是未定义的jquery-1.9.1.js:622:3跟踪错误并由highcharts生成。我尝试使用其他版本的jQuery,但问题仍然存在。尝试为饼图启用工具提示,但未成功。我认为可以在绘图上启用标签。
    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;
    }
    
    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;
    }