Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9228765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:24:23+00:00 2026-06-18T05:24:23+00:00

I am displaying data from html table to pie chart (HighChart). I want to

  • 0

I am displaying data from html table to pie chart (HighChart).
I want to display text which are between <th>..</th> tag of table tag.
But instead of text .. it displays slice … slice .. slice everywhere wherever is partition.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Pie Charts</title>
    <script src="js/jquery-migrate-1.0.0.js" type="text/javascript"></script>
    <script src="js/jquery.js" type="text/javascript"></script>
    <script>
        $(function () 
        {
            // On document ready, call visualize on the datatable.
            $(document).ready(function () 
            {
                /**
                * Visualize an HTML table using Highcharts. The top (horizontal) header
                * is used for series names, and the left (vertical) header is used
                * for category names. This function is based on jQuery.
                * @param {Object} table The reference to the HTML table to visualize
                * @param {Object} options Highcharts options
                */
                Highcharts.visualize = function (table, options) 
                {
                    // 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));
                                }
                            }
                        });
                    });

                    var chart = new Highcharts.Chart(options);
                }

                var table = document.getElementById('datatable'),
        options = {
            chart: {
                renderTo: 'container',
                type: 'pie'
            },
            title: {
                text: 'Data extracted from a HTML table in the page'
            },
            xAxis: {
        },
        yAxis: {
            title: {
                text: 'Units'
            }
        },
        tooltip: 
       {
            formatter: function() 
           {
               return '<b>'+ this.series.name +'</b><br/>'+
                  this.y +' '+ this.point.name;
            }
       },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    color: '#000000',
                    connectorColor: '#000000',
                    formatter: function () {
                        return '<b>' + this.point.name + '</b>: ' + this.percentage + ' %';
                    }
                }
            }
        }
    };

                Highcharts.visualize(table, options);
            });

        });

    </script>
</head>
<body>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>

<table id="datatable" border=1>
    <thead>
        <tr>
            <th>Fruits</th>
            <th>Qty</th>

        </tr>
    </thead>
    <tbody>
        <tr>
            <th>Apples</th>
            <td>3</td>

        </tr>
        <tr>
            <th>Pears</th>
            <td>2</td>

        </tr>
        <tr>
            <th>Plums</th>
            <td>5</td>

        </tr>
        <tr>
            <th>Bananas</th>
            <td>1</td>

        </tr>
        <tr>
            <th>Oranges</th>
            <td>2</td>

        </tr>
    </tbody>
</table>
</body>
</html>

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:24:24+00:00Added an answer on June 18, 2026 at 5:24 am

    You should not give the slices name through xAxis’ categories field. Slice names should be included in the data object. Try this:

    sliceNames = [];
    $('tbody th', table).each(function (i) 
    {
        sliceNames.push(this.innerHTML);
    });
    
    options.series[j - 1].data.push({name: sliceNames[i - 1], y: parseFloat(this.innerHTML)});
    

    You don’t need categories object at all, just populate the slices name into any array variable and use that while pushing data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display the data from xml to html via jquery I have
I'm trying to get data from HTML table but when I'm connecting to the
I'm having a problem displaying data from a function to text box within a
I'm retrieving data from a MySQL table and displaying it on a webpage using
I'm working on this JSF table which is used for displaying data. When I
I want to display data in my own format from Mysql database connecting through
I have been writing a html interface for displaying tables, pie charts, data etc.
I've the data(retrieved from database) in a list but when I use `f:view><html> <body>
This is the code for displaying data from database to gridview....If i am doing
I have a WCF web-service and a Silverlight app displaying data from that service.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.