Overview

Pie charts should be used to show the relationship of individual parts to the whole for a single series of data.

The line charts that you can create with this plugin are highly customizable, can be animated, updated dynamically, and feature area fills, data points, and tooltips. Find out more below.

Return to top

Usage

To create an line chart, assign a class of lineChart to a div element. Data and options are assigned via the data-chartData and data-chartOptions attributes, respectively.

The data-chartData attribute takes an array of JSON objects as its value, with each object containing x and y keys with array values containing numerical data points. Charts with dates along the x-axis will ignore the x key-value pair, so for those charts, its possible to omit the x-axis information.

Chart options passed through the data-chartOptions attribute must be contained in a single-level JSON object, with each option key corresponding to a value. It's not necessary to use the data-chartOptions attribute if you only want to have the default chart. All of the options relevant to line charts are detailed below.

Return to top

Options

Chart Options
Chart Options
Option Description Default Value Values
animate Animates the chart. false true, false
animationDuration The duration of the chart animation in seconds. 1 Any positive number
aspectRatio The aspect ratio of the entire chart area, including labels and keys. [16, 9] An array of 2 positive integers [x, y]
colors The hex colors for each series of chart data. ['#058DC7', '#A006C7', '#C7062D', '#06C740', '#C7A006', '#EEE', '#CCC', '#999', '#666', '#333', '#000'] An array of hex codes [color1, color2, ...]
dataLabels Labels for each series of data, will also show in the key. If no labels are provided, labels will be 'Series 1', 'Series 2', etc. [] An array of strings equal to the number of series ['Label 1', 'Label 2', ...]
keyPosition The position of the key. The showKey option must also be enabled. 'bottom' 'top', 'bottom', 'left', 'right'
keyWidthPercentage The width percentage of the key in relation to the entire chart area, applicable only for left and right key positions. 12 Any positive integer
showKey Toggles the chart key. false true, false
showTips Toggles tooltips for all charts. Line charts and area charts must have showPoints enabled for tips to show. false true, false
showTitle Toggles the chart title. false true, false
textColor The color of all text in the chart. "#000" Any hex color string
title The title of the chart. "Untitled Chart" Any string
tipText An array of HTML text strings to customize the tip text, one string for each series. Placeholders in the string (surrounded by curly braces {}) can be replaced by values or labels from the chart. Placeholders options include: {x}, {y}, {xAxis}, {yAxis}, {piePercent} and {label}. [] An array of HTML strings with placeholders, one string for each series

Return to top

Events

Each chart type has an updateChart event, which allows the chart to be updated dynamically. The event is bound to the chart container element and can be fired using MooTools' fireEvent method.

New data can be passed directly to the chart via fireEvent. If no new data is passed through fireEvent, then the plugin will pull the data and options from the data attributes.

Note When the updateChart event is fired, the plugin will rerender the chart completely.

Return to top

Demos

Inline

Inline bar charts are small charts that can appear inline within the context of a block of text or other inline elements. Note Because inline charts are so small, they should generally only be used with a single data set and without many of the visual chart features enabled. Keep inline charts simple.

Demo

This is an inline bar chart: It can appear within a paragraph.

Show Code

<p>This is an inline pie chart: <span class="inlinePieChart" data-chartData="[
{x:[40,10]}
]"></span> It can appear within a paragraph.</p>

Return to top

Default

This is the default pie chart, with no options enabled. It expands to the full height of its container and shows data only. The y-axis data is not necessary.

Demo

Show Code

<div class="pieChart" data-chartData="[
{x:[130,33,75]}
]"></div>

Return to top

Aspect Ratio

The default aspect ratio for any chart is 16:9, but because pie charts aren't rectangular, you may want to adjust the aspect ratio using the aspectRatio option so that the chart takes up more of the available space. The demo has been adjusted to a 4:3 ratio.

Demo

Show Code

<div class="pieChart" data-chartData="[
	{x:[130,33,45,75]}														
]" data-chartOptions="{
	aspectRatio: [4,3]
}"></div>

Return to top

Interactive Keys

Most pie charts won't be very useful without a key. To enable a key, use the showKey option. Key position and size can be controlled via the keyPosition and the keyWidthPercentage options.

Demo

Show Code

<div class="pieChart" data-chartData="[
	{x:[130,33,45,75]}														
]" data-chartOptions="{
	showKey: true, 
	keyPosition:'right', 
	keyWidthPercentage: 25
}"></div>

Return to top

Custom Labels

The default labels for a key are Series 1, Series 2, etc. To insert custom labels, use the dataLabels option, giving it an array of strings as a value, one string for each data segment.

Demo

Show Code

<div class="pieChart" data-chartData="[
{x:[130,33,45,75]}
]" data-chartOptions="{
	showKey: true, 
	keyPosition:'right', 
	keyWidthPercentage: 25,  
	dataLabels: ['Like Jar Jar', 'Kill Jar Jar'],
	showTitle: true,
	title: 'Reactions'	
}"></div>

Return to top

Chart Tips

Use the showTips option to enable tips. Custom tips can be entered using the tipText option, with a value of an array containing a single HTML string.

The following placeholders can be used for pie charts: {x} (the raw value of a segment), {piePercent} (the segment's percentage of the pie), and {label} (the name of the segment). The demo has the default tip text.

Demo

Show Code

<div class="pieChart" data-chartData="[
{x:[130,33,45,75]}
]" data-chartOptions="{
	showKey: true, 
	keyPosition:'right', 
	keyWidthPercentage: 25, 
	showTips: true
}"></div>

Return to top

Animation

The chart can be animated by setting the animate option to true. The length of the animation can also be controlled with the animationDuration option, which defaults to a 1 second animation.

Note Animations do not currently work in Internet Explorer as it does not support declarative animations. The chart will simply ignore the animate option and display a static chart in Internet Explorer.

Animation has also been disabled in Safari until further testing can be performed and a fix can be found. A static chart will also be displayed for Safari.

Demo

Refresh Animation

Show Code

<div id="animatedPieChart" class="pieChart" data-chartData="[
	{x:[50,33,45,48]}
]" data-chartOptions="{
	showKey: true, 
	keyPosition:'right', 
	keyWidthPercentage: 25, 
	showTips: true, 
	animate:true
}"></div>

<p><a id="animateButton" class="infoButton" href="#">Refresh Animation</a></p>

<script type="text/javascript">
	window.addEvent('domready', function(){
		$('animateButton').addEvent('click', function(e){
			e.stop();
			$('animatedPieChart').fireEvent('updateChart');
		});
	});
</script>

Return to top

VM UI Framework is created, owned, maintained by Virtuosi Media, Inc. © 2012-2013.