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 1092399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:40:35+00:00 2026-05-16T23:40:35+00:00

I have the script below which works well, i.e. it generates a chart on

  • 0

I have the script below which works well, i.e. it generates a chart on the screen when the page loads:

<script type="text/javascript">
    google.load("visualization", "1", {packages:["corechart"]});
    google.setOnLoadCallback(drawChartAjax);

    function drawChartAjax() {
        $.ajax({ 
            url: 'json_data.aspx', 
            type: 'POST', 
            dataType: 'json', 
            success: function(data) { 
                drawChart(data); 
            } 
        });
    }

    function drawChart(json) {
        var data = new google.visualization.DataTable();
        data.addColumn('string', 'did');
        data.addColumn('number', '09/10'); 

        data.addRows(json.length);  

        var l = json.length, i, x = 0, y = 0; 
        for(i = 0; i < l; i++) { 
            data.setValue(y, x, json[i].did); x++; 
            data.setValue(y, x, json[i].v1); x=0; 
            y++; 
        } 

        var chart = new google.visualization.BarChart( document.getElementById('chart_div') );
        chart.draw(data, {width: 300, height: 400, legend: 'bottom', title: 'title goes here'});
    }
</script>

What do I have to do to get this to load when a link is clicked?

I know I can display an alert like this:

$(document).ready(function(){
    $("a.display_chart").click(function(event){
        alert("display the chart");
        event.preventDefault();
    });
});
  • 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-05-16T23:40:36+00:00Added an answer on May 16, 2026 at 11:40 pm

    latest answer.

    after searching what .setOnLoadCallback() does,

    It turned out you just have to call the function on click

    $(document).ready(function(){
        $("a.display_chart").click(function(event){
            drawChartAjax();
            event.preventDefault();
        });
    });
    

    previous answer.

    move google.setOnLoadCallback(drawChartAjax); inside your click event.

    like this,

    $(document).ready(function(){
        $("a.display_chart").click(function(event){
            google.setOnLoadCallback(drawChartAjax); // this line should not appear anymore there at the top
            event.preventDefault();
        });
    });
    

    <script type="text/javascript">
        google.load("visualization", "1", {packages:["corechart"]});
        //google.setOnLoadCallback(drawChartAjax);
    
        function drawChartAjax() {
            $.ajax({ 
                url: 'json_data.aspx', 
                type: 'POST', 
                dataType: 'json', 
                success: function(data) { 
                    drawChart(data); 
                } 
            });
        }
    
        function drawChart(json) {
            var data = new google.visualization.DataTable();
            data.addColumn('string', 'did');
            data.addColumn('number', '09/10'); 
    
            data.addRows(json.length);  
    
            var l = json.length, i, x = 0, y = 0; 
            for(i = 0; i < l; i++) { 
                data.setValue(y, x, json[i].did); x++; 
                data.setValue(y, x, json[i].v1); x=0; 
                y++; 
            } 
    
            var chart = new google.visualization.BarChart( document.getElementById('chart_div') );
            chart.draw(data, {width: 300, height: 400, legend: 'bottom', title: 'title goes here'});
        }
    
        $(document).ready(function(){
            $("a.display_chart").click(function(event){
                google.setOnLoadCallback(drawChartAjax); // this line should not appear anymore there at the top
                event.preventDefault();
            });
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tested the below script on a demo page which is not using
I have a script in the link below which works in IE8 nicely. However,
I have a user who randomly gets a Script Error box (shown below) which
I have a Perl script which nests foreach loops as seen below. It takes
I have a python script which outputs lots of data, sample is as below.
I have a small script which im using to test PHP mail(), as below:
I have a PHP script which works fine in PHP 5, but not in
Updated below: I have a script which has a function I made that calculates
I have the script below placed in the HEAD of the page. The map
I have a piece of code below which works fine when it comes to

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.