請參考討論Highcharts text labels for y-axis的方式設置y軸標籤。Highcharts打字稿,y軸標籤
我在打字稿定義中使用https://github.com/borisyankov/DefinitelyTyped/blob/master/highcharts/highcharts.d.ts,但我無法找到一個方法來定義y軸格式。
任何人之前沒有試過?
- 更新 -
我的原著JavaScript代碼是
var yearChartOptions = {
yAxis: {
plotLines: [{
label: {
formatter: function() {
return '$' + Highcharts.numberFormat(this.value/1000, 0) +'k ';
}
},
}]
},
};
// Create the chart
var yearChart = new Highcharts.Chart(yearChartOptions);
在代碼我有一個THIS.VALUE其是每個杆(I使用條形圖)值。在TypeScript中(我還沒有改變,以刪除數組呢)。
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);
輸出是
/*
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'
*/
,它不會編譯。
可能重複http://stackoverflow.com/questions/4987457/highcharts-text-labels-for-y-軸) – 2013-02-15 06:48:46
我不認爲這是重複的。海報正在嘗試使用該答案中的代碼,但是TypeScript編譯器正在拒絕它。 – Fenton 2013-02-15 10:01:11
@hardywang做了更新的定義解決你的問題? – Fenton 2013-02-18 15:10:49