|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Chart with Multiple Series</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
<h1>Example: Chart with Multiple Series</h1> |
|
|
25 |
<div class="yui3-g"> |
|
|
26 |
<div class="yui3-u-3-4"> |
|
|
27 |
<div id="main"> |
|
|
28 |
<div class="content"><style scoped> |
|
|
29 |
#mychart { |
|
|
30 |
margin:10px 10px 10px 10px; |
|
|
31 |
width:90%; |
|
|
32 |
max-width: 800px; |
|
|
33 |
height:400px; |
|
|
34 |
} |
|
|
35 |
</style> |
|
|
36 |
<div class="intro"> |
|
|
37 |
<p>This example shows how to create a <code>Chart</code> with multiple series.</p> |
|
|
38 |
</div> |
|
|
39 |
<div class="example"> |
|
|
40 |
<div id="mychart"></div> |
|
|
41 |
<script type="text/javascript"> |
|
|
42 |
(function() { |
|
|
43 |
YUI().use('charts', function (Y) |
|
|
44 |
{ |
|
|
45 |
var myDataValues = [ |
|
|
46 |
{category:"5/1/2010", miscellaneous:2000, expenses:3700, revenue:2200}, |
|
|
47 |
{category:"5/2/2010", miscellaneous:50, expenses:9100, revenue:100}, |
|
|
48 |
{category:"5/3/2010", miscellaneous:400, expenses:1100, revenue:1500}, |
|
|
49 |
{category:"5/4/2010", miscellaneous:200, expenses:1900, revenue:2800}, |
|
|
50 |
{category:"5/5/2010", miscellaneous:5000, expenses:5000, revenue:2650} |
|
|
51 |
]; |
|
|
52 |
|
|
|
53 |
var mychart = new Y.Chart({dataProvider:myDataValues, render:"#mychart"}); |
|
|
54 |
}); |
|
|
55 |
})(); |
|
|
56 |
</script> |
|
|
57 |
|
|
|
58 |
</div> |
|
|
59 |
<h3>Creating a chart <code>Chart</code> with multiple series.</h3> |
|
|
60 |
|
|
|
61 |
<h4>Implementation</h4> |
|
|
62 |
|
|
|
63 |
<p>Often times, you will want to plot multiple sets of data, or series, across the same category or range axis in a chart. This can be accomplished by changing your <code>dataProvider</code> source appropriately.</p> |
|
|
64 |
|
|
|
65 |
<h4>CSS</h4> |
|
|
66 |
<pre class="code prettyprint">#mychart { |
|
|
67 |
margin:10px 10px 10px 10px; |
|
|
68 |
width:90%; |
|
|
69 |
max-width: 800px; |
|
|
70 |
height:400px; |
|
|
71 |
}</pre> |
|
|
72 |
|
|
|
73 |
|
|
|
74 |
<h4>HTML</h4> |
|
|
75 |
<pre class="code prettyprint"><div id="mychart"></div></pre> |
|
|
76 |
|
|
|
77 |
|
|
|
78 |
<h4>JavaScript</h4> |
|
|
79 |
<pre class="code prettyprint">YUI().use('charts', function (Y) |
|
|
80 |
{ |
|
|
81 |
var myDataValues = [ |
|
|
82 |
{category:"5/1/2010", miscellaneous:2000, expenses:3700, revenue:2200}, |
|
|
83 |
{category:"5/2/2010", miscellaneous:50, expenses:9100, revenue:100}, |
|
|
84 |
{category:"5/3/2010", miscellaneous:400, expenses:1100, revenue:1500}, |
|
|
85 |
{category:"5/4/2010", miscellaneous:200, expenses:1900, revenue:2800}, |
|
|
86 |
{category:"5/5/2010", miscellaneous:5000, expenses:5000, revenue:2650} |
|
|
87 |
]; |
|
|
88 |
|
|
|
89 |
var mychart = new Y.Chart({dataProvider:myDataValues, render:"#mychart"}); |
|
|
90 |
});</pre> |
|
|
91 |
|
|
|
92 |
|
|
|
93 |
<p>The only difference between the above code and the previous example is that the <code>dataProvider</code> array has more records.</p> |
|
|
94 |
<p>The chart application will plot all records that match it's <code>categoryKey</code> attribute along the category axis. |
|
|
95 |
All other records will be plotted as series against the value axis. By default a chart's <code>categoryKey</code> is "category". This can be changed, if |
|
|
96 |
necessary, to match the format of your <code>dataProvider</code> array. For example, if the key value for your dates was "date", you would need to change |
|
|
97 |
the chart's <code>categoryKey</code> to "date".</p> |
|
|
98 |
|
|
|
99 |
<pre class="code prettyprint">YUI().use('charts', function (Y) |
|
|
100 |
{ |
|
|
101 |
var myDataValues = [ |
|
|
102 |
{date:"5/1/2010", miscellaneous:2000, expenses:3700, revenue:2200}, |
|
|
103 |
{date:"5/2/2010", miscellaneous:50, expenses:9100, revenue:100}, |
|
|
104 |
{date:"5/3/2010", miscellaneous:400, expenses:1100, revenue:1500}, |
|
|
105 |
{date:"5/4/2010", miscellaneous:200, expenses:1900, revenue:2800}, |
|
|
106 |
{date:"5/5/2010", miscellaneous:5000, expenses:5000, revenue:2650} |
|
|
107 |
]; |
|
|
108 |
|
|
|
109 |
var mychart = new Y.Chart({dataProvider:myDataValues, render:"#mychart", categoryKey:"date"}); |
|
|
110 |
});</pre> |
|
|
111 |
|
|
|
112 |
|
|
|
113 |
<p>By default, all remaining key values in your object literals will plot as series data on the chart. If you want to restrict the data that plots on a chart, |
|
|
114 |
you can do so by setting the <code>seriesKeys</code> attribute. The below line of code would only display the expenses and revenue.</p> |
|
|
115 |
|
|
|
116 |
<pre class="code prettyprint">var mychart = new Y.Chart({ |
|
|
117 |
dataProvider:myDataValues, |
|
|
118 |
render:"#mychart", |
|
|
119 |
categoryKey:"date", |
|
|
120 |
seriesKeys:["expenses", "revenue"] |
|
|
121 |
});</pre> |
|
|
122 |
|
|
|
123 |
</div> |
|
|
124 |
</div> |
|
|
125 |
</div> |
|
|
126 |
|
|
|
127 |
<div class="yui3-u-1-4"> |
|
|
128 |
<div class="sidebar"> |
|
|
129 |
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
<div class="sidebox"> |
|
|
133 |
<div class="hd"> |
|
|
134 |
<h2 class="no-toc">Examples</h2> |
|
|
135 |
</div> |
|
|
136 |
|
|
|
137 |
<div class="bd"> |
|
|
138 |
<ul class="examples"> |
|
|
139 |
|
|
|
140 |
|
|
|
141 |
<li data-description="Shows how to use Charts to create a basic chart."> |
|
|
142 |
<a href="charts-simple.html">Basic Charts Implementation</a> |
|
|
143 |
</li> |
|
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
<li data-description="Shows how to create a chart with multiple series."> |
|
|
148 |
<a href="charts-multiseries.html">Chart with Multiple Series</a> |
|
|
149 |
</li> |
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
|
153 |
<li data-description="Shows how to create a column chart with multiple series."> |
|
|
154 |
<a href="charts-column.html">Specify Chart Type</a> |
|
|
155 |
</li> |
|
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
|
159 |
<li data-description="Shows how to create a column chart with a stacked numeric axis."> |
|
|
160 |
<a href="charts-stackedcolumn.html">Create Stacked Chart</a> |
|
|
161 |
</li> |
|
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
|
165 |
<li data-description="Shows how to create a chart with a time axis."> |
|
|
166 |
<a href="charts-timeaxis.html">Create a Chart with a Time Axis</a> |
|
|
167 |
</li> |
|
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
<li data-description="Shows how to add gridlines to a chart."> |
|
|
172 |
<a href="charts-gridlines.html">Add Gridlines to a Chart</a> |
|
|
173 |
</li> |
|
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
<li data-description="Shows how to create a chart with planar based events."> |
|
|
178 |
<a href="charts-stackedarea.html">Create a Stacked Area Chart with Planar Based Events</a> |
|
|
179 |
</li> |
|
|
180 |
|
|
|
181 |
|
|
|
182 |
|
|
|
183 |
<li data-description="Shows how to use a chart's styles attribute to customize a chart."> |
|
|
184 |
<a href="charts-globalstyles.html">Customize a Chart</a> |
|
|
185 |
</li> |
|
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
<li data-description="Shows how to customize the default tooltip of a chart."> |
|
|
190 |
<a href="charts-customizedtooltip.html">Customize a Chart's Tooltip</a> |
|
|
191 |
</li> |
|
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
<li data-description="Shows how to explicitly define the axes and series for a chart."> |
|
|
196 |
<a href="charts-objectstyles.html">Define a Chart's Axes and Series</a> |
|
|
197 |
</li> |
|
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
|
201 |
<li data-description="Shows how to use charts to create a pie chart."> |
|
|
202 |
<a href="charts-pie.html">Pie Chart</a> |
|
|
203 |
</li> |
|
|
204 |
|
|
|
205 |
|
|
|
206 |
|
|
|
207 |
<li data-description="Shows how to create a chart with multiple value axes."> |
|
|
208 |
<a href="charts-dualaxes.html">Dual Axes Chart</a> |
|
|
209 |
</li> |
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
<li data-description="Shows how to access a chart instance's value axis after the chart has rendered."> |
|
|
214 |
<a href="charts-axisupdate.html">Update Chart Axis</a> |
|
|
215 |
</li> |
|
|
216 |
|
|
|
217 |
|
|
|
218 |
|
|
|
219 |
<li data-description="Shows how to access a chart instance's seriesCollection after the chart has rendered."> |
|
|
220 |
<a href="charts-seriesupdate.html">Update Chart Series</a> |
|
|
221 |
</li> |
|
|
222 |
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
<li data-description="Shows how to add a legend to a chart."> |
|
|
226 |
<a href="charts-legend.html">Create Chart with a Legend</a> |
|
|
227 |
</li> |
|
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
|
231 |
<li data-description="Shows how to render multiple data points in a singe marker."> |
|
|
232 |
<a href="charts-groupmarkers.html">Group Marker Chart</a> |
|
|
233 |
</li> |
|
|
234 |
|
|
|
235 |
|
|
|
236 |
</ul> |
|
|
237 |
</div> |
|
|
238 |
</div> |
|
|
239 |
|
|
|
240 |
|
|
|
241 |
|
|
|
242 |
</div> |
|
|
243 |
</div> |
|
|
244 |
</div> |
|
|
245 |
</div> |
|
|
246 |
|
|
|
247 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
248 |
<script>prettyPrint();</script> |
|
|
249 |
|
|
|
250 |
<script> |
|
|
251 |
YUI.Env.Tests = { |
|
|
252 |
examples: [], |
|
|
253 |
project: '../assets', |
|
|
254 |
assets: '../assets/charts', |
|
|
255 |
name: 'charts-multiseries', |
|
|
256 |
title: 'Chart with Multiple Series', |
|
|
257 |
newWindow: '', |
|
|
258 |
auto: false |
|
|
259 |
}; |
|
|
260 |
YUI.Env.Tests.examples.push('charts-simple'); |
|
|
261 |
YUI.Env.Tests.examples.push('charts-multiseries'); |
|
|
262 |
YUI.Env.Tests.examples.push('charts-column'); |
|
|
263 |
YUI.Env.Tests.examples.push('charts-stackedcolumn'); |
|
|
264 |
YUI.Env.Tests.examples.push('charts-timeaxis'); |
|
|
265 |
YUI.Env.Tests.examples.push('charts-gridlines'); |
|
|
266 |
YUI.Env.Tests.examples.push('charts-stackedarea'); |
|
|
267 |
YUI.Env.Tests.examples.push('charts-globalstyles'); |
|
|
268 |
YUI.Env.Tests.examples.push('charts-customizedtooltip'); |
|
|
269 |
YUI.Env.Tests.examples.push('charts-objectstyles'); |
|
|
270 |
YUI.Env.Tests.examples.push('charts-pie'); |
|
|
271 |
YUI.Env.Tests.examples.push('charts-dualaxes'); |
|
|
272 |
YUI.Env.Tests.examples.push('charts-axisupdate'); |
|
|
273 |
YUI.Env.Tests.examples.push('charts-seriesupdate'); |
|
|
274 |
YUI.Env.Tests.examples.push('charts-legend'); |
|
|
275 |
YUI.Env.Tests.examples.push('charts-groupmarkers'); |
|
|
276 |
|
|
|
277 |
</script> |
|
|
278 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
279 |
|
|
|
280 |
|
|
|
281 |
|
|
|
282 |
</body> |
|
|
283 |
</html> |