YUI Library Home

YUI Library Examples: Charts Control: Chart and DataTable Example

Charts Control: Chart and DataTable Example

A YUI Charts Control and a DataTable Control may share a DataSource to display the same data.

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.

Widgets, Inc. Financial Summary 2003-2006
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 DataSource

The provider of data for the BarChart and the DataTable in this example is a standard JavaScript Array. Each Object in the Array contains multiple values that can be used for series in the BarChart or headers in the DataTable.

The Array is passed to a new DataSource instance, and fields are defined to specify which items will be used from the original source.

Define a Series Definition

A series definition allows the chart to display more than one series, and one can use it customize the appearance and behavior of each series individually.

In the series definition above, each series uses the xField property to select a different key from the DataSource. The displayName property will provide a visual reference to the name of each series in the mouse-over data tip, and it will be displayed in the legend, if present.

Notice that the third series defines a type property. By customizing this value, we're able to build a combination chart that uses both bars and lines to display its data.

Create the Chart

The DataSource instance is passed as a required argument of the BarChart's constructor. The series definition is passed to the chart through an optional initialization attribute named series. We also specify the default yField to be used for categories and pass in a custom axis that formats its labels as currency.

Define Column Headers and Create DataTable

Similar to the Chart control's series definition, the DataTable control defines column headers. A formatter is set for each column that will display currency.

Both the column headers and the DataSource instance are passed to the DataTable's constructor.

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