2013-02-14 236 views
2

創建JSON對象,我現在有一個Highcharts在我的代碼,我使用的JavaScript創建JSON對象按摩數據,代碼片段看起來像使用打字稿

var yearChartOptions = { 
    chart: { 
     renderTo: 'YearChartContainer', 
     type: 'column', 
     margin: [ 50, 50, 50, 50] 
    }, 
    title: { 
     text: '' 
    }, 
    xAxis: { 
     categories: [], 
     labels: { 
      rotation: -90, 
      align: 'right' 
     } 
    }, 
    yAxis: { 
     title: { 
      text: '' 
     }, 
     plotLines: [{ 
      color: '#FF0000', 
      width: 2, 
      label: { 
       style: { 
        color: 'blue', 
        fontWeight: 'bold', 
        zIndex: -1 
       }, 
       formatter: function() { 
        return '$' + Highcharts.numberFormat(this.value/1000, 0) +'k '; 
       } 
      }, 
      zIndex: 10 
     }] 
    }, 
}; 

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

我怎樣才能在打字稿寫有相同的JavaScript結果?

+1

'yearChartOptions'是一個JavaScript對象。 [沒有像「JSON對象」](http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/)。 – 2013-02-14 01:18:45

+0

你的意思是我需要自己創建Highcharts對象? – hardywang 2013-02-14 01:22:56

回答

4

將一個/// <reference path="highcharts.d.ts" />標記添加到您的文件。您可以從DefinitelyTyped獲取文件。一切都應該從那裏開始。

+0

謝謝,很高興知道這是一個高分辨率的定義。 – hardywang 2013-02-14 01:39:14