Merge pull request #499 from danvk/synchronizer
[dygraphs.git] / docs / per-axis.html
CommitLineData
14403441
DV
1<!--#include virtual="header.html" -->
2<h2>dygraphs per-series and per-axis options</h2>
3
4<p>When you create a Dygraph object, your code looks something like
5this:</p>
6
7<pre>
8 g = new Dygraph(document.getElementById("div"),
9 <i>data</i>,
10 { <i>options</i> });
11</pre>
12
13<p>This document is about some of the values you can put in the
14<i>options</i> parameter.</p>
15
16<h3>per-series options</h3>
17
18<p>Typically, an option applies to the whole chart: if you set the
19strokeWidth option, it will apply to all data-series equally:</p>
20
21<pre>
22 g = new Dygraph(document.getElementById("div"),
23 "X,Y1,Y2,Y3\n" +
24 "1,2,3,4\n" +
25 ...,
26 {
27 strokeWidth: 5
28 });
29</pre>
30
31<p>Some options, however, can be applied on a per-series or a per-axis
32basis. For instance, to set three different strokeWidths, you could
33write:</p>
34
35<pre>
36 g = new Dygraph(document.getElementById("div"),
37 "X,Y1,Y2,Y3\n" +
38 "1,2,3,4\n" +
39 ...,
40 {
41 strokeWidth: 5, // default stroke width
42 'Y1': {
43 strokeWidth: 3 // Y1 gets a special value.
44 },
45 'Y3': {
46 strokeWidth: 1 // so does Y3.
47 }
48 });
49</pre>
50
51<p>The result of these options is that Y1 will have a strokeWidth of 1, Y2 will have a strokeWidth of 5 and Y3 will have a strokeWidth of 1. You can see a demonstration of this <a href='tests/per-series.html'>here</a>.</p>
52
53<h3>per-axis options</h3>
54
55<p>Some options make more sense when applied to an entire axis, rather than to individual series. For instance, the axisLabelFormatter option lets you specify a function for format the labels on axis tick marks for display. You might want one function for the x-axis and another one for the y-axis.</p>
56
57<p>Here's how you can do that:</p>
58
59<pre>
60 g = new Dygraph(document.getElementById("div"),
61 "X,Y1,Y2,Y3\n" +
62 "1,2,3,4\n" +
63 ...,
64 {
65 axes: {
66 x: {
67 axisLabelFormatter: function(x) {
68 return 'x' + x;
48e614ac 69 }
14403441
DV
70 },
71 y: {
72 axisLabelFormatter: function(y) {
73 return 'y' + y;
48e614ac 74 }
14403441
DV
75 }
76 }
77 });
78</pre>
79
80<p>The keys in the 'axes' option are always 'x', 'y' and, if you have a
81secondary y-axis, 'y2'. If you set the "axisLabelFormatter" option at the
82top level, it will apply to all axes.</p>
83
84<p>To see this in practice, check out the <a
85href="tests/two-axes.html">two-axes</a> test.</p>
86
87<!--#include virtual="footer.html" -->