繁体   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