如何在Highcharts中将HTML表格中的每一行做成饼图?

人们

例如,我的表将如下所示:

            agree neutral disagree
    q1      10     4       4
    q2      16     1       1
    q3      18     0       0
    q4      15     2       1
    q5      13     5       0

我想将q1做成一个饼图,不同部门同意,中立和不同意,q2,q3..etc类似。

    <script type="text/javascript">

         $(function () {
           var chart;
        $('#container').highcharts({
            data: {
                table: document.getElementById('datatable')
            },
            chart: {
                type: 'column'
            },
            title: {
                text: ''
            },
            yAxis: {
                allowDecimals: false,
                title: {
                    text: 'Persons'
                }
            },
            tooltip: {
                formatter: function() {
                    return '<b>'+ this.series.name +'</b><br/>'+
                        this.point.y +' individuals said '+ this.point.name.toLowerCase();
                }
            },

        });
    });

    /**********************************************

    **********************************************/


         $(function () {
           var chart;
        $('#container2').highcharts({
            data: {
                table: document.getElementById('datatable')
            },
            chart: {
                type: 'pie'
            },
            title: {
                text: ''
            },
            yAxis: {
                allowDecimals: false,
                title: {
                    text: 'Persons'
                }
            },
            tooltip: {
                formatter: function() {
                    return '<b>'+ this.series.name +'</b><br/>'+
                        this.point.y +' individuals said '+ this.point.name.toLowerCase();
                }
            },

        });
    });


    /**********************************************/

    /**********************************************/
    $(function () {
        var chart;
        $(document).ready(function() {
            chart = new Highcharts.Chart({
                chart: {
                    renderTo: 'container3',
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false,
                    margin: [0, 0, 0, 0],
                    spacingTop: 0,
                    spacingBottom: 0,
                    spacingLeft: 0,
                    spacingRight: 0             
                },
                title: {
                    text: ''
                },
                tooltip: {
                    formatter: function() {
                        return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
                    }
                },
                legend: {
                    enabled:true
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        size: '50%',
                        dataLabels: {
                            enabled: false
                        }
                    }
                },
                series: 
                [
                    {
                    type: 'pie',
                    name: 'testname1',
                    center: [70, 140],//+130 to the x-axis
                    showInLegend:true,
                    data: [
                        ['Commerce',   33.0],
                        ['Engineering',       32.3],
                        {
                            name: 'Financial Services',
                            y: 18.8,
                            sliced: true,
                            selected: true
                        },
                        ['Logistics, Aviation & Shipping',    5.5],
                        ['Seafood & Marine',     9.2],
                        ['Corporate Services & others',   1.2]
                    ]
                    }
                    ,{
                    type: 'pie',
                    name: 'testname2',
                    center: [200, 140],
                    showInLegend:false,
                    data: [
                        ['Commerce',   33.0],
                        ['Engineering',       32.3],
                        {
                            name: 'Financial Services',
                            y: 18.8,
                            sliced: true,
                            selected: true
                        },
                        ['Logistics, Aviation & Shipping',    5.5],
                        ['Seafood & Marine',     9.2],
                        ['Corporate Services & others',   1.2]
                    ]
                    },
                    {
                    type: 'pie',
                    name: 'testname3',
                    center: [330, 140],
                    showInLegend:false,
                    data: [
                        ['Commerce',   33.0],
                        ['Engineering',       32.3],
                        {
                            name: 'Financial Services',
                            y: 18.8,
                            sliced: true,
                            selected: true
                        },
                        ['Logistics, Aviation & Shipping',    5.5],
                        ['Seafood & Marine',     9.2],
                        ['Corporate Services & others',   1.2]
                    ]
                    },
                    {
                    type: 'pie',
                    name: 'testname4',
                    center: [460, 140],
                    showInLegend:false,
                    data: [
                        ['Commerce',   33.0],
                        ['Engineering',       32.3],
                        {
                            name: 'Financial Services',
                            y: 18.8,
                            sliced: true,
                            selected: true
                        },
                        ['Logistics, Aviation & Shipping',    5.5],
                        ['Seafood & Marine',     9.2],
                        ['Corporate Services & others',   1.2]
                    ]
                    },
                    {
                    type: 'pie',
                    name: 'testname5',
                    center: [590, 140],
                    showInLegend:false,
                    data: [
                        ['Commerce',   33.0],
                        ['Engineering',       32.3],
                        {
                            name: 'Financial Services',
                            y: 18.8,
                            sliced: true,
                            selected: true
                        },
                        ['Logistics, Aviation & Shipping',    5.5],
                        ['Seafood & Marine',     9.2],
                        ['Corporate Services & others',   1.2]
                    ]
                    },
                    {
                    type: 'pie',
                    name: 'testname6',
                    center: [720, 140],
                    showInLegend:false,
                    data: [
                        ['Commerce',   33.0],
                        ['Engineering',       32.3],
                        {
                            name: 'Financial Services',
                            y: 18.8,
                            sliced: true,
                            selected: true
                        },
                        ['Logistics, Aviation & Shipping',    5.5],
                        ['Seafood & Marine',     9.2],
                        ['Corporate Services & others',   1.2]
                    ]
                    },
                    {
                    type: 'pie',
                    name: 'testname7',
                    center: [850, 140],
                    showInLegend:false,
                    data: [
                        ['Commerce',   33.0],
                        ['Engineering',       32.3],
                        {
                            name: 'Financial Services',
                            y: 18.8,
                            sliced: true,
                            selected: true
                        },
                        ['Logistics, Aviation & Shipping',    5.5],
                        ['Seafood & Marine',     9.2],
                        ['Corporate Services & others',   1.2]
                    ]
                    },
                    {
                    type: 'pie',
                    name: 'testname8',
                    center: [980, 140],
                    showInLegend:false,
                    data: [
                        ['Commerce',   33.0],
                        ['Engineering',       32.3],
                        {
                            name: 'Financial Services',
                            y: 18.8,
                            sliced: true,
                            selected: true
                        },
                        ['Logistics, Aviation & Shipping',    5.5],
                        ['Seafood & Marine',     9.2],
                        ['Corporate Services & others',   1.2]
                    ]
                    }

                ]

            },function(chart) {

            $(chart.series[0].data).each(function(i, e) {
                e.legendItem.on('click', function(event) {
                    var legendItem=e.name;

                    event.stopPropagation();

                    $(chart.series).each(function(j,f){
                           $(this.data).each(function(k,z){
                               if(z.name==legendItem)
                               {
                                   if(z.visible)
                                   {
                                       z.setVisible(false);
                                   }
                                   else
                                   {
                                       z.setVisible(true);
                                   }
                               }
                           });
                    });

                });
            });
        });
        });

    });


    </script>

