2013-02-15 6 views
7

y 축 레이블을 설정하는 방법은 Highcharts text labels for y-axis 토론을 참조하십시오.하이 차트 TypeScript, y 축 레이블

TypeScript 정의에 https://github.com/borisyankov/DefinitelyTyped/blob/master/highcharts/highcharts.d.ts을 사용했지만 y 축 포맷터를 정의하는 방법을 찾을 수 없습니다.

누구도 전에 시도한 적이 있습니까?

- 업데이트 -

내 origianl 자바 스크립트 코드는 내가 각 막대입니다 이는 this.value있는 코드에서

var yearChartOptions = { 
    yAxis: { 
     plotLines: [{ 
      label: { 
       formatter: function() { 
        return '$' + Highcharts.numberFormat(this.value/1000, 0) +'k '; 
       } 
      }, 
     }] 
    }, 
}; 

// Create the chart 
var yearChart = new Highcharts.Chart(yearChartOptions); 

입니다 값 (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' 
*/ 

입니다 그리고 그것은 컴파일되지 않습니다.

+0

가능한 중복 http://stackoverflow.com/questions/4987457/highcharts-text-labels-for-y- :

완벽하게 작동 예를 들어 당신의 코드를 기반으로 축) –

+1

나는 이것이 중복이라고 생각하지 않는다. 포스터가 해당 답변과 같은 코드를 사용하려고하지만 TypeScript 컴파일러가이를 거부합니다. – Fenton

+0

@hardywang 업데이트 된 정의가 문제를 해결 했습니까? – Fenton

답변

2

- 에는 최신 버전이 포함되어있어 문제를 해결할 수 있습니다.

하이 차트의 유형 정의는 amd 배열을 yAxis에 전달해야 함을 나타냅니다. 이것은 TypeScript에서 컴파일됩니다.

var chart = new Highcharts.Chart({ 
    yAxis: [{ 
     labels: { 
      formatter: function(): string { 
       return 'My Label'; 
      } 
     } 
    }] 
}); 

그러나, 나는이되지 이러한 개체의 많은의 배열로, the documentation, which suggests you pass the yAxis options as an object 일치하는지 모르겠어요. 이것은 또한 하나의 yAxis가 있다는 관점에서 의미가 있습니다. 가 당신은 당신의 highchart.d.ts 파일을 여기에 조정할 수 있습니다

...

interface HighchartsOptions { 
    chart?: HighchartsChartOptions; 
    // others... 
    yAxis?: HighchartsAxisOptions; // <-- remove the [] from this line 
} 

내가

/// <reference path="highchart.d.ts" /> 

var yearChartOptions: HighchartsOptions = { 
    yAxis: { 
     plotLines: { 
      label: { 
       formatter: function(): string { 
        return '$' + Highcharts.numberFormat(this.value/1000, 0) + 'k '; 
       } 
      }, 
     } 
    } 
}; 


// Create the chart 
var yearChart = new Highcharts.Chart(yearChartOptions); 
를 제출 한 :

내가 유효한 버전 (즉,하지 배열)입니다 믿는 것을 달성하기 위해 이 문제를 해결하기 위해 명확하게 유형화 된 요청을 요청합니다.

[y 축에 대한 Highcharts 텍스트 레이블] (의
+0

'yearChartOptions.yAxis.plotLines.label.style.formatter (() => "$"+ Highcharts.numberFormat (this.value/1000, 0) + "k") 때문에'여전히 컴파일 오류가 발생했습니다. 발견되어'this' 키워드가 인식되지 않습니다. 샘플 http://stackoverflow.com/questions/4987457/highcharts-text-labels-for-y-axis 및 문서 http://api.highcharts.com/highcharts#yAxis.labels.formatter – hardywang

+0

아래 예제를 업데이트했습니다. '내가 믿는 것을 성취하는 것은 유효한 버전이다 '라는 코멘트. – Fenton

+0

고마워, 나는 개체 내에서 개체를 인스턴스화하는 구문을 시도하고 작동합니다. 내 방식이 무엇이 잘못되었는지, 객체를 인스턴스화 한 다음 객체의 속성을 설정할 수는 있지만 작동하지 않습니다. – hardywang

관련 문제