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

  • Home
  • SEARCH
  • 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 9276201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:47:07+00:00 2026-06-18T16:47:07+00:00

I have a page that uses highcharts pie chart, and I am trying to

  • 0

I have a page that uses highcharts pie chart, and I am trying to update the chart with a date selector drop down. I have a similar implementation for a bar chart and its working great. Please note (this is coming from a PHP class, hence the concatenation and what not).

<script type='text/javascript'>

                    function drawPie(data)
                    {
                        var chart;
                        alert('called');
                        var options = {
                            chart: {
                                renderTo: 'PieChart',
                                plotBackgroundColor: null,
                                plotBorderWidth: null,
                                plotShadow: false,
                                height: 350
                            },
                            title: {
                                text: 'Product Popularity'
                            },
                            tooltip: {
                                pointFormat: '{series.name}: <b>{point.percentage}%</b>',
                                percentageDecimals: 1
                            },
                            plotOptions: {
                                pie: {
                                    allowPointSelect: true,
                                    cursor: 'pointer',
                                    dataLabels: {enabled: false},
                                    showInLegend: true
                                }
                            },
                            series: [{
                                type: 'pie',
                                name: 'Product Popularity',
                                data: data

                            }]
                        }
                        chart = new Highcharts.Chart(options);
                        $('#ProductPieMod div.mod_content').css('height', $('#PieChart').css('height'));
                    }
                $(document).ready(function(){
                    drawPie(" . $this->get_data($this->date) . ");

                    $('#ProductPieMod_date').on('change', function(){
                        var val = parseInt($(this).val());
                        switch(val)
                        {
                            case 0:
                                var date = Date.today();
                                break;
                            case 1:
                                var date = Date.parse('last week');
                                break;
                            case 2:
                                var date = Date.today().moveToFirstDayOfMonth();
                                break;
                            case 3:
                                var date = Date.parse('January').moveToFirstDayOfMonth();
                                break;
                            default:
                                var date = Date.today();
                        }
                        var info;
                        $.ajax({
                            type: 'POST',
                            url: '". matry::base_to('utilities/dhs/manager_dash') . "',
                            async: false,
                            dataType: 'json',
                            data: {date: date.toString('M/dd/yyyy'), module: 'ProductPieMod'},
                            success: function(data)
                            {
                                drawPie(data);  
                            }
                        });

                    });
                });
                </script>

My ajax returns the following string:

[['FASTCLIX LANCING DEVICE', 62.5],['FREESTYLE LANCING DEVICE', 25],['ONETOUCH DELICA LANCING DEVICE', 12.5]]

In addition, this chart is initially built, using the exact same method, just fine. Its just when I use the dropdown (run the onChange event) that it breaks.

Update
I have created a fiddle for this as well: http://jsfiddle.net/SHReZ/1/

  • 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-18T16:47:09+00:00Added an answer on June 18, 2026 at 4:47 pm

    Firts, you need to place chart var to document.ready handler scope, next, you need to destroy chart before draw.

    $(document).ready(function () {
        var chart;
    
        function drawPie(data) {
            console.log('called');
            var options = {
                chart: {
                    renderTo: 'PieChart',
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false,
                    height: 350
                },
                title: {
                    text: 'Product Popularity'
                },
                tooltip: {
                    pointFormat: '{series.name}: <b>{point.percentage}%</b>',
                    percentageDecimals: 1
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: false
                        },
                        showInLegend: true
                    }
                },
                series: [{
                    type: 'pie',
                    name: 'Product Popularity',
                    data: data
                }]
            };
            if (chart !== undefined) chart.destroy();
            chart = new Highcharts.Chart(options);
            $('#ProductPieMod div.mod_content').css('height', $('#PieChart').css('height'));
        }
    
    
        drawPie([
            ['ONETOUCH DELICA LANCING DEVICE', 27.78],
            ['FREESTYLE LANCING DEVICE', 20.83],
            ['Nova Max Ketone Test Strips Health and', 11.11],
            ['ONETOUCH ULTRASOFT LANCING DEVICE 2PK', 11.11]
        ]);
        //get data from https://gist.github.com/zba/4712055 , delay 4
        $.post('/gh/gist/response.html/4712055', {
            delay: 4
        }, function (data) {
            drawPie(data);
        }, 'json');
    
    });
    

    fiddle

    also here is demo which not destroy chart, but it change colors to much

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

Sidebar

Related Questions

I have a page that uses some variables for the date. y for year
I have a web page that uses a date range filter, the selected date
I have a page that uses the Telerik RadListView control and a Telerik RadDataPager
I have a page that uses another page via the include() function. The page
I have a page that uses jQuery with a small glitch. I managed to
I have a page that uses a background image to do rounded corners, and
I'd like to have a page that uses a child master page, fill in
I have a sample page that uses 2 PHP files and a MySql database,
I have a web page that uses cross page posting to post to a
I have an HTML page that uses AJAX to retrieve messages from a server.

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.