Cross Reference: /yui3/src/charts/docs/charts-legend.mustache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
2431f6aca1be7f7a136c5df34022e3f902490075Tripp<style scoped>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp#mychart {
2431f6aca1be7f7a136c5df34022e3f902490075Tripp margin:10px 10px 10px 10px;
2431f6aca1be7f7a136c5df34022e3f902490075Tripp width:90%;
2431f6aca1be7f7a136c5df34022e3f902490075Tripp max-width: 800px;
2431f6aca1be7f7a136c5df34022e3f902490075Tripp height:400px;
2431f6aca1be7f7a136c5df34022e3f902490075Tripp}
2431f6aca1be7f7a136c5df34022e3f902490075Tripp</style>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp<div class="intro">
2431f6aca1be7f7a136c5df34022e3f902490075Tripp<p>This example shows how to add a legend to a `Chart`.</p>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp</div>
d676c69348c891c2a261a6dbd4f450ddb2e312f3Tripp<div class="example">
2431f6aca1be7f7a136c5df34022e3f902490075Tripp{{>charts-legend-source}}
2431f6aca1be7f7a136c5df34022e3f902490075Tripp</div>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp<h3>Adding a legend to a `Chart` instance</h3>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp
2431f6aca1be7f7a136c5df34022e3f902490075Tripp<p>When a chart has multiple series, a legend can allow the user to identify each series more easily. The `charts` module includes a `charts-legend` submodule. Specifying
2431f6aca1be7f7a136c5df34022e3f902490075Tripp`charts-legend` in you use statement allows you to add a legend to a `Chart` instance. A legend is added to a chart through the `legend` attribute. This attribute is an
2431f6aca1be7f7a136c5df34022e3f902490075Trippobject containing value pairs for the attributes of a legend. All available attributes for the `legend` are outlined <a href="index.html#usinglegend">here</a>. In the
2431f6aca1be7f7a136c5df34022e3f902490075Trippexample below, we will add a legend to a chart instance.</p>
2431f6aca1be7f7a136c5df34022e3f902490075Tripp
2431f6aca1be7f7a136c5df34022e3f902490075Tripp```
2431f6aca1be7f7a136c5df34022e3f902490075TrippYUI().use('charts-legend', function (Y)
2431f6aca1be7f7a136c5df34022e3f902490075Tripp{
2431f6aca1be7f7a136c5df34022e3f902490075Tripp var myDataValues = [
2431f6aca1be7f7a136c5df34022e3f902490075Tripp {category:"5/1/2010", miscellaneous:2000, expenses:3700, revenue:2200},
2431f6aca1be7f7a136c5df34022e3f902490075Tripp {category:"5/2/2010", miscellaneous:50, expenses:9100, revenue:100},
2431f6aca1be7f7a136c5df34022e3f902490075Tripp {category:"5/3/2010", miscellaneous:400, expenses:1100, revenue:1500},
2431f6aca1be7f7a136c5df34022e3f902490075Tripp {category:"5/4/2010", miscellaneous:200, expenses:1900, revenue:2800},
2431f6aca1be7f7a136c5df34022e3f902490075Tripp {category:"5/5/2010", miscellaneous:5000, expenses:5000, revenue:2650}
2431f6aca1be7f7a136c5df34022e3f902490075Tripp ];
2431f6aca1be7f7a136c5df34022e3f902490075Tripp
2431f6aca1be7f7a136c5df34022e3f902490075Tripp var myChart = new Y.Chart({
2431f6aca1be7f7a136c5df34022e3f902490075Tripp legend: {
2431f6aca1be7f7a136c5df34022e3f902490075Tripp position: "right",
2431f6aca1be7f7a136c5df34022e3f902490075Tripp width: 300,
2431f6aca1be7f7a136c5df34022e3f902490075Tripp height: 300,
2431f6aca1be7f7a136c5df34022e3f902490075Tripp styles: {
2431f6aca1be7f7a136c5df34022e3f902490075Tripp hAlign: "center",
2431f6aca1be7f7a136c5df34022e3f902490075Tripp hSpacing: 4
2431f6aca1be7f7a136c5df34022e3f902490075Tripp }
2431f6aca1be7f7a136c5df34022e3f902490075Tripp },
2431f6aca1be7f7a136c5df34022e3f902490075Tripp axes: {
2431f6aca1be7f7a136c5df34022e3f902490075Tripp category: {
2431f6aca1be7f7a136c5df34022e3f902490075Tripp keys: ["date"],
type: "category",
styles: {
label: {
rotation: -90
}
}
}
},
categoryKey: "date",
dataProvider:myDataValues,
horizontalGridlines: true,
verticalGridlines: true,
render:"#mychart"
});
});
```