Library pages

For definitive info about amCharts library please see it's home page and it's reference page.

Instalation

You need to download amCharts files. Specifically Column & Bar, Line & Area, Pie & Donut zip files.

Unfortunately amCharts ships as several zips, so you need to download each one from the above path:

and within each of these zips you will find the following files:

Download and place them in the downloaded folder of the Drupal Charts and Graphs module, directly, without any folder structure inside the downloaded folder (e.g. into sites/all/modules/charts_graphs/apis/charts_graphs_amcharts/downloaded).

Dependency

SMFTools module

amCharts implementation for Charts and Graphs dependends on the SWFTools module.

At this point, you should be able to start using AmCharts, but it is highly recommended that you complete following three steps as well:

  1. download: http://code.google.com/p/swfobject zip file, extract it and copy the swfobject.js file to sites/all/modules/swftools/shared/swfobject2/swfobject.js
  2. enable SWFObject2 module
  3. go to SWFTools embeding configuration located at: http://yourdomain.com/admin/settings/swftools/embed and under Embedding Methods make SWFObject 2 - JavaScript the default method
DOM extension

amCharts for Charts and Graphs also depends on PHP's DOM extension. It is a standard PHP extension. If you have any problem, please see DOM Setup.

Usage

The quickest code to get something graphed using AmCharts:

<?php
function charts_graphs_test() {
  $canvas = charts_graphs_get_graph('amcharts');

  $canvas->title = 'AmCharts Chart';
  $canvas->type = 'line';
  $canvas->y_legend = 'Y Legend';
  $canvas->colour = '#808000';
  $canvas->theme = 'keynote';
  $canvas->series = array(
    'Some Value' => array(9,6,7,9,5,7,6,9,7),
    'Page Views' => array(6,7,9,5,7,6,9,7,3),
  );
  $canvas->x_labels = array('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine');

  $out = $canvas->get_chart();

  return $out;
}

License key

License key owners can refer to the following code to use their keys:

<?php
  $canvas->key = 'YOUR_KEY';

Arbitrary parameters

amCharts implementation for Charts and Graphs supports the settings, chart_series, chart_graphs and pie general parameters. With then the user can set any parameter in amCharts as everything set in it will be passed to amCharts through appropriate XML files and will override any default setting or setting through the standard settings supported by Charts and Graphs.

For details on how to set any of these optional parameters, please see Arbitrary XML Settings.

The settings array deals with the contents of the settings file.

The other three arrays deals with the contents of the data file.

This way the user has complete control on what is being included on the charting call.

With great power comes great responsability.

As the ultimate control feature the parameters option intends to be, the values are passed absolutely unchanged as defined by the user. There is no urlencoding, quotes inclusion or any other safety net. The values should be set in a safe and complete manner.

Example

Setting bar width and spacing:

<php
$canvas->parameters['chbh'] = "25,5,10";

Graph types supported

amCharts supports all main and standardized graph types. It also supports the following graph types:

100_stacked_bar
Stacked bar where columns equalized at the same height and values take up a percentage of each column.
bar_3d
Columns are 3D and are positioned one behind another.
100_stacked_side_bar
Stacked side bar where columns equalized at the same width and values take up a percentage of each column.
side_bar_3d
3D side bars positioned one behind another.
pie_3d
3D pie.
donut_3d
3D donut.

Unsupported properties

The amCharts charting library doesn't support the y_step property.

Examples

The examples below will only work if you have the amCharts submodule configured correctly.