Hi,

I need to create a simple line chart, 2 axis, x-axis with dates and y-axis with values.
The Charts module offers views integration out of the box with Drupal 7 so I attemtped to create a chart using the Views UI, but unfortunately the module seems very "buggy" with no way to explicitly state what goes on which axis - as default it piles everything on the x-axis (date, value, date, value, date....)

So with no luck there, I'm attempting just to create the chart by creating a node and writing the php straight in to a textbox (with php filter enabled). All the documentation at https://developers.google.com/chart/ is written in javascript, and I am struggling to find any good learning resources to create charts in php.

Is writing the code straight in as a piece of content the best way to create a chart? Would it better to hook in to the views chart and alter that? (No useful documentation on how to do this) I've noticed if i make any mistakes I break the whole site and have to delete content and create it all over again...
Also, where can I learn how to use Google Charts API?? I've a bit of experience in php but am by no means an expert - is this functionality only really available for Drupal experts??

Hope someone can take the time to help me :)

Thanks,
Paul

Comments

supertrader6’s picture

Some possible answers

Single field display in node

The Drupal theme formatter API can be used in a custom module to display that field as a chart.

If you want to display a single series of points on a line chart, you can store them in a single field containing multiple values. If you then want another set of values as dates, you may be able to simply match them to stored values e.g. if they were always seven days of week and you were happy to display them as values Monday - Sunday etc. the values could be "hardcoded."

Series of fields displayed in node

For a series of fields look at the example on "http://drupal.org/project/chart">project page. The points (values) on the line can be collected from
the node fields. Dates (i.e. labels) can be added too. A (Drupal 6) example is at "http://drupal.org/node/1386846">How do I get a pie chart out of a view result????

Views

You could try using the Views module to collect the field values for a single node and display them in a block. As you can see the Google Chart API module provides Views integration, but you say you have found this "buggy."

Google Chart API and Javascript/Drupal/PHP/HTML

Drupal 7 API has clear explanation of what each function does. This should help a lot.

Google Chart API uses the Drupal theme function to output stored values as a chart (HTML). API documentation explains how to theme values as a table (HTML). So if you wanted you could start by displaying your data as a table, and then when you were happy with this, use the same values in a chart/graph.

Take another look at the example on the Google Chart API project page. The first argument provided to the function is the name of the theme hook. If you decided that you wanted to use a different Drupal chart/graph solution (and there a quite a number of charting modules available), then you could still use the theme function but you could provide it with a different hook_theme implementation.

Effectively, you have access to a wide range of Javascript chart/graph libraries. for which you can access the online documentation. Or look at something like pChart module if you like PHP: it comes with examples. So there shouldn't be any need to worry about getting stuck on lack of documentation, and you can end up with nice looking charts/graphs.

Pierre.Vriens’s picture

Title: Creating Charts » How to use Chart?
Component: Code » Documentation
Priority: Major » Normal
Issue summary: View changes
Parent issue: » #2369883: Create chart documentation

I know we're 3 years later now, but this issue contains a lot of valid questions. Moreover, the comment from @supertrader6 is much appreciated! Expect it to become part of the documentation, and hopefully soon. Also note the parent issue link I added here ...