2015-02-10 108 views
0

我想添加一个图像的工具提示到甜甜圈饼图。有没有一种方法可以将工具提示放在饼图片之外?如何在饼图外显示高位图工具提示?

http://jsfiddle.net/jlai403/6eenxom2/4/

$('#container').highcharts({ 
    chart: { 
     plotBackgroundColor: null, 
     plotBorderWidth: null, 
     plotShadow: false 
    }, 
    title: { 
     useHTML: true, 
     text: '<span style="text-align:center; top: -50px; position: relative"><h6>such pie much wow</h6><h2>79</h2></span>', 
     verticalAlign: 'middle', 
    }, 

    tooltip: { 
     useHTML: true, 
     pointFormat: "<img src='{point.customValue}' width='50'/>" 
    }, 
    plotOptions: { 
     pie: { 
      allowPointSelect: true, 
      cursor: 'pointer', 
      dataLabels: { 
       useHTML: false, 
       enabled: false, 
       style: { 
        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black' 
       } 
      } 
     } 
    }, 
    series: [{ 
     type: 'pie', 
     name: 'Some Pie Chart', 
     data: [ 
      {name: 'turtle eating strawberry', y: 25, customValue: 'http://www.tehcute.com/pics/201109/baby-turtle-eats-strawberry.jpg'}, 
      {name: 'red panda', y: 25, customValue: 'http://www.greenvillezoo.com/assets/img/Adopt/RedPanda.png'}, 
      {name: 'doge', y: 50, customValue: 'http://img2.wikia.nocookie.net/__cb20141105223610/r2d/images/7/73/Dogepic.png'} 
     ], 
     size: '60%', 
     innerSize: '50%', 
     startAngle: 0, 
     endAngle: 260 
    }] 
}); 
+0

你是什么意思,在饼皮外?你想要一个静态的地方还是动态的? – 2015-02-10 10:34:30

+0

请参阅['tooltip.positioner'](http://api.highcharts.com/highcharts#tooltip.positioner)选项。但工具提示需要在图表的容器内。如果您想在容器外部获取工具提示,请使用['point.events.mouseOver'](http://api.highcharts.com/highcharts#plotOptions.series.point.events.mouseOver)和['point.events .mouseOut'](http://api.highcharts.com/highcharts#plotOptions.series.point.events.mouseOut) - 使用该事件创建自己的工具提示。 – 2015-02-10 10:43:09

+0

@RaeenHashemi我不希望它在一个静态位置。我希望它是动态的,但不包括扇形。 – Joey 2015-02-10 16:02:33

回答

1

很抱歉,我没有信誉发表评论,所以我在这里加入了更新的小提琴。你的意思是这样吗?

http://jsfiddle.net/6eenxom2/6/

更新JS

$(function() { 
$('#container').highcharts({ 
    chart: { 
     plotBackgroundColor: null, 
     plotBorderWidth: null, 
     plotShadow: false 
    }, 
    title: { 
     useHTML: true, 
     text: '<span style="text-align:center; top: -50px; position: relative"><h6>such pie much wow</h6><h2>79</h2></span>', 
     verticalAlign: 'middle', 
    }, 

    tooltip: { 
     useHTML: true, 
     //pointFormat: "<img src='{point.customValue}' width='50'/>", 
     formatter:function(){ 
     $('#tooltip').html(this.y + '<img src=' + this.point.customValue + '/>'); 
} 
}, 
    plotOptions: { 
     pie: { 
      allowPointSelect: true, 
      cursor: 'pointer', 
      dataLabels: { 
       useHTML: false, 
       enabled: false, 
       style: { 
        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black' 
       } 
      } 
     } 
    }, 
    series: [{ 
     type: 'pie', 
     name: 'Some Pie Chart', 
     data: [ 
      {name: 'turtle eating strawberry', y: 25, customValue: 'http://www.tehcute.com/pics/201109/baby-turtle-eats-strawberry.jpg'}, 
      {name: 'red panda', y: 25, customValue: 'http://www.greenvillezoo.com/assets/img/Adopt/RedPanda.png'}, 
      {name: 'doge', y: 50, customValue: 'http://img2.wikia.nocookie.net/__cb20141105223610/r2d/images/7/73/Dogepic.png'} 
     ], 
     size: '60%', 
     innerSize: '50%', 
     startAngle: 0, 
     endAngle: 260 
    }] 
});}); 

使用格式化功能,显示圆形切片外部的提示信息。

+0

我不是在寻找一个静态定位工具提示。但我不确定这是否有可能,除非我写我自己的工具提示。不过谢谢。 – Joey 2015-02-11 15:05:00

+0

太棒了!在文档http://api.highcharts.com/highcharts/tooltip.enabled http://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master中有一个稍微不同的例子/ samples/highcharts/plotoptions/series-point-events-mouseover/@http://stackoverflow.com/users/4248377/pratik-mehta's和文档的组合将是理想的。 – 2017-04-02 21:43:49