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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:07:20+00:00 2026-06-13T10:07:20+00:00

I’m using gviz_api (google-visualization-python) to build some line charts. http://code.google.com/p/google-visualization-python/ I’e edited a line

  • 0

I’m using gviz_api (google-visualization-python) to build some line charts.
http://code.google.com/p/google-visualization-python/

I’e edited a line chart example taken from the google documentation.
However, I’m not sure how I would pass a date into the DataTable

Here’s the edited example I’ve been working with.
https://gist.github.com/3941946

Here’s the code I had a question about

 # Creating the data
 description = {"year": ("string", "Year"),
             "sales": ("number", "Sales"),
             "expenses": ("number", "Expenses")}

 data = [{"year": '2004', "sales": 1000, "expenses": 300}, 
      {"year": '2005', "sales": 1200, "expenses": 400}, 
      {"year": '2006', "sales": 1300, "expenses": 500}, 
      {"year": '2007', "sales": 1400, "expenses": 600}, 
      {"year": '2008', "sales": 1500, "expenses": 800}]
  # Loading it into gviz_api.DataTable
  data_table = gviz_api.DataTable(description)
  data_table.LoadData(data)

How would I load a date into the DataTable using gviz_api?

The google documentation describes how to creat a new Date() using javascript, however, I’d like to keep using gviz_api.py.

Notes from the google documentation
from https://developers.google.com/chart/interactive/docs/dev/implementing_data_source#jsondatatable

*JSON Modifications
Google’s helper libraries, and all queries sent to Google, return a slightly non-standard version of JSON/JSONP. If you are not parsing the returned code yourself, this should not matter to you. The Visualization API client supports both standard and the modified versions of JSON. Here is a summary of the differences:

JSON does not support JavaScript Date values (for example, “new Date(2008,1,28,0,31,26)”; the API implementation does. However, the API does now support a custom valid JSON representation of dates as a string in the following format: Date(year, month, day[,hour, minute, second[, millisecond]]) where everything after day is optional, and months are zero-based.

JSON uses double-quotes for dictionary keys; the API implementation uses unquoted keys.

JSON requires double-quotes around string values; the API implementation uses single quotes.*

  • 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-13T10:07:23+00:00Added an answer on June 13, 2026 at 10:07 am

    You can actually handle creating dates just like you would in standard Python – the API handles the conversion to JS for you. All you have to do is import datetime at the beginning of your script, change the column type for year from string to date and then create the dates as you would in standard Python:

    # This is the first modification - importing the library
    import datetime
    import gviz_api
    
    # page_template stays the same
    # ...
    
    def main():
      # Creating the data
      # Here we change the type of column "year" to "date"
      description = {"year": ("date", "Year"),
                     "sales": ("number", "Sales"),
                     "expenses": ("number", "Expenses")}
    
      # Here we switch out the string dates with an actual Python datetime.date
      # The conversion happens in the the subsequent functions, giving you a 
      # date that is usable in the JS
      data = [{"year": datetime.date(2007,3,7), "sales": 1000, "expenses": 300},
              {"year": datetime.date(2009,6,11), "sales": 1200, "expenses": 400},
              {"year": datetime.date(2009,3,1), "sales": 1300, "expenses": 500},
              {"year": datetime.date(2010,8,6), "sales": 1401, "expenses": 600},
              {"year": datetime.date(2011,7,13), "sales": 1500, "expenses": 800}]
      # Loading it into gviz_api.DataTable
      data_table = gviz_api.DataTable(description)
      data_table.LoadData(data)
    
      # Creating a JavaScript code string
      jscode = data_table.ToJSCode("jscode_data",
                                   columns_order=("year", "sales", "expenses"),
                                   order_by="year")
      # Creating a JSon string
      json = data_table.ToJSon(columns_order=("year", "sales", "expenses"),
                               order_by="year")
    
      # Putting the JS code and JSon string into the template
      print "Content-type: text/html"
      print
      print page_template % vars()
    
    
    if __name__ == '__main__':
      main()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.