2013-03-29 32 views
0

enter image description here調整X比例在highchart顯示適當比例

基地圖像,每個X值有20點不同 和線應顯示爲直線。

但是由於我添加了2值1025.96和1026.50(如右邊表格中的顏色背景所示),並且它仍然對每個數字使用相同的比例,所以線圖不是筆直的。

如何在圖表中調整這2點顯示並使其繪製合適的比例? (顯示直線)。

$(document).ready(function() { 


    chart = new Highcharts.Chart({ 
     chart: { 
      renderTo: 'container2950', 
      type: 'line', 
      marginRight: 130, 
      marginBottom: 45 
     }, 
     title: { 
      text: 'Strategy 2, Long C950', 
      x: -20 //center 
     }, 
     subtitle: { 
      text: '', 
      x: -20 
     }, 
     credits: { 
enabled: false 
    }, 
     xAxis: { 
    title: { 
       text: 'SET50 Index ณ วันหมดอายุ' 
      }, 
    categories:  [925,945,965,985,1005,1025,1025.96,1026.5,1045,1065,1085,1105,1125] 

     }, 
     yAxis: { 
      title: { 
       text: 'Profit/Loss (Bath)' 
      }, 
      plotLines: [{ 
       value: 0, 
       width: 1, 
       color: '#808080' 
      }] 
     }, 
     tooltip: { 
      formatter: function() { 
        return '<b>'+ this.series.name +'</b><br/>'+ 
        this.x +': '+ this.y +' บาท'; 
      } 
     }, 
     legend: { 
      layout: 'vertical', 
      align: 'right', 
      verticalAlign: 'top', 
      x: -10, 
      y: 100, 
      borderWidth: 0 
     }, 
     series: [ 
     {name: 'Long C950', data:  [-15300,-15300,-12300,-8300,-4300,-300,-107.99999999999,0,3700,7700,11700,15700,19700]} 
     ] 

    }); 
}); 

回答

1

無需任何代碼,看看,我不能肯定,但我懷疑你指定x軸的類別。這將始終等間隔x軸參數,而不是繪製它們的比例。

相反,你應該像這樣指定一系列的數據:

data:[ [925,-15300],[945,-15300] ] 

這指定的x,y值對。你也可以這樣做:

data:[ {x:925,y:-15300},{x:945,y:-15300} ] 

第二個選項允許你設置其他點屬性,如顏色等

+0

請找我上面的代碼,並再次諮詢我。 – user2194507

+0

我是對的。刪除xAxis中的類別並按照我的第一個示例中的建議指定您的數據。我只向他們展示了前兩點,但可以用這種方式指定所有點。 – SteveP

+0

看起來很好。非常感謝你。 :-) – user2194507