|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Add Gridlines to a Chart</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: Add Gridlines to a Chart</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 add gridlines to a <code>Chart</code>.</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({ |
|
|
54 |
dataProvider:myDataValues, |
|
|
55 |
render:"#mychart", |
|
|
56 |
horizontalGridlines: { |
|
|
57 |
styles: { |
|
|
58 |
line: { |
|
|
59 |
color: "#dad8c9" |
|
|
60 |
} |
|
|
61 |
} |
|
|
62 |
}, |
|
|
63 |
verticalGridlines: { |
|
|
64 |
styles: { |
|
|
65 |
line: { |
|
|
66 |
color: "#dad8c9" |
|
|
67 |
} |
|
|
68 |
} |
|
|
69 |
} |
|
|
70 |
}); |
|
|
71 |
}); |
|
|
72 |
})(); |
|
|
73 |
</script> |
|
|
74 |
|
|
|
75 |
</div> |
|
|
76 |
<h3>Adding gridlines to a <code>Chart</code> instance</h3> |
|
|
77 |
|
|
|
78 |
<p>Gridlines can be used to make a chart more readable. You can add gridlines to a chart with the <code>horizontalGridlines</code> and <code>verticalGridlines</code> attributes. There are 2 ways to |
|
|
79 |
add gridlines to a chart. Setting either attribute to <code>true</code> will add gridlines with default styling. Alternatively, you can pass a style object to either attribute. The <code>styles</code> |
|
|
80 |
object of a gridline contains the line property with color, alpha and weight attributes.</p> |
|
|
81 |
|
|
|
82 |
<h4>CSS</h4> |
|
|
83 |
<pre class="code prettyprint">#mychart { |
|
|
84 |
margin:10px 10px 10px 10px; |
|
|
85 |
width:90%; |
|
|
86 |
max-width: 800px; |
|
|
87 |
height:400px; |
|
|
88 |
}</pre> |
|
|
89 |
|
|
|
90 |
|
|
|
91 |
<h4>HTML</h4> |
|
|
92 |
<pre class="code prettyprint"><div id="mychart"></div></pre> |
|
|
93 |
|
|
|
94 |
|
|
|
95 |
<h4>JavaScript</h4> |
|
|
96 |
<pre class="code prettyprint">YUI().use('charts', function (Y) |
|
|
97 |
{ |
|
|
98 |
var myDataValues = [ |
|
|
99 |
{category:"5/1/2010", miscellaneous:2000, expenses:3700, revenue:2200}, |
|
|
100 |
{category:"5/2/2010", miscellaneous:50, expenses:9100, revenue:100}, |
|
|
101 |
{category:"5/3/2010", miscellaneous:400, expenses:1100, revenue:1500}, |
|
|
102 |
{category:"5/4/2010", miscellaneous:200, expenses:1900, revenue:2800}, |
|
|
103 |
{category:"5/5/2010", miscellaneous:5000, expenses:5000, revenue:2650} |
|
|
104 |
]; |
|
|
105 |
|
|
|
106 |
var mychart = new Y.Chart({ |
|
|
107 |
dataProvider:myDataValues, |
|
|
108 |
render:"#mychart", |
|
|
109 |
horizontalGridlines: { |
|
|
110 |
styles: { |
|
|
111 |
line: { |
|
|
112 |
color: "#dad8c9" |
|
|
113 |
} |
|
|
114 |
} |
|
|
115 |
}, |
|
|
116 |
verticalGridlines: { |
|
|
117 |
styles: { |
|
|
118 |
line: { |
|
|
119 |
color: "#dad8c9" |
|
|
120 |
} |
|
|
121 |
} |
|
|
122 |
} |
|
|
123 |
}); |
|
|
124 |
});</pre> |
|
|
125 |
|
|
|
126 |
</div> |
|
|
127 |
</div> |
|
|
128 |
</div> |
|
|
129 |
|
|
|
130 |
<div class="yui3-u-1-4"> |
|
|
131 |
<div class="sidebar"> |
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
|
135 |
<div class="sidebox"> |
|
|
136 |
<div class="hd"> |
|
|
137 |
<h2 class="no-toc">Examples</h2> |
|
|
138 |
</div> |
|
|
139 |
|
|
|
140 |
<div class="bd"> |
|
|
141 |
<ul class="examples"> |
|
|
142 |
|
|
|
143 |
|
|
|
144 |
<li data-description="Shows how to use Charts to create a basic chart."> |
|
|
145 |
<a href="charts-simple.html">Basic Charts Implementation</a> |
|
|
146 |
</li> |
|
|
147 |
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
<li data-description="Shows how to create a chart with multiple series."> |
|
|
151 |
<a href="charts-multiseries.html">Chart with Multiple Series</a> |
|
|
152 |
</li> |
|
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
|
156 |
<li data-description="Shows how to create a column chart with multiple series."> |
|
|
157 |
<a href="charts-column.html">Specify Chart Type</a> |
|
|
158 |
</li> |
|
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
<li data-description="Shows how to create a column chart with a stacked numeric axis."> |
|
|
163 |
<a href="charts-stackedcolumn.html">Create Stacked Chart</a> |
|
|
164 |
</li> |
|
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
|
168 |
<li data-description="Shows how to create a chart with a time axis."> |
|
|
169 |
<a href="charts-timeaxis.html">Create a Chart with a Time Axis</a> |
|
|
170 |
</li> |
|
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
|
174 |
<li data-description="Shows how to add gridlines to a chart."> |
|
|
175 |
<a href="charts-gridlines.html">Add Gridlines to a Chart</a> |
|
|
176 |
</li> |
|
|
177 |
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
<li data-description="Shows how to create a chart with planar based events."> |
|
|
181 |
<a href="charts-stackedarea.html">Create a Stacked Area Chart with Planar Based Events</a> |
|
|
182 |
</li> |
|
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
<li data-description="Shows how to use a chart's styles attribute to customize a chart."> |
|
|
187 |
<a href="charts-globalstyles.html">Customize a Chart</a> |
|
|
188 |
</li> |
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
<li data-description="Shows how to customize the default tooltip of a chart."> |
|
|
193 |
<a href="charts-customizedtooltip.html">Customize a Chart's Tooltip</a> |
|
|
194 |
</li> |
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
<li data-description="Shows how to explicitly define the axes and series for a chart."> |
|
|
199 |
<a href="charts-objectstyles.html">Define a Chart's Axes and Series</a> |
|
|
200 |
</li> |
|
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
<li data-description="Shows how to use charts to create a pie chart."> |
|
|
205 |
<a href="charts-pie.html">Pie Chart</a> |
|
|
206 |
</li> |
|
|
207 |
|
|
|
208 |
|
|
|
209 |
|
|
|
210 |
<li data-description="Shows how to create a chart with multiple value axes."> |
|
|
211 |
<a href="charts-dualaxes.html">Dual Axes Chart</a> |
|
|
212 |
</li> |
|
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
<li data-description="Shows how to access a chart instance's value axis after the chart has rendered."> |
|
|
217 |
<a href="charts-axisupdate.html">Update Chart Axis</a> |
|
|
218 |
</li> |
|
|
219 |
|
|
|
220 |
|
|
|
221 |
|
|
|
222 |
<li data-description="Shows how to access a chart instance's seriesCollection after the chart has rendered."> |
|
|
223 |
<a href="charts-seriesupdate.html">Update Chart Series</a> |
|
|
224 |
</li> |
|
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
<li data-description="Shows how to add a legend to a chart."> |
|
|
229 |
<a href="charts-legend.html">Create Chart with a Legend</a> |
|
|
230 |
</li> |
|
|
231 |
|
|
|
232 |
|
|
|
233 |
|
|
|
234 |
<li data-description="Shows how to render multiple data points in a singe marker."> |
|
|
235 |
<a href="charts-groupmarkers.html">Group Marker Chart</a> |
|
|
236 |
</li> |
|
|
237 |
|
|
|
238 |
|
|
|
239 |
</ul> |
|
|
240 |
</div> |
|
|
241 |
</div> |
|
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
|
245 |
</div> |
|
|
246 |
</div> |
|
|
247 |
</div> |
|
|
248 |
</div> |
|
|
249 |
|
|
|
250 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
251 |
<script>prettyPrint();</script> |
|
|
252 |
|
|
|
253 |
<script> |
|
|
254 |
YUI.Env.Tests = { |
|
|
255 |
examples: [], |
|
|
256 |
project: '../assets', |
|
|
257 |
assets: '../assets/charts', |
|
|
258 |
name: 'charts-gridlines', |
|
|
259 |
title: 'Add Gridlines to a Chart', |
|
|
260 |
newWindow: '', |
|
|
261 |
auto: false |
|
|
262 |
}; |
|
|
263 |
YUI.Env.Tests.examples.push('charts-simple'); |
|
|
264 |
YUI.Env.Tests.examples.push('charts-multiseries'); |
|
|
265 |
YUI.Env.Tests.examples.push('charts-column'); |
|
|
266 |
YUI.Env.Tests.examples.push('charts-stackedcolumn'); |
|
|
267 |
YUI.Env.Tests.examples.push('charts-timeaxis'); |
|
|
268 |
YUI.Env.Tests.examples.push('charts-gridlines'); |
|
|
269 |
YUI.Env.Tests.examples.push('charts-stackedarea'); |
|
|
270 |
YUI.Env.Tests.examples.push('charts-globalstyles'); |
|
|
271 |
YUI.Env.Tests.examples.push('charts-customizedtooltip'); |
|
|
272 |
YUI.Env.Tests.examples.push('charts-objectstyles'); |
|
|
273 |
YUI.Env.Tests.examples.push('charts-pie'); |
|
|
274 |
YUI.Env.Tests.examples.push('charts-dualaxes'); |
|
|
275 |
YUI.Env.Tests.examples.push('charts-axisupdate'); |
|
|
276 |
YUI.Env.Tests.examples.push('charts-seriesupdate'); |
|
|
277 |
YUI.Env.Tests.examples.push('charts-legend'); |
|
|
278 |
YUI.Env.Tests.examples.push('charts-groupmarkers'); |
|
|
279 |
|
|
|
280 |
</script> |
|
|
281 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
282 |
|
|
|
283 |
|
|
|
284 |
|
|
|
285 |
</body> |
|
|
286 |
</html> |