Javascript Highcharts图表栏-如何在图表中显示HTML表格中的一列?

Javascript Highcharts图表栏-如何在图表中显示HTML表格中的一列?,javascript,jquery,highcharts,Javascript,Jquery,Highcharts,我得到了一个条形图,它从页面中的HTML表中提取数据。 如果我们按照上面的例子,Johncomlumn,我如何只提取表中的一列 这是构建系列的代码 // the categories options.xAxis.categories = []; $('tbody th', table).each( function(i) { options.xAxis.categories.push(this.innerHTML); }); // the data series options.se

我得到了一个条形图,它从页面中的HTML表中提取数据。

如果我们按照上面的例子,Johncomlumn,我如何只提取表中的一列

这是构建系列的代码

// 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) { ... }
希望任何人都能有比我更好的答案。 Shlomi.

试试这个:

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
以便只获取第2列中的数据,然后在创建
选项.series
数组时,您需要使用
0
-Highcharts至少需要
series[0]