Yahoo! Developer Network Home - Help

YDN Site Search

# YUI Library Examples: Charts Control (experimental): Chart with DataSource Polling

# Charts Control (experimental): Chart with DataSource Polling

The YUI Charts Control provides built-in support for iterative polling for data over XHR using an XHR DataSource instance. In the example below, iterative polling causes the chart to refresh every several seconds and animate its display to represent the new 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.

View example in new window.

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 that uses XHR

If a DataSource loads its data from an external source through XHR, a Chart may continually poll the DataSource to determine if new data is available. Nothing special needs to be done to the DataSource. The Chart handles all the details.

var jsonData = new YAHOO.util.DataSource( "assets/generatedata.php?" ); jsonData.responseType = YAHOO.util.DataSource.TYPE_JSON; jsonData.responseSchema = { resultsList: "Results", fields: ["Name","Value"] };

## Turning on Chart Polling

The `polling` attribute of the Chart control accepts a numeric value representing the number of milliseconds between requests for new data.

var mychart = new YAHOO.widget.ColumnChart( "chart", jsonData, { xField: "Name", yField: "Value", yAxis: yAxis, polling: 2000 });

In this case, the Chart control will ask the DataSource to reload its data every 2.5 seconds. When new data is available, the chart will redraw or animate to display the new information.

### YUI Logger Output:

Note: Logging and debugging is currently turned off for this example.

Reload with logging
and debugging enabled.

### Charts Control (experimental) Examples:

- Charts Quickstart Example
- Chart with Legend Example
- Skinning a Chart Example
- Chart and DataTable Example
- Chart with DataSource Polling

### More Charts Control (experimental) Resources:

- User's Guide (external)
- API Documentation
- Cheat Sheet PDF (external)

Copyright © 2008 Yahoo! Inc. All rights reserved.

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