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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:13:40+00:00 2026-06-17T15:13:40+00:00

I am trying to draw a line graph using google charts and a JSON

  • 0

I am trying to draw a line graph using google charts and a JSON that I have created from MYSQL. I have tried to use the examples provided on Google Visualization API but haven’t been successful.

google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);


function drawChart() {
    var selectedValue = $("select option:selected").val()
    var jsonData = $.ajax({
        type: 'get',
        url: '/social_scores/'+selectedValue,
        dataType:"json",
        success: function(response, status, jqXHR) {
             /* Create the charts after operation succeeded */
             var data = new google.visualization.DataTable(response);
             data.addColumn('string', 'Week');
             data.addColumn('number', 'Overall');
             data.addColumn('number', 'Presence');
             data.addColumn('number', 'Popularity');
             data.addColumn('number', 'Engagement');
             data.addColumn('number', 'Reputation');
             data.addRows([
                 ['Week 1', response.overall_score, response.presence_score, response.popularity_score, response.engagement_score, response.reputation_score ],
                 ['Week 2', response.overall_score, response.presence_score, response.popularity_score, response.engagement_score, response.reputation_score ]
             ]);
            var options = {
                title:'Key Success Metrics over time across all channels',
                'backgroundColor': 'transparent',
                'width': 620,
                'vAxis': {minValue:"0", maxValue:"100", gridlines:{count: 7} },
                'chartArea': {top:"50", left: "40"},
                'legend':{position: 'top', alignment: 'start' }
           };
           var chart = new google.visualization.LineChart(document.getElementById('line_graph'));
           chart.draw(data, options);
          ("select").change(function(){
            alert($("select option:selected").val())

           });


        }
    });
};

Here is the graph span that should be update:

<span id="line_graph"></span>

Here is the drop down html:

<select id="social_entity_id" name="social_entity[id]">
<option value="1">DataSimply</option>
<option value="2">mbonat</option>
<option value="3">OpenLabel</option>
<option value="4">scrible</option>
<option value="5">jivesoftware</option>
<option value="6">lithiumTech</option>
<option value="7">getsatisfaction</option>
<option value="8">tumblr</option>
<option value="9">nytimes</option>
<option value="10">gilt</option>
<option value="11">groupon</option>
<option value="12">Bloombergnow</option>
<option value="13">NWSCorp</option>
<option value="14">etsy</option>
<option value="15">foursquare</option>
<option value="16">Yelp</option>
<option value="17">businessinsider</option>
</select>

Where should I put the change event so that the numbers changed based on the selected value of the dropdown?

  • 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-17T15:13:41+00:00Added an answer on June 17, 2026 at 3:13 pm

    The AJAX operation works asynchronously, so you need to wait until the operation has completed before initializing your charts.

    $(function() {
        var chart;
    
        var drawChart = function {
            var selectedValue = $("select#social_entity_id option:selected").val();
            $.ajax({
                type: 'get',
                url: '/social_scores/'+selectedValue,
                dataType:"json",
                success: function(response, status, jqXHR) {
                     /* Create the charts after operation succeeded */
                     var data = new google.visualization.DataTable(response);
                     data.addColumn('string', 'Week');
                     data.addColumn('number', 'Overall');
                     data.addColumn('number', 'Presence');
                     data.addColumn('number', 'Popularity');
                     data.addColumn('number', 'Engagement');
                     data.addColumn('number', 'Reputation');
                     data.addRows([
                         ['1', response.overall_score, 1, 1, 1, 1 ],
                         ['1', 1, 1, 1, 1, 1 ]);
    
                    var options = {
                        title:'Key Success Metrics over time across all channels',
                        'backgroundColor': 'transparent',
                        'width': 620,
                        'vAxis': {minValue:"0", maxValue:"100", gridlines:{count: 7} },
                        'chartArea': {top:"50", left: "40"},
                        'legend':{position: 'top', alignment: 'start' }
                   };
                   chart = new google.visualization.LineChart(document.getElementById('line_graph'));
                   chart.draw(data, options);
                }
            });
         }
    
         google.load("visualization", "1", {'callback': drawChart, packages:["corechart"]});
    
         $('#social_entity_id').change(drawChart);
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to draw a simple line graph which would use values from the
Using core graphics , I am trying to draw a line, in that when
Hi I am trying to draw one line graph and for that I am
I am trying to draw a line using on touch method. I want that
I have some data that I am trying to display using the Google Visualization
So I am trying to map Tide times on a line graph using Google's
I'm trying to draw a line using ctx.lineTo in loop. I have small function
I'm trying to draw a single line using OnMouseMove() event. My Problem is that
I am trying to draw some basic graphics primitives(line, rectangle etc.) using GDI+ apis
I am trying to write some code that that will draw the line which

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.