2014-07-21 60 views
1

我有一個圖表顯示收到1 - 5(1星級,2星級等)的項目收到的數量,但我無法讓它正確顯示圖表。這是我來得到它顯示最接近:Highcharts相同類型的數據與不同系列

$('#chartdiv').highcharts({ 
    chart: { 
     type: "column" 
    }, 
    title: { 
     text: 'My Ads' 
    }, 
    xAxis: { 
     categories: ["1 Star", "2 Stars", "3 Stars", "4 Stars", "5 Stars"], 
     tickInterval: 1, 
     labels: { 
      rotation: -20, 
      style: { 
       fontSize: '13px', 
       fontFamily: 'Verdana, sans-serif' 
      } 
     } 
    }, 
    yAxis: { 
     "min": 0, 
     "title": { 
      "text": "Number of Ratings" 
     } 
    }, 
    series: [{ 
     "name": "1 Stars", 
     "data": [10] 
    }, { 
     "name": "2 Stars", 
     "data": [42] 
    }, { 
     "name": "3 Stars", 
     "data": [60] 
    }, { 
     "name": "4 Stars", 
     "data": [110] 
    }, { 
     "name": "5 Stars", 
     "data": [100] 
    }], 
    tooltip: { 
     //shared: true, 
     crosshairs: false 
    }, 
    series: series, 
}); 

,這裏是什麼樣子:

Output

我怎樣才能得到它像她那樣,但有都標籤?我一直在使用這樣的數據集也試過:

[{ 
    "data": [10, 0, 0, 0, 0] 
}, { 
    "data": [0, 42, 0, 0, 0] 
}, { 
    "data": [0, 0, 60, 0, 0] 
}, { 
    "data": [0, 0, 0, 110, 0] 
}, { 
    "data": [0, 0, 0, 0, 100] 
}], 

,這讓我這個輸出

Graph 2

那些被間隔太遠,所以基本上我怎麼能得到這個顯示像第一個圖像,但每個數據集中只有一個項目?

------------
UPDATE:
------------

該系列爲我工作。我唯一的問題是它在工具提示中說Series 1: 10(圖像有點模糊,抱歉)。

Graph 3

"series": [{ 
     "data": [{ 
       "name": "1 Star", 
       "y": 10 
      }, { 
       "name": "2 Stars", 
       "y": 42 
      }, { 
       "name": "3 Stars", 
       "y": 60 
      }, { 
       "name": "4 Stars", 
       "y": 110 
      }, { 
       "name": "5 Stars", 
       "y": 100 
      }] 
    }], 
+1

'唯一的問題是它說的系列1:10在工具提示中 - 你想說什麼? – Mark

+0

工具提示中應該包含哪些值? –

回答

1

您可以嘗試使用這些設置(嘗試用pointWidth玩 - 列的寬度)

 plotOptions: { 
      series: { 
       pointPadding: 0.2, 
       groupPadding: 0, 
       pointWidth: 50//width of the column 
      }, 
      column: { 
         pointPadding: 0, 
         borderWidth: 0 
        } 
     }, 
    tooltip: { 
     formatter: function() { 
     return 'The value for <b>' + this.x + '</b> is <b>'+ '</b>, in series '+ this.series.name; 
    } 

更新 - 我已經添加了自定義提示

+0

我已更新我的問題,請看看 –

+0

@RyanNaddy我已更新我的答案。您需要使用自定義「工具提示」。請再次查看我的代碼。 – Oyeme

0

我能夠得到我正在尋找使用這個系列的東西:

"series": [{ 
     "name": "Number of Ratings", 
     "data": [{ 
       "name": "1 Star", 
       "y": 10 
      }, { 
       "name": "2 Stars", 
       "y": 42 
      }, { 
       "name": "3 Stars", 
       "y": 60 
      }, { 
       "name": "4 Stars", 
       "y": 110 
      }, { 
       "name": "5 Stars", 
       "y": 100 
      }] 
    }], 
相關問題