簡體   English   中英

Highcharts圖表欄 - 如何在圖表中顯示HTML表格中的一列?

[英]Highcharts Chart Bar - How can I display in the chart, only one column from my HTML table?

我有一個條形圖,它從頁面中的HTML表中提取數據。 http://www.highcharts.com/demo/column-parsed

如果我們按照上面的例子, John comlumn ...如何只提取表格的一列...

這是構建serias的代碼

// the categories
options.xAxis.categories = [];
$('tbody th', table).each( function(i) {
    options.xAxis.categories.push(this.innerHTML);
});

// the data series
options.series = [];
$('tr', table).each( function(i) {
    var tr = this;
    $('th, td', tr).each( function(j) {
        if (j > 0) { // skip first column
            if (i == 0) { // get the name and init the series
                options.series[j - 1] = {
                    name: this.innerHTML,
                    data: []
                };
            } else { // add values
                options.series[j - 1].data.push(parseFloat(this.innerHTML));
            }
        }
    });
});

我試圖只讀取等於2的列,以便到達最后一列,但沒有成功

if (j == 2) { ... }

希望任何人都能得到比我更好的答案。 施洛米。

嘗試這個 :

options.series = [];
$('tr', table).each( function(i) {
    var tr = this;
    $('th, td', tr).each( function(j) {
        if (j == 2) { // get only column 2
            if (i == 0) { // get the name and init the series
                options.series[0] = {
                    name: this.innerHTML,
                    data: []
                };
            } else { // add values
                options.series[0].data.push(parseFloat(this.innerHTML));
            }
        }
    });
});

您需要檢查j == 2以便只獲取第二列中的數據,然后在創建options.series數組時需要使用0 - Highcharts至少需要series[0]數據series[0]

這里的工作示例

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM