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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:14:17+00:00 2026-06-16T21:14:17+00:00

When I attempt to load a Google Chart in node.js, nothing happens. I tried

  • 0

When I attempt to load a Google Chart in node.js, nothing happens.

I tried loading the first example from the line chart docs in both zombie.js and jsdom, but the chart never loads in either case.

The end goal is to retrieve the SVG data of the generated chart for export into an image or PDF. So if an alternate method (server side using node.js or PHP) to achieve this is possible, I’m open to suggestions.

NOTE: I have successfully generated a images of a few charts using gChartPhp, but the requirements of this project state that the embedded version be the interactive version provided by the current API and the exported version be visually IDENTICAL to the embedded one (without being interactive, obviously).

Edit: I tagged PhantomJS, since that is the solution with which I ultimately went.

Sorry for the lack of links, but the spam prevention mechanism will only allow me to post 2.

  • 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-16T21:14:18+00:00Added an answer on June 16, 2026 at 9:14 pm

    It wasn’t the ideal solution, but I found an alternative to node.js for accomplishing the same end goal in PhantomJS. Simply create an HTML file containing the chart (test.html) and like node.js, create a JS file containing your code (test.js). Then run your JS file with PhantomJS.

    In your JS file, open your HTML file as a webpage, then render it, either saving the image buffer to a file:

    var page = require('webpage').create();
    page.open('test.html', function () {
        page.render('test.png');
        phantom.exit();
    });
    

    Then run it:

    phantomjs test.js
    

    To dynamically create a chart, create the following JS file (test2.js):

    var system = require('system');
    var page = require('webpage').create();
    page.onCallback = function(data)
    {
        page.clipRect = data.clipRect;
        page.render('test.png');
        phantom.exit();
    };
    page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js', function()
    {
        page.includeJs('https://www.google.com/jsapi', function()
        {
            page.evaluate(function(chartType, data_json, options_json)
            {
                var div = $('<div />').attr('id', 'chart').width(900).height(500).appendTo($('body'));
                google.load("visualization", "1",
                {
                    packages:[chartType == 'GeoChart' ? 'geochart' : 'corechart'],
                    callback: function()
                    {
                        data_arr = $.parseJSON(data_json);
                        data = google.visualization.arrayToDataTable(data_arr);
                        options = $.parseJSON(options_json);
                        chart = new google.visualization[chartType]($(div).get(0));
                        google.visualization.events.addListener(chart, 'ready', function()
                        {
                            window.callPhantom(
                            {
                                clipRect: $(div).get(0).getBoundingClientRect()
                            });
                        });
                        chart.draw(data, options);
                    }
                });
            }, system.args[1], system.args[2], system.args[3]);
        });
    });
    

    Then run it:

    phantomjs test2.js LineChart '[["Date","Steve","David","Other"],["Dec 31",8,5,3],["Jan 1",7,10,4],["Jan 2",9,4,3],["Jan 3",7,5,3]]' '{"hAxis.slantedText":true}'
    
    phantomjs test2.js PieChart '[["Employee","Calls"],["Steve",31],["David",24],["Other",13]]' '{"is3D":true}'
    
    phantomjs test2.js GeoChart '[["State","Calls"],["US-CA",7],["US-TX",5],["US-FL",4],["US-NY",8]]' '{"region":"US","resolution":"provinces"}'
    

    To get the image data from an external script, make a copy of test2.js (test3.js) and change

    page.render('test.png');
    

    to

    console.log(page.renderBase64('png'));
    

    Then call it (from PHP, for example):

    <?php
    
        $data = array(
            array("Employee", "Calls"),
            array("Steve", 31),
            array("David", 24),
            array("Other", 13)
        );
        $options = array(
            "is3D" => true
        );
        $command = "phantomjs test3.js PieChart '" . json_encode($data) . "' '" . json_encode($options) . "'";
        unset($output);
        $result = exec($command, $output);
        $base64_image = implode("\n", $output);
        $image = base64_decode($base64_image);
    
    ?>
    

    NOTE: Looking back on this whole process, the problem I was having with node.js was possibly that I didn’t setup callbacks or timeouts to wait until the charts were “ready”.

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

Sidebar

Related Questions

In an attempt to load google maps asynchronously I took a look at google's
I'm trying to load images from google maps static images api into flash. When
In my attempt to load information from the analytics engine, I have been unable
I am trying to attempt my first Google Chrome Extension and have a question.
I have an image that I get and attempt to load into a graphics
First attempt to use this cool site - after searching for 2 hours: So
I attempt to use webservice return POCO class generated from entity data model as
This is my first attempt at responsive design, so I'm keeping it simple. I
When I attempt to connect to an intranet web service from a web application
I'm trying to screenscrape the first result of a Google search using Python and

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.