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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:14:05+00:00 2026-06-02T17:14:05+00:00

Take a looka t my JS below, for my drawChart function for a google

  • 0

Take a looka t my JS below, for my drawChart function for a google chart. This works as I expected. HOWEVER, because var chart ... is inside the drawChart function, the animations do not work – instead google thinks it’s creating a brand new chart each time, and just refreshes the chart.

I would like to do something like in their examples, where the data moves according to my settings (1000ms, default easing: linear). Examples are here: https://developers.google.com/chart/interactive/docs/animation

If I pull out the var chart ... from the drawChart function, I get a “Chart not defined” error. Appreciate the help from anyone who has worked with google charts a lot. Thanks for the help.

var chart = "notSet";
google.load('visualization', '1.0', {'packages':['corechart']});
google.setOnLoadCallback(setGoogleData);
google.setOnLoadCallback(drawChart);
newValue = 0;
var data = [];
function setGoogleData(){
  data[0] = new google.visualization.DataTable(JSON_DATA_LOCATED_HERE);
  data[1] = new google.visualization.DataTable(JSON_DATA_LOCATED_HERE);
  var chart = new google.visualization.LineChart(document.getElementById('stopByTripChart'));
}
function drawChart() {
  if(chart == "notSet"){
    var chart = new google.visualization.LineChart(document.getElementById('stopByTripChart'));
  }
  var options = {"title":"Average Load Summary","titlePosition":"in","width":1100,"height":700,"hAxis.slantedTextAngle":90,"hAxis.position":"out","pointSize":5,"animation.duration":1000,"animation.easing":"linear","hAxis.showTextEvery":1,"hAxis.title":"Stops"};
  chart.draw(data[newValue], options);
}
function changeChart(){
  newValue = document.getElementById("chartNumber").value;
  drawChart();
}
  • 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-02T17:14:06+00:00Added an answer on June 2, 2026 at 5:14 pm

    I’ve never tried Google charts myself, but I think such a code would work:

    var chart = null;
    function drawChart() {
      if(chart === null){
         chart = new google.visualization.LineChart(document.getElementById('stopByTripChart'));
      }
      var options = {"title":"Average Load Summary",
                     "titlePosition":"in",
                     "width":1100,
                     "height":700,
                     "hAxis" :{"slantedTextAngle":90,
                               "position":"out",
                               "showTextEvery":1,
                               "title":"Stops"},
                     "pointSize":5,
                     "animation":{"duration":1000,
                                  "easing": 'out'};
      chart.draw(data[newValue], options);
    }
    function changeChart(){
      newValue = document.getElementById("chartNumber").value;
      drawChart();
    }
    

    Otherwise, the error about chart not being defined might come from the fact that you might have placed your code before the load of the google library. Hence, chart was called before the google objects existed (tho it’s hard to tell with just that snippet).

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

Sidebar

Related Questions

Take a look at this snippet below: <script> $(function(){ var to_username = alex; window.Persona
Take a look at the image below. I defined the red boxes inside the
Take a look at this html: <head> <title>Test page</title> <script type=text/javascript> function submitForm() {
take a look at this code: $(document).ready(function() { document.getElementById(sliderId).onmousedown = sliderMouseDown; }); function sliderMouseDown()
Please take a look at this below line of code in JSF <h:inputText id=name
So take a look at the below rough code: function Manager() { try {
This must be an oft-answered question, but my google-foo fails me. Take a look
Possible Duplicate: Javascript Variable Variables Please take a look at code below var selected_id=1;
Take a look at the snippet below. Is there any function I could write
Take a look at this jsFiddle Code also listed below: window.MyView = Backbone.View.extend({ ticks:

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.