1

我想使用 Highcharts 在饼图中显示数据表。我可以在外面显示表,但是在导出图像时,数据表不会被导出。所以我的目标是在饼图中显示数据表。参考这个。我能够部分实现它。演示

但是我怎样才能给它列标题和边框呢?

$(function () {


   Highcharts.drawTable = function() {

    // user options
    var tableTop = 200,
        colWidth = 60,
        tableLeft = 50,
        rowHeight = 20,
        cellPadding = 2.5,
        valueDecimals = 1,
        valueSuffix = '';

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

    // draw category labels
    $.each(series, function(serie_index, serie) {
        renderer.text(
            serie.name, 
            cellLeft + cellPadding, 
            tableTop + (serie_index + 1) * rowHeight - cellPadding
        )
        .css({
            fontWeight: 'bold'
        })       
        .add();
    });



        $.each(series[0].data, function(i) {

            renderer.text(
                    series[0].data[i].name, 
                    cellLeft + colWidth - cellPadding, 
                    tableTop + (i + 2) * rowHeight - cellPadding
                )
                .attr({
                    align: 'right'
                })
                .add();
        });
     $.each(series[0].data, function(i) {
            renderer.text(
                    Highcharts.numberFormat(series[0].data[i].y, valueDecimals) + valueSuffix, 
                    150, 
                    tableTop + (i + 2) * rowHeight - cellPadding
                )
                .attr({
                    align: 'left'
                })
                .add();

        });



}




$('#container').highcharts({
    chart: {
        plotBackgroundColor: null,
        plotBorderWidth: null,
        plotShadow: false,
        events: {
            load: Highcharts.drawTable
        },
        height: 600,
        width: 800,
        marginBottom: 250
    },
    title: {
        text: 'Browser market shares at a specific website, 2010'
    },
    tooltip: {
        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    },
    plotOptions: {
        pie: {
            allowPointSelect: true,
            cursor: 'pointer',
            dataLabels: {
                enabled: true,
                color: '#000000',
                connectorColor: '#000000',
                format: '<b>{point.name}</b>: {point.percentage:.1f} %'
            }
        }
    },
    series: [{
        type: 'pie',
        name: 'Browser share',
        data: [
            ['Firefox',   45.0],
            ['IE',       26.8],
            {
                name: 'Chrome',
                y: 12.8,
                sliced: true,
                selected: true
            },
            ['Safari',    8.5],
            ['Opera',     6.2],
            ['Others',   0.7]
        ]
    }]
});
});
4

1 回答 1

0

对于列标题,我不知道。取决于你想做什么。

至于边框,因为那是 SVG,你可以使用RECTand来绘制边框PATH。看看你的演示的这个分支,了解一些粗略的边界,也许你可以改进它。

于 2013-06-23T11:42:29.250 回答