UNPKG

dygraphs

Version:

dygraphs is a fast, flexible open source JavaScript charting library.

182 lines (158 loc) 8.94 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Dygraphs — per-series and per-axis options</title> <link rel="stylesheet" type="text/css" href=".jslibs/bootstrap.min.css" /> <link rel="stylesheet" type="text/css" href="dist/dygraph.css" /> <link rel="stylesheet" type="text/css" href="common/vextlnk.css" /> <link rel="stylesheet" type="text/css" href="site.css" /> <script type="text/javascript" src=".jslibs/jquery.min.js"></script> <script type="text/javascript" src=".jslibs/bootstrap.min.js"></script> <script type="text/javascript" src="dist/dygraph.js"></script> </head> <body> <nav id="header" class="navbar navbar-default navbar-fixed-top"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-responsive-collapse" aria-expanded="false"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="/">dygraphs</a> </div><!-- /navbar-header --> <div class="collapse navbar-collapse" id="navbar-responsive-collapse"> <!-- TODO(danvk): fill in relevant links here --> <ul class="nav navbar-nav"> <li class="dropdown"> <a class="dropdown-toggle" id="drop3" role="button" data-toggle="dropdown" href="#">Documentation<b class="caret"></b></a> <ul id="menu0" class="dropdown-menu" role="menu" aria-labelledby="drop3"> <li role="presentation"><a role="menuitem" tabindex="-1" href="tutorial.html">Tutorial</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="options.html">Options Reference</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="jsdoc/symbols/Dygraph.html">API Reference</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="data.html">Data Format</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="annotations.html">Annotations</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="css.html">CSS Reference</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="versions.html">Version History</a></li> <li role="separator" class="divider"></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="ie.html">Notes on Internet Explorer</a></li> </ul> </li> <li class="dropdown"> <a class="dropdown-toggle" id="drop4" role="button" data-toggle="dropdown" href="#">Examples<b class="caret"></b></a> <ul id="menu1" class="dropdown-menu" role="menu" aria-labelledby="drop4"> <li role="presentation"><a role="menuitem" tabindex="-1" href="gallery/">Demo Gallery</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="users.html">List of Users</a></li> <li role="separator" class="divider"></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="tests/">Test Cases</a></li> <li role="separator" class="divider"></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="https://dygraphs.com/fiddle/">Play</a></li> </ul> </li> <li><a class="xnavbar-link" href="download.html">Download</a></li> <li class="dropdown"> <a class="dropdown-toggle" id="drop7" role="button" data-toggle="dropdown" href="#">Community <b class="caret"></b></a> <ul id="menu4" class="dropdown-menu" role="menu" aria-labelledby="drop7"> <li role="presentation"><a role="menuitem" tabindex="-1" href="http://blog.dygraphs.com/">Blog</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="https://stackoverflow.com/questions/ask?tags=dygraphs+javascript">Ask a Question</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="https://stackoverflow.com/questions/tagged/dygraphs">Stack Overflow</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="https://groups.google.com/g/dygraphs-users">Mailing List</a></li> </ul> </li> <li class="dropdown"> <a class="dropdown-toggle" id="drop6" role="button" data-toggle="dropdown" href="#">Contribute <b class="caret"></b></a> <ul id="menu3" class="dropdown-menu" role="menu" aria-labelledby="drop6"> <li role="presentation"><a role="menuitem" tabindex="-1" href="changes.html">Contributors Guide</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="https://github.com/danvk/dygraphs">Source (Github)</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="https://github.com/danvk/dygraphs/issues">Issue Tracker</a></li> <li role="presentation"><a role="menuitem" tabindex="-1" href="https://github.com/danvk/dygraphs/issues/new">Report a Bug</a></li> </ul> </li> </ul><!-- /navbar-nav --> </div><!-- /navbar-responsive-collapse --> </div><!-- container-fluid --> </nav> <div class="container" id="main"> <div class="row"> <div class="col-lg-12"> <h2>dygraphs per-series and per-axis options</h2> <p>When you create a Dygraph object, your code looks something like this:</p> <pre> g = new Dygraph(document.getElementById("div"), <i>data</i>, { <i>options</i> }); </pre> <p>This document is about some of the values you can put in the <i>options</i> parameter.</p> <h3>per-series options</h3> <p>Typically, an option applies to the whole chart: if you set the strokeWidth option, it will apply to all data-series equally:</p> <pre> g = new Dygraph(document.getElementById("div"), "X,Y1,Y2,Y3\n" + "1,2,3,4\n" + ..., { strokeWidth: 5 }); </pre> <p>Some options, however, can be applied on a per-series or a per-axis basis. For instance, to set three different strokeWidths, you could write:</p> <pre> g = new Dygraph(document.getElementById("div"), "X,Y1,Y2,Y3\n" + "1,2,3,4\n" + ..., { strokeWidth: 5, // default stroke width series: { Y1: { strokeWidth: 3 // Y1 gets a special value. }, Y3: { strokeWidth: 1 // so does Y3. } } }); </pre> <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> <h3>per-axis options</h3> <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> <p>Here's how you can do that:</p> <pre> g = new Dygraph(document.getElementById("div"), "X,Y1,Y2,Y3\n" + "1,2,3,4\n" + ..., { axes: { x: { axisLabelFormatter: function(x) { return 'x' + x; } }, y: { axisLabelFormatter: function(y) { return 'y' + y; } } } }); </pre> <p>The keys in the 'axes' option are always 'x', 'y' and, if you have a secondary y-axis, 'y2'. If you set the "axisLabelFormatter" option at the top level, it will apply to all axes.</p> <p>To see this in practice, check out the <a href="tests/two-axes.html">two-axes</a> test.</p> </div> <!-- .col-lg-12 --> </div> <!-- /div.row --> </div> <!-- /div#main.container --> <!-- TODO(danvk): add a real footer --> <!--@@@IFIMPRINT:<div class="container" style="border:1px solid green; margin-bottom:1ex;">@@@PLACE_IMPRINT_LINK_HERE_IF_NECESSARY@@@</div>:FIIMPRINT@@@--> </body> </html>