简体   繁体   English

Highchart-在PlotLine标签上使用格式化程序

[英]Highchart - Use a formatter on PlotLine labels

I'm using highchart to show some text next to a plot line on the xAxis. 我正在使用highchart在xAxis上的绘图线旁边显示一些文本。 I would like to customize each label from a formatter function as it is possible on every other labels in the chart. 我想通过格式化程序功能自定义每个标签,因为在图表中的每个其他标签上都有可能。

I've seen another topic on this matter but they're using TypeScript and I don't. 我看到了与此相关的另一个主题,但是他们正在使用TypeScript,但我没有。

What I'm doing is : 我正在做的是:

vay chart = new HighChart({
...
xAxis: {
        plotLines: [{
            id: "plotLines",
            zIndex: 15,
            color: myColor,
            width: 1,
            value: theXvalue, //x value where to show the line
            label: {
                formatter: function () {
                    return " VAL > "+this.value;
               }
            },
        }]
    },
    ...
});

If I set the 'text' value in the label it shows up and it works like a charm. 如果我在标签中设置了“文本”值,它将显示出来,并且就像一个超级按钮。

Any help to use a formatter for those labels ? 对这些标签使用格式化程序有帮助吗?

不幸的是您不能使用格式化程序,您应该在文本对象中定义标签的内容,可以将其包装在html元素中,但是随后您需要设置[useHTML( http://api.highcharts.com/highcharts#xAxis.plotLines.label .useHTML )参数

Set the useHTML value to true and set your html content inside text. 将useHTML值设置为true并在文本内设置html内容。 Here is an example of how to achieve it http://jsfiddle.net/9mvwpqf3/1/ 这是一个如何实现的示例http://jsfiddle.net/9mvwpqf3/1/

yAxis: { plotLines: [{ color: 'red', width: 2, value: 100, label: { useHTML: true, text: '<button>Click Me</button>', }, }] },

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

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