注意:第一个图表成功地从我正在使用的表中提取数据。

另外两个是我试图回答我的问题的尝试。

这是我发布的代码的结果:

http://tinypic.com/r/11uyj3s/8

PawełFus

示例:http//jsfiddle.net/4Kn5t/

您需要为每个图表设置三个额外的选项,以告诉饼图应使用哪些行:

$('#container2').highcharts({
    data: {
        table: document.getElementById('datatable'),
        switchRowsAndColumns: true, // use rows as points
        startRow: 1, 
        endRow: 2 // use row == 2
    },
    chart: {
        type: 'pie'
    },
    title: {
        text: 'Data extracted from a HTML table in the page'
    },
    yAxis: {
        allowDecimals: false,
        title: {
            text: 'Units'
        }
    },
    tooltip: {
        formatter: function() {
            return '<b>'+ this.series.name +'</b><br/>'+
                this.point.y +' '+ this.point.name.toLowerCase();
        }
    }
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Highcharts中将HTML表格中的每一行做成饼图?

来自分类Dev

HTML如何使表格的每一行都可滚动?

来自分类Dev

如何在表格的每一行中添加删除按钮?

来自分类Dev

如何自动对HTML表格中每一行的输入值框求和

来自分类Dev

如何在Shell脚本中将文本中的每一行分配给数组?

来自分类Dev

Highcharts饼图。如何在两行中设置标签

来自分类Dev

如何在表格中为Oracle APEX中的每一行访问选择列表中的列值

来自分类Dev

如何在HTML的每一行中添加按钮/超链接

来自分类Dev

如何在js中将每一行的背景颜色一一移走并从上一颜色中删除颜色

来自分类Dev

如果每一行包含不同数量的视图,如何在表格布局中制作大小相同的视图?

来自分类Dev

如何在getline()中的每一行中移动

来自分类Dev

如何在PHP中显示每一行的编号

来自分类Dev

如何在列表中的每一行之间画线?

来自分类Dev

如何在PHP中显示每一行的编号

来自分类Dev

如何在表格的每一行之间获得一条实线?

来自分类Dev

如何在终端中将文件名中的字符附加到文件每一行的末尾?

来自分类Dev

饼图或表格的行

来自分类Dev

如何在表格中添加一行?

来自分类Dev

如何为表格中的每一行生成唯一的URL?

来自分类Dev

如何绘制,其中矩阵中的每一行都是R中的线积分图

来自分类Dev

如何绘制,其中矩阵中的每一行都是R中的线积分图

来自分类Dev

如何在R中将每一行或观察结果作为单个文件写出

来自分类Dev

如何在ListView的每一行中将Text设置为TextView

来自分类Dev

如何在bash中将文件的每一行用作输入开关?

来自分类Dev

如何在包含数字 1 的每一行中将数字增加 1

来自分类Dev

如何获取表格视图的每一行?

来自分类Dev

如何获取表格视图的每一行?

来自分类Dev

Google表格:如何找到每列的最后一行?

来自分类Dev

数据框中每一行的条形图

Related 相关文章

  1. 1

    如何在Highcharts中将HTML表格中的每一行做成饼图?

  2. 2

    HTML如何使表格的每一行都可滚动?

  3. 3

    如何在表格的每一行中添加删除按钮?

  4. 4

    如何自动对HTML表格中每一行的输入值框求和

  5. 5

    如何在Shell脚本中将文本中的每一行分配给数组?

  6. 6

    Highcharts饼图。如何在两行中设置标签

  7. 7

    如何在表格中为Oracle APEX中的每一行访问选择列表中的列值

  8. 8

    如何在HTML的每一行中添加按钮/超链接

  9. 9

    如何在js中将每一行的背景颜色一一移走并从上一颜色中删除颜色

  10. 10

    如果每一行包含不同数量的视图,如何在表格布局中制作大小相同的视图?

  11. 11

    如何在getline()中的每一行中移动

  12. 12

    如何在PHP中显示每一行的编号

  13. 13

    如何在列表中的每一行之间画线?

  14. 14

    如何在PHP中显示每一行的编号

  15. 15

    如何在表格的每一行之间获得一条实线?

  16. 16

    如何在终端中将文件名中的字符附加到文件每一行的末尾?

  17. 17

    饼图或表格的行

  18. 18

    如何在表格中添加一行?

  19. 19

    如何为表格中的每一行生成唯一的URL?

  20. 20

    如何绘制,其中矩阵中的每一行都是R中的线积分图

  21. 21

    如何绘制,其中矩阵中的每一行都是R中的线积分图

  22. 22

    如何在R中将每一行或观察结果作为单个文件写出

  23. 23

    如何在ListView的每一行中将Text设置为TextView

  24. 24

    如何在bash中将文件的每一行用作输入开关?

  25. 25

    如何在包含数字 1 的每一行中将数字增加 1

  26. 26

    如何获取表格视图的每一行?

  27. 27

    如何获取表格视图的每一行?

  28. 28

    Google表格:如何找到每列的最后一行?

  29. 29

    数据框中每一行的条形图

热门标签

归档