【问题标题】:Customizing Highcharts legend behavior for two series为两个系列自定义 Highcharts 图例行为
【发布时间】:2013-05-11 03:59:57
【问题描述】:

在自定义两个系列饼图的图例时发现自己完全卡住了。

JSFiddle 和代码:

http://jsfiddle.net/jschlick/cCXkj/

colors: ['#f00000', '#f8d10a', '#9edb70'],
legend: {
  layout: 'horizontal',
  verticalAlign: 'bottom'
},
plotOptions: {
  pie: {
    point: {
      events: {
        legendItemClick: function () {
          this.select();
          elm.tooltip.refresh(this);
          return false;
        },
        mouseOver: function () {
          this.select();
          elm.tooltip.refresh(this);
          return false;
        }
      }
    },
    showInLegend: true
  },
  series: {
    dataLabels: {
      enabled: true,
      format: '{point.percentage}%'
    }
  }
},
series: [{
  type: 'pie',
  center: [450, 150],
  data: [
    ["Red", 2],
    ["Yellow", 5],
    ["Green", 3]
  ],
  size: '60%',
  innerSize: '40%'
}, {
  type: 'pie',
  linkedTo: ':previous',
  center: [150, 150],
  data: [
    ["Red", 1],
    ["Yellow", 2],
    ["Green", 7]
  ],
  size: '60%',
  innerSize: '40%'
}]

1) 我需要当前的图例点击行为(切片数据点)在悬停而不是点击时执行。

2) 我预计使用“linkedTo: ':previous'”也会将第二个图表与图例行为联系起来,但只影响第一个图表。 IE。单击“红色”将在两个图表上分割红色数据点。

感谢您的帮助。

【问题讨论】:

    标签: highcharts


    【解决方案1】:

    这似乎是一种迂回的方式,但这是我首先想到的。我不认为 HighCharts 在图例项目上提供悬停事件,所以我自己做了一个:

    [after creating the chart]
    
    $.each(Highcharts.charts[0].legend.allItems, function() {
        var groupElem = this.legendGroup.element;  // for each legend group
        $.data(groupElem, 'info', {'series':[this.series, this.series.linkedSeries[0]],'point':this.x}); // store some data about the group for use in the mouseover call back
        $(groupElem).mouseover(function(){
                $.data(this,'info').series[0].points[$.data(this,'info').point].select(true,false); // select the pie wedge
                $.data(this,'info').series[1].points[$.data(this,'info').point].select(true,true); // select the linked pie wedge pass (true, true) to no deselect other.
            }); 
    });
    

    小提琴here.

    【讨论】:

    • 这太好了,谢谢!我正在处理:1)第二个鼠标悬停在图例项上只会为一个图表上的切片设置动画,2)鼠标悬停在图例样本上,并且同一图例项的文本被视为两个事件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多