2015-02-10 123 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