Highcharts: How to add a table of values with scrollbar?

走远了吗. 提交于 2019-12-25 08:13:57

问题


This is one of my failed attempts:

http://jsfiddle.net/mm484L57/

Highcharts.drawTable = function() {

// user options
var tableTop = 310,
    colWidth = 100,
    tableLeft = 20,
    rowHeight = 20,
    cellPadding = 2.5,
    valueDecimals = 1,
    valueSuffix = ' °C';

// internal variables
var chart = this,
    series = chart.series,
    renderer = chart.renderer,
    cellLeft = tableLeft;

// draw category labels
$.each(chart.xAxis[0].categories, function(i, name) {
    renderer.text(
        name, 
        cellLeft + cellPadding, 
        tableTop + (i + 2) * rowHeight - cellPadding
    )
    .css({
        fontWeight: 'bold'
    })       
    .add();
});

$.each(series, function(i, serie) {
    cellLeft += colWidth;

    // Apply the cell text
    renderer.text(
            serie.name,
            cellLeft - cellPadding + colWidth, 
            tableTop + rowHeight - cellPadding
        )
        .attr({
            align: 'right'
        })
        .css({
            fontWeight: 'bold'
        })
        .add();

    $.each(serie.data, function(row, point) {

        // Apply the cell text
        renderer.text(
                Highcharts.numberFormat(point.y, valueDecimals) + valueSuffix, 
                cellLeft + colWidth - cellPadding, 
                tableTop + (row + 2) * rowHeight - cellPadding
            )
            .attr({
                align: 'right'
            })
            .add();

        // horizontal lines
        if (row == 0) {
            Highcharts.tableLine( // top
                renderer,
                tableLeft, 
                tableTop + cellPadding,
                cellLeft + colWidth, 
                tableTop + cellPadding
            );
            Highcharts.tableLine( // bottom
                renderer,
                tableLeft, 
                tableTop + (serie.data.length + 1) * rowHeight + cellPadding,
                cellLeft + colWidth, 
                tableTop + (serie.data.length + 1) * rowHeight + cellPadding
            );
        }
        // horizontal line
        Highcharts.tableLine(
            renderer,
            tableLeft, 
            tableTop + row * rowHeight + rowHeight + cellPadding,
            cellLeft + colWidth, 
            tableTop + row * rowHeight + rowHeight + cellPadding
        );

    });

    // vertical lines        
    if (i == 0) { // left table border  
        Highcharts.tableLine(
            renderer,
            tableLeft, 
            tableTop + cellPadding,
            tableLeft, 
            tableTop + (serie.data.length + 1) * rowHeight + cellPadding
        );
    }

    Highcharts.tableLine(
        renderer,
        cellLeft, 
        tableTop + cellPadding,
        cellLeft, 
        tableTop + (serie.data.length + 1) * rowHeight + cellPadding
    );

    if (i == series.length - 1) { // right table border    

        Highcharts.tableLine(
            renderer,
            cellLeft + colWidth, 
            tableTop + cellPadding,
            cellLeft + colWidth, 
            tableTop + (serie.data.length + 1) * rowHeight + cellPadding
        );
    }

});

The first part of the code is to create the table and the second is the chart.

The idea is that you can display the entire table of values although the graphics have a lot of values.

I tried to integrate the scrollbar of Highstock but not recognized as part of the graph too.

I think taht the main problem is that is not integrated in the DOM Highcharts but being integrated graphics not know how to format it with jQuery.

Any idea?

来源:https://stackoverflow.com/questions/38434666/highcharts-how-to-add-a-table-of-values-with-scrollbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!