简体   繁体   中英

Showing a value as DataLabel in HighCharts

https://jsfiddle.net/5v7xy8re/4/

series: [{
        data: [{
                y: 9.5,
            MYVALUE: 95
        }],
        dataLabels: {
            format: '<div style="text-align:center"><span style="font-size:25px;color:' +
                ((Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black') + '">{MYVALUE}</span><br/>' +
                   '<span style="font-size:12px;color:silver"></span></div>'
        },
    }]

I need to show either y or y * 10 depending on a condition and I should not change the value y in data. So I wanted to show MYVALUE as datalabel by accesing it instead of y. Is that possible to do it? When I run my code, it prints nothing on the screen. Thanks

To reference custom data values in format, you need to specify that it belongs to the point. Ie {point.MYVALUE} . Similarly, if you want to access a series custom point, you would need to write {series.MYSERIESVALUE} .

Working example: https://jsfiddle.net/ewolden/reLab5s7/1/

More information here: https://www.highcharts.com/docs/chart-concepts/labels-and-string-formatting

And here: https://api.highcharts.com/highcharts/tooltip.pointFormat

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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