简体   繁体   English

如何在图例中的所有系列旁边添加图标

[英]How to add an icon beside all the series in an legend

I want to add a favicon beside all the series data objects in the legend of my highcharts pie chart but I'm having no luck. 我想在highcharts饼图的图例中的所有系列数据对象旁边添加一个图标,但是我没有运气。 I've searched around for a few hours but it seems like all of the examples are not quite right. 我已经搜索了几个小时,但似乎所有示例都不太正确。 I want it to look like the image below 我希望它看起来像下图

在此处输入图片说明

I though adding the icon to the series data and defining it in the legends labelFormatter like this: 我虽然将图标添加到系列数据中,并在图例的labelFormatter中定义它,如下所示:

legend: {
  enabled: true,
  floating: true,
  borderWidth: 0,
  align: 'right',
  layout: 'vertical',
  verticalAlign: 'middle',
  itemMarginTop: 20,
  itemMarginBottom: 20,
  labelFormatter: function() {
    return '<span style="font-weight: normal;">' + this.name + ' </span> <span style:"font-weight: normal;"><b>€' + this.y + '<br/></span>';
  }
},

   series: [{
  name: 'Transactions',
  data: [{
    name: 'Carrots',
    y: 7450.00,
    icon: 'url(http://www.highcharts.com/demo/gfx/snow.png)'
  }, {
    name: 'Apples',
    y: 435.00,
    icon: 'url(http://www.highcharts.com/demo/gfx/snow.png)'
  }, {
    name: 'Oranges',
    y: 300.87,
    icon: 'url(http://www.highcharts.com/demo/gfx/snow.png)'
  }, {
    name: 'Lemons',
    y: 45.67,
    icon: 'url(http://www.highcharts.com/demo/gfx/snow.png)'
  }, {
    name: 'Limes',
    y: 42.45,
    icon: 'url(http://www.highcharts.com/demo/gfx/snow.png)'
  }],

would work the best but still no luck. 会工作得最好,但仍然没有运气。 Can anybody please enlighten me on what I'm doing wrong? 有人可以启发我做错什么吗? The whole code is here http://jsfiddle.net/tobitobetoby/1fqvzpdn/6/ 整个代码在这里http://jsfiddle.net/tobitobetoby/1fqvzpdn/6/

Thank you! 谢谢!

For your legend, you can enable HTML with the useHTML flag. 对于图例,可以使用useHTML标志启用HTML。 I also didn't see anywhere in your code where you were adding the image, so I added an image tag to the labelFormatter. 我也没有在代码中的任何地方看到要添加图像的位置,因此我将图像标签添加到了labelFormatter。

legend: {
  enabled: true,
  floating: true,
  borderWidth: 0,
  align: 'right',
  layout: 'vertical',
  verticalAlign: 'middle',
  itemMarginTop: 20,
  itemMarginBottom: 20,
  useHTML: true,
  labelFormatter: function() {
    return '<span style="font-weight: normal;">' + this.name + ' </span> <span style:"font-weight: normal;"><b>€' + this.y + '<br/><image src="' + this.icon +'" /></span>';
  }
},

http://jsfiddle.net/blaird/1fqvzpdn/8/ http://jsfiddle.net/blaird/1fqvzpdn/8/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM