Highcharts Legend Custom HTML

夙愿已清 提交于 2020-03-23 04:05:30

问题


I have a highcharts graph and I'm looking to collect some data from the user about each line graphed. I'm trying to have a text input box with an id or a name related to the series name to appear next to each label in the legend. I could then have a button and code to submit the collected data to the server elsewhere.

I've tried setting a labelFormatter function, but that appears to only support plain text.

Is there an easy way to do this with highcharts or am I looking at writing my own function using the highchart event hooks that will go in and add the html I want?

Any help is appreciated. Thanks!


回答1:


when you want working html in any type of labels/tooltips you need to set useHTML to true (not in documentation:/). It gives some problembs in posistioning but can render any html.

example

plotOptions : {
   series: {
     dataLabels: {
       useHTML: true
     }
   }
}



回答2:


You can set the useHTML option of Highcharts legend to true.

legend: {
    useHTML: true,
    labelFormatter: function () {
        return '<span title="' + this.name + '">' + this.name + '</span>';
    }
}

http://api.highcharts.com/highcharts/legend.useHTML




回答3:


Take a look this example. http://jsfiddle.net/LCFKA/ You have to set your series' data inside the loadedData and then you just have to set in the function getItemsDescription what do you want to show.




回答4:


So I eventually came up with a "solution" to this. I'm not sure if it's the best, but I wanted to leave a note here in case anyone else needs it.

I ended up extending the highstock source code and copied their showCheckbox code to be a showTextbox code. It's not a very generic solution, but it solved my particular problem. I also had to modify the onmousedown handler to allow passing focus through to the text box when it's clicked on.

The boxes are rendered in html with exact position so they appear next to the legend items. The legend itself is part of the SVG of the graph which makes it rather difficult to get other html in there.

If you'd like all the code - leave a comment and I'll post it.



来源:https://stackoverflow.com/questions/9416310/highcharts-legend-custom-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!