YUI Library Home

YUI Library Examples: Charts Control: Stacked Bar Chart

Charts Control: Stacked Bar Chart

This example demonstrates how to use YUI Charts Control to create a Stacked Bar Chart.

Please note: The YUI Charts Control requires Flash Player 9.0.45 or higher. The latest version of Flash Player is available at the Adobe Flash Player Download Center.

Media Conglomerate Ad Sales Summary 2004-2007
Unable to load Flash content. The YUI Charts Control requires Flash Player 9.0.45 or higher. You can download the latest version of Flash Player from the Adobe Flash Player Download Center.

Create a Stacked BarChart

When creating Bar and Column charts with multiple series, you have the ability to stack your series on top of one-another. In this example, we'll create stacked BarChart, which lets you show the absolute values of data points through their segments, as well as the total values of each series.

Create a DataSource

First, we'll create the DataSource to populate the chart. This DataSource contains four values, a year and three sets of sales figures.

Define Series Definition

We will have three series in our example, corresponding to the Internet sales, print sales, and TV sales.

Create an Axis

Create a NumericAxis and set its stackingEnabled property to true. Assign a labelFunction to format the axis.

Create a StackedBarChart

Instantiate a StackedBarChart and set its xAxis to the NumericAxis you created.

The series bars will stack from left to right rather than aligning vertically.

Configuration for This Example

You can load the necessary JavaScript and CSS for this example from Yahoo's servers. Click here to load the YUI Dependency Configurator with all of this example's dependencies preconfigured.

Copyright © 2011 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings