5
<title>Example: Define a Chart's Axes and Series</title>
6
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Maven+Pro:400,700">
7
<link rel="stylesheet" href="../../build/cssgrids/grids-min.css">
8
<link rel="stylesheet" href="../assets/css/main.css">
9
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
10
<script src="../../build/yui/yui-min.js"></script>
15
<h1>Example: Define a Chart's Axes and Series</h1>
20
<div class="yui3-u-3-4">
22
<div class="content"><style scoped>
24
margin:10px 10px 10px 10px;
31
<p>This example shows how to explicitly define the axes and series for a <code>Chart</code>.</p>
34
<div id="mychart"></div>
35
<script type="text/javascript">
37
YUI().use('charts', function (Y)
41
{date:"1/1/2010", miscellaneous:2000, expenses:3700, revenue:2200},
42
{date:"2/1/2010", miscellaneous:5000, expenses:9100, revenue:100},
43
{date:"3/1/2010", miscellaneous:4000, expenses:1900, revenue:1500},
44
{date:"4/1/2010", miscellaneous:3000, expenses:3900, revenue:2800},
45
{date:"5/1/2010", miscellaneous:500, expenses:7000, revenue:2650},
46
{date:"6/1/2010", miscellaneous:3000, expenses:4700, revenue:1200}
49
//Define our axes for the chart.
52
keys:["miscellaneous", "revenue", "expenses"],
78
var seriesCollection = [
86
yDisplayName:"Miscellaneous",
105
yDisplayName:"Expenses",
130
yDisplayName:"Deductions",
152
//instantiate the chart
153
var myChart = new Y.Chart({
154
dataProvider:myDataValues,
156
seriesCollection:seriesCollection,
157
horizontalGridlines: true,
158
verticalGridlines: true,
166
<h3>Defining the axes and series for a <code>Chart</code> instance</h3>
168
<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
169
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
170
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
171
object literals. This will allow us to place our value axis on the right and build a chart with columns and lines.</p>
173
<pre class="code prettyprint">YUI().use('charts', function (Y)
175
//dataProvider source
177
{date:"1/1/2010", miscellaneous:2000, expenses:3700, revenue:2200},
178
{date:"2/1/2010", miscellaneous:5000, expenses:9100, revenue:100},
179
{date:"3/1/2010", miscellaneous:4000, expenses:1900, revenue:1500},
180
{date:"4/1/2010", miscellaneous:3000, expenses:3900, revenue:2800},
181
{date:"5/1/2010", miscellaneous:500, expenses:7000, revenue:2650},
182
{date:"6/1/2010", miscellaneous:3000, expenses:4700, revenue:1200}
185
//Define our axes for the chart.
188
keys:["miscellaneous", "revenue", "expenses"],
189
position:"right",
190
type:"numeric",
193
display: "none"
198
keys:["date"],
199
position:"bottom",
200
type:"category",
203
display: "none"
213
//define the series
214
var seriesCollection = [
216
type:"column",
217
xAxis:"dateRange",
218
yAxis:"financials",
219
xKey:"date",
220
yKey:"miscellaneous",
221
xDisplayName:"Date",
222
yDisplayName:"Miscellaneous",
226
color: "#58006e"
236
type:"column",
237
xAxis:"dateRange",
238
yAxis:"financials",
239
xKey:"date",
240
yKey:"expenses",
241
yDisplayName:"Expenses",
245
color: "#e0ddd0"
249
color: "#cbc8ba"
260
type:"combo",
261
xAxis:"dateRange",
262
yAxis:"financials",
263
xKey:"date",
264
yKey:"revenue",
265
xDisplayName:"Date",
266
yDisplayName:"Deductions",
268
color: "#ff7200"
272
color: "#ff9f3b"
275
color: "#ff7200",
288
//instantiate the chart
289
var myChart = new Y.Chart({
290
dataProvider:myDataValues,
292
seriesCollection:seriesCollection,
293
horizontalGridlines: true,
294
verticalGridlines: true,
295
render:"#mychart"
303
<div class="yui3-u-1-4">
304
<div class="sidebar">
308
<div class="sidebox">
310
<h2 class="no-toc">Examples</h2>
314
<ul class="examples">
317
<li data-description="Shows how to use Charts to create a basic chart.">
318
<a href="charts-simple.html">Basic Charts Implementation</a>
323
<li data-description="Shows how to create a chart with multiple series.">
324
<a href="charts-multiseries.html">Chart with Multiple Series</a>
329
<li data-description="Shows how to create a column chart with multiple series.">
330
<a href="charts-column.html">Specify Chart Type</a>
335
<li data-description="Shows how to create a column chart with a stacked numeric axis.">
336
<a href="charts-stackedcolumn.html">Create Stacked Chart</a>
341
<li data-description="Shows how to create a chart with a time axis.">
342
<a href="charts-timeaxis.html">Create a Chart with a Time Axis</a>
347
<li data-description="Shows how to add gridlines to a chart.">
348
<a href="charts-gridlines.html">Add Gridlines to a Chart</a>
353
<li data-description="Shows how to create a chart with planar based events.">
354
<a href="charts-stackedarea.html">Create a Stacked Area Chart with Planar Based Events</a>
359
<li data-description="Shows how to use a chart's styles attribute to customize a chart.">
360
<a href="charts-globalstyles.html">Customize a Chart</a>
365
<li data-description="Shows how to customize the default tooltip of a chart.">
366
<a href="charts-customizedtooltip.html">Customize a Chart's Tooltip</a>
371
<li data-description="Shows how to explicitly define the axes and series for a chart.">
372
<a href="charts-objectstyles.html">Define a Chart's Axes and Series</a>
377
<li data-description="Shows how to use charts to create a pie chart.">
378
<a href="charts-pie.html">Pie Chart</a>
383
<li data-description="Shows how to create a chart with multiple value axes.">
384
<a href="charts-dualaxes.html">Dual Axes Chart</a>
389
<li data-description="Shows how to access a chart instance's value axis after the chart has rendered.">
390
<a href="charts-axisupdate.html">Update Chart Axis</a>
395
<li data-description="Shows how to access a chart instance's seriesCollection after the chart has rendered.">
396
<a href="charts-seriesupdate.html">Update Chart Series</a>
401
<li data-description="Shows how to add a legend to a chart.">
402
<a href="charts-legend.html">Create Chart with a Legend</a>
407
<li data-description="Shows how to render multiple data points in a singe marker.">
408
<a href="charts-groupmarkers.html">Group Marker Chart</a>
423
<script src="../assets/vendor/prettify/prettify-min.js"></script>
424
<script>prettyPrint();</script>