YUI Library Home

YUI Library Examples: Charts Control: Apply scope to label functions

Charts Control: Apply scope to label functions

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.

Personal Expenses
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 Custom Graph Class

We will start by creating a custom class to contain all the necessary elements required to render a chart.

Our class contains a reference to a dataTip function, data, chart, styles and some custom text to be used in our data tips.

Add Tips Formatting Methods

We will now add all the methods necessary for formatting axis labels and data tips. It is important to note that the dataTip and axis label methods make use of other class level methods, so the ability to add socpe to these methods will prove useful.

Set Axis and DataTip Functions

Next, we will add methods that return an axis and a series definition. We will also add a method that draws our chart. Each of these methods will create references to text formatting functions to pass to our YUI Chart instance. Our vertical axis method sets the axis label function, our series definition sets a data tip function for our car payment series and our chart method sets the data tip function for all other series.

Normally, when setting a formatting function for the chart, a function is passed either directly or as a string reference. When you want to include scope, however, you instead pass an object with two properties, func, a reference to the function, and scope, a reference to the scope. dataTipFunction:{func:myDataTipFunction, scope:this}

Create the Chart

Finally, we'll instantiate our class and draw the chart.

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 © 2009 Yahoo! Inc. All rights reserved.

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