2013-02-14 126 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