RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Google Chart (Depreciated) WordPress Shortcode

Google charts are awesome. I used them on about a dozen sites to visually represent all kinds of data before switching to our own charting library. If you don't know what Google Charts are, it's worth checking out the massive resources available on the Google Chart Tools website.

This code references the depreciated tool... so support isn't provided and there's no guarantee of continued availability. This article was ported over from Internoetics, and we've done so to preserve the content (which is still working). Another article is forthcoming that deals with the most up-to-date tools which are far superior to the very basic image-based service.

The shortcode below will get you started with implementing Google Charts on your WordPress website with shortcode. The functions below will permit you to construct only the most basic charts.

The Result

Pie Chart (pie)

In the first example we'll render the population of Australia by State.

[chart data="7238819,5547527,4516361,1644642,507626,229675,127532,2296411,358894" bg="F7F9FA" labels="NSW|Victoria|Queensland|South Australia|Tasmania|Northern+Territory|Darwin|Western Australia|ACT" colors="058DC7,81feb6,ff8080,1601d1,50B432,ff0f0f,800040,ED561B,EDEF00" size="445x200" title="Australian Population" type="pie"]

Australian Population

Sparkline (sparkline)

Sparkline graphs are great for rendering stock data or the value of currency. They're also useful in illustrating trends in traffic. It will draw a line chart where data points are spaced evenly along the x-axis.

[chart data="0,22,24,26,28,100,90,80,70,65,20,80,30,50,20,30" bg="F7F9FA" size="445x100" type="sparkline"]

Google-O-Meter Charts (gom)

A Google-o-meter is a gauge that points toward a single value on a range. The range has a color gradation that you can optionally specify. You can also specify custom text above the pointer. The dial range is from the data format minimum value to the maximum value.

[chart_depreciated data="30" bg="F7F9FA" labels="low" colors="00ff40,009d27,ffc22f,d89b07,ffa346,d89b07,ff6666,ff0f0f" size="445x200" title="Fire Danger" type="gom"]

Fire Danger

The above examples are very basic. You should play around with the chart types with reference to the Google Charts page to get a feel for how they're rendered (and what fields are required).

WordPress Shortcode

Copy and paste the WordPress function into your theme's functions.php file or, if you sensibly have one installed, your custom functions plugin.

1
<?php 
2
/*
3
 Google Chart (Depreciated) WordPress Shortcode
4
 http://www.beliefmedia.com/code/wp-snippets/google-charts-depreciated
5
*/
6
 
7
8
 
9
  extract(shortcode_atts(array(
10
   'data' => '',
11
   'colors' => '',
12
   'size' => '400x200',
13
   'bg' => 'ffffff',
14
   'title' => '',
15
   'labels' => '',
16
   'advanced' => '',
17
   'type' => 'pie'
18
  ), $atts));
19
 
20
  switch ($type) {
21
   case 'line' :
22
 $charttype = 'lc'; break;
23
   case 'xyline' :
24
 $charttype = 'lxy'; break;
25
   case 'sparkline' :
26
 $charttype = 'ls'; break;
27
   case 'meter' :
28
 $charttype = 'gom'; break;
29
   case 'scatter' :
30
 $charttype = 's'; break;
31
   case 'venn' :
32
 $charttype = 'v'; break;
33
   case 'pie' :
34
 $charttype = 'p3'; break;
35
   case 'pie2d' :
36
 $charttype = 'p'; break;
37
   default :
38
 $charttype = $type;
39
   break;
40
   }
41
 
42
  if ($title) $string .= '&chtt=' . $title;
43
  if ($labels) $string .= '&chl=' . $labels;
44
  if ($colors) $string .= '&chco=' . $colors;
45
  $string .= '&chs=' . $size;
46
  $string .= '&chd=t:' . $data;
47
  $string .= '&chf=' . $bg;
48
 
49
 return '
50
<p style="text-align:center;"><img title="' . $title . '" src="http://chart.apis.google.com/chart?cht=' . $charttype . $string . $advanced . '" alt="' . $title . '" />';
51
}
52
add_shortcode('chart_depreciated', 'beliefmedia_chart_shortcode_depreciated');

If you require shortcode to work in a sidebar widget, you'll have to enable the functionality with a filter. If you're using our custom functions plugin, you'll have that feature enabled by default.

Again, the code and API is old. Use with caution.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment