5
<title>Example: Define a Chart's Axes and Series</title>
6
<link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
<link rel="stylesheet" href="../assets/css/main.css">
8
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
<script src="../../build/yui/yui-min.js"></script>
14
<h1>Example: Define a Chart's Axes and Series</h1>
19
<div id="main" class="yui3-u">
20
<div class="content"><style scoped>
22
margin:10px 10px 10px 10px;
29
<p>This example shows how to explicitly define the axes and series for a <code>Chart</code>.</p>
32
<div id="mychart"></div>
33
<script type="text/javascript">
35
YUI().use('charts', function (Y)
39
{date:"1/1/2010", miscellaneous:2000, expenses:3700, revenue:2200},
40
{date:"2/1/2010", miscellaneous:5000, expenses:9100, revenue:100},
41
{date:"3/1/2010", miscellaneous:4000, expenses:1900, revenue:1500},
42
{date:"4/1/2010", miscellaneous:3000, expenses:3900, revenue:2800},
43
{date:"5/1/2010", miscellaneous:500, expenses:7000, revenue:2650},
44
{date:"6/1/2010", miscellaneous:3000, expenses:4700, revenue:1200}
47
//Define our axes for the chart.
50
keys:["miscellaneous", "revenue", "expenses"],
76
var seriesCollection = [
84
yDisplayName:"Miscellaneous",
103
yDisplayName:"Expenses",
128
yDisplayName:"Deductions",
150
//instantiate the chart
151
var myChart = new Y.Chart({
152
dataProvider:myDataValues,
154
seriesCollection:seriesCollection,
155
horizontalGridlines: true,
156
verticalGridlines: true,
164
<h3>Defining the axes and series for a <code>Chart</code> instance</h3>
166
<p>As we have seen from previous examples, the <code>Chart</code> class allows you to create and customize multiple chart types with very little code. Sometimes you'll want more control
167
over the <code>Chart</code>. Suppose you want to place your value axis on the right or you need different series types in the same chart. Charts allows you to explicitly define your series and axes objects. You can either declare
168
an axis or series directly or define them with an object literal and allow the <code>Chart</code> instance to build them for you. In this example, we are going to define our axes and series with
169
object literals. This will allow us to place our value axis on the right and build a chart with columns and lines.</p>
171
<pre class="code prettyprint">YUI().use('charts', function (Y)
173
//dataProvider source
175
{date:"1/1/2010", miscellaneous:2000, expenses:3700, revenue:2200},
176
{date:"2/1/2010", miscellaneous:5000, expenses:9100, revenue:100},
177
{date:"3/1/2010", miscellaneous:4000, expenses:1900, revenue:1500},
178
{date:"4/1/2010", miscellaneous:3000, expenses:3900, revenue:2800},
179
{date:"5/1/2010", miscellaneous:500, expenses:7000, revenue:2650},
180
{date:"6/1/2010", miscellaneous:3000, expenses:4700, revenue:1200}
183
//Define our axes for the chart.
186
keys:["miscellaneous", "revenue", "expenses"],
187
position:"right",
188
type:"numeric",
191
display: "none"
196
keys:["date"],
197
position:"bottom",
198
type:"category",
201
display: "none"
211
//define the series
212
var seriesCollection = [
214
type:"column",
215
xAxis:"dateRange",
216
yAxis:"financials",
217
xKey:"date",
218
yKey:"miscellaneous",
219
xDisplayName:"Date",
220
yDisplayName:"Miscellaneous",
224
color: "#58006e"
234
type:"column",
235
xAxis:"dateRange",
236
yAxis:"financials",
237
xKey:"date",
238
yKey:"expenses",
239
yDisplayName:"Expenses",
243
color: "#e0ddd0"
247
color: "#cbc8ba"
258
type:"combo",
259
xAxis:"dateRange",
260
yAxis:"financials",
261
xKey:"date",
262
yKey:"revenue",
263
xDisplayName:"Date",
264
yDisplayName:"Deductions",
266
color: "#ff7200"
270
color: "#ff9f3b"
273
color: "#ff7200",
286
//instantiate the chart
287
var myChart = new Y.Chart({
288
dataProvider:myDataValues,
290
seriesCollection:seriesCollection,
291
horizontalGridlines: true,
292
verticalGridlines: true,
293
render:"#mychart"
300
<div id="sidebar" class="yui3-u">
304
<div class="sidebox">
306
<h2 class="no-toc">Examples</h2>
310
<ul class="examples">
313
<li data-description="Shows how to use Charts to create a basic chart.">
314
<a href="charts-simple.html">Basic Charts Implementation</a>
319
<li data-description="Shows how to create a chart with multiple series.">
320
<a href="charts-multiseries.html">Chart with Multiple Series</a>
325
<li data-description="Shows how to create a column chart with multiple series.">
326
<a href="charts-column.html">Specify Chart Type</a>
331
<li data-description="Shows how to create a column chart with a stacked numeric axis.">
332
<a href="charts-stackedcolumn.html">Create Stacked Chart</a>
337
<li data-description="Shows how to create a chart with a time axis.">
338
<a href="charts-timeaxis.html">Create a Chart with a Time Axis</a>
343
<li data-description="Shows how to add gridlines to a chart.">
344
<a href="charts-gridlines.html">Add Gridlines to a Chart</a>
349
<li data-description="Shows how to create a chart with planar based events.">
350
<a href="charts-stackedarea.html">Create a Stacked Area Chart with Planar Based Events</a>
355
<li data-description="Shows how to use a chart's styles attribute to customize a chart.">
356
<a href="charts-globalstyles.html">Customize a Chart</a>
361
<li data-description="Shows how to customize the default tooltip of a chart.">
362
<a href="charts-customizedtooltip.html">Customize a Chart's Tooltip</a>
367
<li data-description="Shows how to explicitly define the axes and series for a chart.">
368
<a href="charts-objectstyles.html">Define a Chart's Axes and Series</a>
373
<li data-description="Shows how to use charts to create a pie chart.">
374
<a href="charts-pie.html">Pie Chart</a>
379
<li data-description="Shows how to create a chart with multiple value axes.">
380
<a href="charts-dualaxes.html">Dual Axes Chart</a>
385
<li data-description="Shows how to access a chart instance's value axis after the chart has rendered.">
386
<a href="charts-axisupdate.html">Update Chart Axis</a>
391
<li data-description="Shows how to access a chart instance's seriesCollection after the chart has rendered.">
392
<a href="charts-seriesupdate.html">Update Chart Series</a>
406
<script src="../assets/vendor/prettify/prettify-min.js"></script>
407
<script>prettyPrint();</script>