Please refer to discussion Highcharts text labels for y-axis the way to setup y-axis label.
I used https://github.com/borisyankov/DefinitelyTyped/blob/master/highcharts/highcharts.d.ts in my TypeScript definition, but I could not find a way to define y-axis formatter.
Anybody ever tried before?
-- Update --
My origianl JavaScript code is
var yearChartOptions = {
yAxis: {
plotLines: [{
label: {
formatter: function () {
return '$' + Highcharts.numberFormat(this.value/1000, 0) +'k ';
}
},
}]
},
};
// Create the chart
var yearChart = new Highcharts.Chart(yearChartOptions);
In the code I have a this.value which is each bar (I used bar chart) value. In TypeScript (I have not changed to remove array yet).
var yearChartOptions: HighchartsOptions = {};
yearChartOptions.chart = {};
yearChartOptions.yAxis = [];
yearChartOptions.yAxis[0] = {};
yearChartOptions.yAxis[0].plotLines = {};
yearChartOptions.yAxis[0].plotLines.label = {};
yearChartOptions.yAxis[0].plotLines.label.style.formatter(() => "$" + Highcharts.numberFormat(this.value / 1000, 0) + "k ");
// Create the chart
var yearChart = new Highcharts.Chart(yearChartOptions);
The output is
/*
Compile Error.
See error list for details
D:/MyProject/Scripts/test.ts(36,56): The property 'formatter' does not exist on value of type 'HighchartsCSSObject'
D:/MyProject/Scripts/test.ts(36,107): The property 'value' does not exist on value of type 'Dashboard'
*/
And it won't compile.
Update - The Definitely Typed Highcharts definition now has my fix, so you can download the latest version and hopefully it will solve your problem.
The type definition for Highcharts suggests you need to pass amd array of options to yAxis. This compiles in TypeScript.
However, I'm not sure this matches the documentation, which suggests you pass the yAxis options as an object, not as an array of many of these objects. This also makes sense from the point of view that you have a single yAxis.
To achieve what I believe is the valid version (i.e. not arrays):
You can adjust your highchart.d.ts file here...
I have submitted a pull request to Definitely Typed to fix this.
Fully working example based on your code: