5
<title>Example: Update Chart 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: Update Chart Series</h1>
20
<div class="yui3-u-3-4">
22
<div class="content"><style scoped>
23
#custom-doc { width: 95%; min-width: 950px; }
24
#pagetitle {background-image: url(../../assets/bg_hd.gif);}
26
margin:10px 10px 10px 10px;
39
border-top:1px solid #aaa;
44
<p>This example shows how to access a <code>Chart</code> instance's <code>seriesCollection</code> after the <code>Chart</code> has rendered.</p>
47
<div id="mychart"></div>
50
<label for="seriesSelector">series:</label>
51
<select name="seriesSelector" id="seriesSelector">
52
<option value="expenses">expenses</option>
53
<option value="revenue">revenue</option>
57
<label for="fillColor">fill color:</label>
58
<input type="text" name="fillColor" id="fillColor" />
61
<label for="borderColor">border color:</label>
62
<input type="text" name="borderColor" id="borderColor" />
65
<label for="borderWeight">border weight:</label>
66
<input type="text" name="borderColor" id="borderWeight" />
69
<button type="button" class="action" id="updateSeries">Update Series</button>
72
<script type="text/javascript">
74
YUI().use('escape', 'charts', function (Y)
77
{category:"Q1", expenses:137000, revenue:532200},
78
{category:"Q2", expenses:211000, revenue:689100},
79
{category:"Q3", expenses:151000, revenue:521500},
80
{category:"Q4", expenses:163000, revenue:892650}
83
var mychart = new Y.Chart({type:"bar", dataProvider:myDataValues, render:"#mychart"});
86
Y.on("click", function(e) {
87
var seriesName = Y.one("#seriesSelector").get("value"),
88
fillColor = Y.Escape.html(Y.one("#fillColor").get("value")),
89
borderColor = Y.Escape.html(Y.one("#borderColor").get("value")),
90
borderWeight = parseFloat(Y.one("#borderWeight").get("value")),
92
marker = {fill:{}, border:{}};
95
series = mychart.getSeries(seriesName);
98
marker.fill.color = fillColor;
102
marker.border.color = borderColor;
104
if(!isNaN(borderWeight))
106
marker.border.weight = borderWeight;
108
series.set("styles", {marker:marker});
116
<h3>Update Series of a <code>Chart</code> Instance After It has Rendered.</h3>
119
<p>You can update a series after the <code>Chart</code> has rendered through the <code>getSeries</code> method. This method returns a reference to a series instance based on either the
120
instance's <code>seriesCollection</code> index or the key value associated with the value data of the series. This example uses the value key of each series to update the fill color,
121
border color and border weight of its markers.</p>
123
<pre class="code prettyprint">YUI().use('charts', function (Y)
126
{category:"Q1", expenses:137000, revenue:532200},
127
{category:"Q2", expenses:211000, revenue:689100},
128
{category:"Q3", expenses:151000, revenue:521500},
129
{category:"Q4", expenses:163000, revenue:892650}
132
var mychart = new Y.Chart({type:"bar", dataProvider:myDataValues, render:"#mychart"});
134
//Click handler
135
Y.on("click", function(e) {
136
var seriesName = Y.one("#seriesSelector").get("value"),
137
fillColor = Y.Escape.html(Y.one("#fillColor").get("value")),
138
borderColor = Y.Escape.html(Y.one("#borderColor").get("value")),
139
borderWeight = parseFloat(Y.one("#borderWeight").get("value")),
141
marker = {fill:{}, border:{}};
144
series = mychart.getSeries(seriesName);
147
marker.fill.color = fillColor;
151
marker.border.color = borderColor;
153
if(!isNaN(borderWeight))
155
marker.border.weight = borderWeight;
157
series.set("styles", {marker:marker});
159
}, "#updateSeries");
166
<div class="yui3-u-1-4">
167
<div class="sidebar">
171
<div class="sidebox">
173
<h2 class="no-toc">Examples</h2>
177
<ul class="examples">
180
<li data-description="Shows how to use Charts to create a basic chart.">
181
<a href="charts-simple.html">Basic Charts Implementation</a>
186
<li data-description="Shows how to create a chart with multiple series.">
187
<a href="charts-multiseries.html">Chart with Multiple Series</a>
192
<li data-description="Shows how to create a column chart with multiple series.">
193
<a href="charts-column.html">Specify Chart Type</a>
198
<li data-description="Shows how to create a column chart with a stacked numeric axis.">
199
<a href="charts-stackedcolumn.html">Create Stacked Chart</a>
204
<li data-description="Shows how to create a chart with a time axis.">
205
<a href="charts-timeaxis.html">Create a Chart with a Time Axis</a>
210
<li data-description="Shows how to add gridlines to a chart.">
211
<a href="charts-gridlines.html">Add Gridlines to a Chart</a>
216
<li data-description="Shows how to create a chart with planar based events.">
217
<a href="charts-stackedarea.html">Create a Stacked Area Chart with Planar Based Events</a>
222
<li data-description="Shows how to use a chart's styles attribute to customize a chart.">
223
<a href="charts-globalstyles.html">Customize a Chart</a>
228
<li data-description="Shows how to customize the default tooltip of a chart.">
229
<a href="charts-customizedtooltip.html">Customize a Chart's Tooltip</a>
234
<li data-description="Shows how to explicitly define the axes and series for a chart.">
235
<a href="charts-objectstyles.html">Define a Chart's Axes and Series</a>
240
<li data-description="Shows how to use charts to create a pie chart.">
241
<a href="charts-pie.html">Pie Chart</a>
246
<li data-description="Shows how to create a chart with multiple value axes.">
247
<a href="charts-dualaxes.html">Dual Axes Chart</a>
252
<li data-description="Shows how to access a chart instance's value axis after the chart has rendered.">
253
<a href="charts-axisupdate.html">Update Chart Axis</a>
258
<li data-description="Shows how to access a chart instance's seriesCollection after the chart has rendered.">
259
<a href="charts-seriesupdate.html">Update Chart Series</a>
264
<li data-description="Shows how to add a legend to a chart.">
265
<a href="charts-legend.html">Create Chart with a Legend</a>
270
<li data-description="Shows how to render multiple data points in a singe marker.">
271
<a href="charts-groupmarkers.html">Group Marker Chart</a>
286
<script src="../assets/vendor/prettify/prettify-min.js"></script>
287
<script>prettyPrint();</script>