369 lines
47 KiB
HTML
369 lines
47 KiB
HTML
<!doctype html><!--[if lt IE 7]>
|
||
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--><!--[if IE 7]>
|
||
<html class="no-js lt-ie9 lt-ie8"> <![endif]--><!--[if IE 8]>
|
||
<html class="no-js lt-ie9"> <![endif]--><!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]--><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><title>Chartist - Getting started</title><meta name="description" content="Learn how to use Chartist.js"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><link rel="stylesheet" href="styles/vendor.css"><link rel="stylesheet" href="styles/main.css"><section class="page-content getting-started"><div class="contain-to-grid sticky"><nav class="top-bar" data-topbar data-options="sticky_on: large"><ul class="title-area"><li class="name"><h1><a href="index.html">Chartist.js</a></h1><li class="toggle-topbar menu-icon"><a href="#">Menu</a></ul><section class="top-bar-section"><ul class="right"><li><a href="//github.com/gionkunz/chartist-js/tree/master/dist" target="_blank">Download</a></ul><ul class="left"><li><a href="getting-started.html">Getting started</a><li><a href="api-documentation.html">API Documentation</a><li><a href="examples.html">Examples</a><li><a href="plugins.html">Plugins</a><li><a href="//github.com/gionkunz/chartist-js" target="_blank">Contribute</a></ul></section></nav></div><article class="main" role="main"><header><h2>Chartist - Getting started</h2></header><aside class="side-navigation"><nav><ul class="side-nav"><li class="heading">Download and set-up<li><a class="text-clipping" href="#bower">Bower</a><li><a class="text-clipping" href="#one-two-three-css">One, two, three, CSS!</a><li><a class="text-clipping" href="#the-sass-way">The Sass way</a><li class="heading">Create your first chart<li><a class="text-clipping" href="#as-simple-as-it-can-get">As simple as it can get</a><li><a class="text-clipping" href="#the-configuration-of-your-chart">The configuration of your chart</a><li><a class="text-clipping" href="#responsive-sugar-topping">Responsive sugar topping</a><li><a class="text-clipping" href="#different-configuration-for-different-series">Different configuration for different series</a><li class="heading">Styling your chart<li><a class="text-clipping" href="#customizing-the-default-css">Customizing the default CSS</a><li><a class="text-clipping" href="#colour-up-your-charts">Colour up your charts</a><li class="heading">Advanced<li><a class="text-clipping" href="#animations-using-chartistsvg">Animations using Chartist.Svg</a><li><a class="text-clipping" href="#switching-axis-type">Switching axis type</a></ul></nav></aside><div class="content"><section class="documentation-section full"><header><h3 id="download-and-setup">Download and set-up</h3></header><div class="content"><div class="sub-section"><h4 id="bower">Bower</h4><p>The easiest way to get started with Chartist.js is by using <a href="http://bower.io/" target="_blank">bower</a>:<pre><code class="bash">bower install chartist --save</code></pre><p>The bower package contains the JavaScript library, CSS as well as the Sass (SCSS) files. You can then integrate the desired dependencies in your project and start using them immediately.</div><div class="sub-section"><h4 id="one-two-three-css">One, two, three, CSS!</h4><p>The quickest way to get things up and running is by using the Chartist.js CSS files. The CSS is compiled from the Sass files with the default class names which are also configured in the JavaScript library. You can then override the default styles or modify the CSS file, however, for customization it's recommended to use the Sass version of Chartist.js.<pre id="simple-start"><code class="html"><!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<title>My first Chartist Tests</title>
|
||
<link rel="stylesheet"
|
||
href="bower_components/chartist/dist/chartist.min.css">
|
||
</head>
|
||
<body>
|
||
<!-- Site content goes here !-->
|
||
<script src="bower_components/chartist/dist/chartist.min.js"></script>
|
||
</body>
|
||
</html>
|
||
</code></pre><h5 id="use-a-cdn-alternatively">Use a CDN alternatively</h5><p>If you'd like to get started even faster you can also use a CDN to load Chartist.js. The awesome people at jsDelivr provide a fantastic job in hosting libraries from over 42 POP Locations around the world! They always update Chartist.js to the latest version immediately and they do all that for free! Check out the <a href="http://www.jsdelivr.com/" target="_blank">jsDeliver website</a> for more information.</p><button class="button" data-toggle-visible="#simple-start-cdn">Show CDN Code</button><pre id="simple-start-cdn"><code class="html"><!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<link rel="stylesheet" href="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.css">
|
||
<script src="//cdn.jsdelivr.net/chartist.js/latest/chartist.min.js"></script>
|
||
</head>
|
||
</html></code></pre></div><div class="sub-section"><h4 id="the-sass-way">The Sass way</h4><p>If you like to customize your charts you can either remove the CSS fully and write your own selectors using the Chartist.js Sass mixins or you just use the Chartist.js Sass settings file to customize the look and feel of your charts.<p>Styling inline SVG with CSS is a breeze and you should also consider writing your own selectors for your charts and using the Sass mixins. You can read more about using the Sass mixins in the <a href="#advanced">advanced</a> section.<p>To customize the style of your charts using the Sass settings file you should copy the settings file to your own Sass folder.<pre><code class="bash">cp bower_components/chartist/dist/scss/settings/_chartist-settings.scss styles</code></pre><p>Then just import your copy of the settings file before you import the chartist.scss file and change the settings in your copy as desired.<pre id="custom-include"><code class="scss">@import "_my-chartist-settings.scss";
|
||
@import "chartist/dist/scss/chartist.scss";
|
||
</code></pre><h5 id="default-settings">Default settings</h5><p>The settings file contains all relevant variables used in the mixins and while generating the default classes. You can simply change the settings for styling your own charts. If you want to override certain settings based on state or pseeudo selectors, you can use the individual mixins to only override specific styles.<p>Take a look at the settings to see how to customize the style of the defalt Chartist.js class selectors.</p><button class="button" data-toggle-visible="#default-sass-settings">Show default settings</button><pre id="default-sass-settings"><code class="scss">// Scales for responsive SVG containers
|
||
$ct-scales: ((1), (15/16), (8/9), (5/6), (4/5), (3/4), (2/3), (5/8), (1/1.618), (3/5), (9/16), (8/15), (1/2), (2/5), (3/8), (1/3), (1/4)) !default;
|
||
$ct-scales-names: (ct-square, ct-minor-second, ct-major-second, ct-minor-third, ct-major-third, ct-perfect-fourth, ct-perfect-fifth, ct-minor-sixth, ct-golden-section, ct-major-sixth, ct-minor-seventh, ct-major-seventh, ct-octave, ct-major-tenth, ct-major-eleventh, ct-major-twelfth, ct-double-octave) !default;
|
||
|
||
// Class names to be used when generating CSS
|
||
$ct-class-chart: ct-chart !default;
|
||
$ct-class-chart-line: ct-chart-line !default;
|
||
$ct-class-chart-bar: ct-chart-bar !default;
|
||
$ct-class-horizontal-bars: ct-horizontal-bars !default;
|
||
$ct-class-chart-pie: ct-chart-pie !default;
|
||
$ct-class-chart-donut: ct-chart-donut !default;
|
||
$ct-class-label: ct-label !default;
|
||
$ct-class-series: ct-series !default;
|
||
$ct-class-line: ct-line !default;
|
||
$ct-class-point: ct-point !default;
|
||
$ct-class-area: ct-area !default;
|
||
$ct-class-bar: ct-bar !default;
|
||
$ct-class-slice-pie: ct-slice-pie !default;
|
||
$ct-class-slice-donut: ct-slice-donut !default;
|
||
$ct-class-slice-donut-solid: ct-slice-donut-solid !default;
|
||
$ct-class-grid: ct-grid !default;
|
||
$ct-class-grid-background: ct-grid-background !default;
|
||
$ct-class-vertical: ct-vertical !default;
|
||
$ct-class-horizontal: ct-horizontal !default;
|
||
$ct-class-start: ct-start !default;
|
||
$ct-class-end: ct-end !default;
|
||
|
||
// Container ratio
|
||
$ct-container-ratio: (1/1.618) !default;
|
||
|
||
// Text styles for labels
|
||
$ct-text-color: rgba(0, 0, 0, 0.4) !default;
|
||
$ct-text-size: 0.75rem !default;
|
||
$ct-text-align: flex-start !default;
|
||
$ct-text-justify: flex-start !default;
|
||
$ct-text-line-height: 1;
|
||
|
||
// Grid styles
|
||
$ct-grid-color: rgba(0, 0, 0, 0.2) !default;
|
||
$ct-grid-dasharray: 2px !default;
|
||
$ct-grid-width: 1px !default;
|
||
$ct-grid-background-fill: none !default;
|
||
|
||
// Line chart properties
|
||
$ct-line-width: 4px !default;
|
||
$ct-line-dasharray: false !default;
|
||
$ct-point-size: 10px !default;
|
||
// Line chart point, can be either round or square
|
||
$ct-point-shape: round !default;
|
||
// Area fill transparency between 0 and 1
|
||
$ct-area-opacity: 0.1 !default;
|
||
|
||
// Bar chart bar width
|
||
$ct-bar-width: 10px !default;
|
||
|
||
// Donut width (If donut width is to big it can cause issues where the shape gets distorted)
|
||
$ct-donut-width: 60px !default;
|
||
|
||
// If set to true it will include the default classes and generate CSS output. If you're planning to use the mixins you
|
||
// should set this property to false
|
||
$ct-include-classes: true !default;
|
||
|
||
// If this is set to true the CSS will contain colored series. You can extend or change the color with the
|
||
// properties below
|
||
$ct-include-colored-series: $ct-include-classes !default;
|
||
|
||
// If set to true this will include all responsive container variations using the scales defined at the top of the script
|
||
$ct-include-alternative-responsive-containers: $ct-include-classes !default;
|
||
|
||
// Series names and colors. This can be extended or customized as desired. Just add more series and colors.
|
||
$ct-series-names: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) !default;
|
||
$ct-series-colors: (
|
||
#d70206,
|
||
#f05b4f,
|
||
#f4c63d,
|
||
#d17905,
|
||
#453d3f,
|
||
#59922b,
|
||
#0544d3,
|
||
#6b0392,
|
||
#f05b4f,
|
||
#dda458,
|
||
#eacf7d,
|
||
#86797d,
|
||
#b2c326,
|
||
#6188e2,
|
||
#a748ca
|
||
) !default;
|
||
</code></pre></div></div></section><section class="documentation-section full"><header><h3 id="create-your-first-chart">Create your first chart</h3></header><div class="content"><p>In this section you'll go through a simple example of how to use Chartist.js in your project. You'll learn the default stages you go through when creating and customizing a basic line chart. If you'd like to see more in depth and advanced examples you should check out the <a href="#advanced">advanced</a> section or the <a href="examples.html">examples page</a>.<div class="sub-section"><h4 id="as-simple-as-it-can-get">As simple as it can get</h4><p>Chartist provides you a very simple API to get started, however, while trying to follow the best practice of relying on standards and clear separation of concerns it sometimes needs a small mind shift in order to understand how things are meant to work within Chartist. Instead of specifying your colors, line width and other style related things in the JavaScript API, you'll need to use CSS in order to control your appearance.<div class="sub-section"><h5 id="creating-a-chart-using-aspect-ratios">Creating a chart using aspect ratios</h5><p>Because of the nature of responsive design it's important to understand that blocks in design like images, videos and similar content need to be able to scale and adapt to the media. In order for an element to scale, you need to rely on a certain aspect ratios (like 4:3, 3:2, 16:9 etc.) rather than specifying a fixed width and height.<p>To designers this Idea is absolutely not new, but to developers this might be at first. However, when a designer talks to a developer about the images being 320x240 on this page and 300x200 on that element, he actually just translated his idea of using 4:3 and 3:2 images into pixels.<p>With Chartist you can specify those ratios directly on containers without the need to calculate any fixed dimensions. In order to create a chart that is using the aspect ratio of a golden section you can just add the class .ct-golden-section to your container where you initialize Chartist.<p>Here is a list of all available container ratios (If using the Sass version of Chartist you can also easily add others):</p><a href="#" class="button" data-toggle-visible="#container-aspect-ratio-classes">Show available aspect ratios</a><table id="container-aspect-ratio-classes" role="presentation"><thead><tr><th>Container class<th>Ratio<tbody><tr><td>.ct-square<td>1<tr><td>.ct-minor-second<td>15:16<tr><td>.ct-major-second<td>8:9<tr><td>.ct-minor-third<td>5:6<tr><td>.ct-major-third<td>4:5<tr><td>.ct-perfect-fourth<td>3:4<tr><td>.ct-perfect-fifth<td>2:3<tr><td>.ct-minor-sixth<td>5:8<tr><td>.ct-golden-section<td>1:1.618<tr><td>.ct-major-sixth<td>3:5<tr><td>.ct-minor-seventh<td>9:16<tr><td>.ct-major-seventh<td>8:15<tr><td>.ct-octave<td>1:2<tr><td>.ct-major-tenth<td>2:5<tr><td>.ct-major-eleventh<td>3:8<tr><td>.ct-major-twelfth<td>1:3<tr><td>.ct-double-octave<td>1:4</table><p>Use the following HTML code to specify a container with one of the above aspect ratio classes.<pre><code class="html"><div class="ct-chart ct-perfect-fourth"></div></code></pre><p>When using a fixed aspect ratio container you can then simply initialize your chart without specifying any width or height in the options.<pre id="simple-start-aspect-ratio-chart"><code class="js">var data = {
|
||
// A labels array that can contain any sort of values
|
||
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
|
||
// Our series array that contains series objects or in this case series data arrays
|
||
series: [
|
||
[5, 2, 4, 2, 0]
|
||
]
|
||
};
|
||
|
||
// Create a new line chart object where as first parameter we pass in a selector
|
||
// that is resolving to our chart container element. The Second parameter
|
||
// is the actual data object.
|
||
new Chartist.Line('.ct-chart', data);</code></pre></div><div class="sub-section"><h5 id="creating-a-chart-with-fixed-dimensions">Creating a chart with fixed dimensions</h5><p>In order to create a simple line chart with fixed width and height you only need to have a container element and initialize Chartist.js on it. Give the container the class ct-chart so that it will get the default styles (if you don't use your own classes).<pre id="simple-start-fixed-chart"><code class="js">var data = {
|
||
// A labels array that can contain any sort of values
|
||
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'],
|
||
// Our series array that contains series objects or in this case series data arrays
|
||
series: [
|
||
[5, 2, 4, 2, 0]
|
||
]
|
||
};
|
||
|
||
// As options we currently only set a static size of 300x200 px. We can also omit this and use aspect ratio containers
|
||
// as you saw in the previous example
|
||
var options = {
|
||
width: 300,
|
||
height: 200
|
||
};
|
||
|
||
// Create a new line chart object where as first parameter we pass in a selector
|
||
// that is resolving to our chart container element. The Second parameter
|
||
// is the actual data object. As a third parameter we pass in our custom options.
|
||
new Chartist.Line('.ct-chart', data, options);
|
||
</code></pre></div><div class="sub-section"><h5 id="more-than-one-chart-on-my-page">More than one chart on my page?</h5><p>The example above uses the chartist default class to select the element where the chart should be created. This class is important for applying the right styles in the CSS of Chartist. If you need to create individual charts on one page, you should use IDs to initialize them separately.<pre id="two-charts"><code class="html"><div class="ct-chart ct-golden-section" id="chart1"></div>
|
||
<div class="ct-chart ct-golden-section" id="chart2"></div>
|
||
|
||
<script>
|
||
// Initialize a Line chart in the container with the ID chart1
|
||
new Chartist.Line('#chart1', {
|
||
labels: [1, 2, 3, 4],
|
||
series: [[100, 120, 180, 200]]
|
||
});
|
||
|
||
// Initialize a Line chart in the container with the ID chart2
|
||
new Chartist.Bar('#chart2', {
|
||
labels: [1, 2, 3, 4],
|
||
series: [[5, 2, 8, 3]]
|
||
});
|
||
</script>
|
||
</code></pre></div></div><div class="sub-section"><h4 id="the-configuration-of-your-chart">The configuration of your chart</h4><p>Chartist.js is built very flexible and almost everything within your charts can be configured. In the default settings (that you can check in the <a href="api-documentation.html">API Documentation</a>) you'll get some predefined defaults applied to your charts.<p>You can always override the default settings of your charts by passing in a configuration object at creation time.<div id="simple-configuration-chart" class="ct-chart ct-golden-section" data-example="Ly8gT3VyIGxhYmVscyBhbmQgdGhyZWUgZGF0YSBzZXJpZXMKdmFyIGRhdGEgPSB7CiAgbGFiZWxzOiBbJ1dlZWsxJywgJ1dlZWsyJywgJ1dlZWszJywgJ1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N0aW9uKHZhbHVlKSB7CiAgICAgIHJldHVybiAnJCcgKyB2YWx1ZSArICdtJzsKICAgIH0KICB9Cn07CgovLyBBbGwgeW91IG5lZWQgdG8gZG8gaXMgcGFzcyB5b3VyIGNvbmZpZ3VyYXRpb24gYXMgdGhpcmQgcGFyYW1ldGVyIHRvIHRoZSBjaGFydCBmdW5jdGlvbgpuZXcgQ2hhcnRpc3QuTGluZSgnLmN0LWNoYXJ0JywgZGF0YSwgb3B0aW9ucyk7Cg=="></div><button class="button" data-toggle-visible="#simple-configuration-chart-code">Show code and comments</button><pre id="simple-configuration-chart-code"><code class="js">// Our labels and three data series
|
||
var data = {
|
||
labels: ['Week1', 'Week2', 'Week3', 'Week4', 'Week5', 'Week6'],
|
||
series: [
|
||
[5, 4, 3, 7, 5, 10],
|
||
[3, 2, 9, 5, 4, 6],
|
||
[2, 1, -3, -4, -2, 0]
|
||
]
|
||
};
|
||
|
||
// We are setting a few options for our chart and override the defaults
|
||
var options = {
|
||
// Don't draw the line chart points
|
||
showPoint: false,
|
||
// Disable line smoothing
|
||
lineSmooth: false,
|
||
// X-Axis specific configuration
|
||
axisX: {
|
||
// We can disable the grid for this axis
|
||
showGrid: false,
|
||
// and also don't show the label
|
||
showLabel: false
|
||
},
|
||
// Y-Axis specific configuration
|
||
axisY: {
|
||
// Lets offset the chart a bit from the labels
|
||
offset: 60,
|
||
// The label interpolation function enables you to modify the values
|
||
// used for the labels on each axis. Here we are converting the
|
||
// values into million pound.
|
||
labelInterpolationFnc: function(value) {
|
||
return '$' + value + 'm';
|
||
}
|
||
}
|
||
};
|
||
|
||
// All you need to do is pass your configuration as third parameter to the chart function
|
||
new Chartist.Line('.ct-chart', data, options);
|
||
</code></pre></div><div class="sub-section"><h4 id="responsive-sugar-topping">Responsive sugar topping</h4><p>Responsive web design is all based on <a href="https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries" taget="_blank">media queries</a> as you are probably already aware. Media queries are great and they help you to define media related conditions that you can use to apply different styles for different media.<p>Sometimes it's also required to have different behavior on certain media and it's possible that a specific component of your web site should behave in an other way on a small media than on a large one. Luckily there is window.matchMedia in your browser that comes to the rescue. With matchMedia it's possible to let your javascript react differently based on CSS3 media queries.<h5 id="responsive-setting-overrides">Responsive setting overrides</h5><p>Configuring different chart behavior for various media is made simple with an override mechanism. The priority of the override mechanism is based on order of specification of the matching media queries.<p>The following example uses different label interpolations (to save some space) on small media as well as different spacing between the bars of the bar chart series. Resize your browser window to see the effect.<div id="example-simple-bar" class="ct-chart ct-golden-section" data-example="dmFyIGRhdGEgPSB7CiAgbGFiZWxzOiBbJ0phbicsICdGZWInLCAnTWFyJywgJ0FwcicsICdNYWknLCAnSnVuJywgJ0p1bCcsICdBdWcnLCAnU2VwJywgJ09jdCcsICdOb3YnLCAnRGVjJ10sCiAgICBzZXJpZXM6IFsKICAgIFs1LCA0LCAzLCA3LCA1LCAxMCwgMywgNCwgOCwgMTAsIDYsIDhdLAogICAgWzMsIDIsIDksIDUsIDQsIDYsIDQsIDYsIDcsIDgsIDcsIDRdCiAgXQp9OwoKdmFyIG9wdGlvbnMgPSB7CiAgc2VyaWVzQmFyRGlzdGFuY2U6IDE1Cn07Cgp2YXIgcmVzcG9uc2l2ZU9wdGlvbnMgPSBbCiAgWydzY3JlZW4gYW5kIChtaW4td2lkdGg6IDY0MXB4KSBhbmQgKG1heC13aWR0aDogMTAyNHB4KScsIHsKICAgIHNlcmllc0JhckRpc3RhbmNlOiAxMCwKICAgIGF4aXNYOiB7CiAgICAgIGxhYmVsSW50ZXJwb2xhdGlvbkZuYzogZnVuY3Rpb24gKHZhbHVlKSB7CiAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgICB9CiAgICB9CiAgfV0sCiAgWydzY3JlZW4gYW5kIChtYXgtd2lkdGg6IDY0MHB4KScsIHsKICAgIHNlcmllc0JhckRpc3RhbmNlOiA1LAogICAgYXhpc1g6IHsKICAgICAgbGFiZWxJbnRlcnBvbGF0aW9uRm5jOiBmdW5jdGlvbiAodmFsdWUpIHsKICAgICAgICByZXR1cm4gdmFsdWVbMF07CiAgICAgIH0KICAgIH0KICB9XQpdOwoKbmV3IENoYXJ0aXN0LkJhcignLmN0LWNoYXJ0JywgZGF0YSwgb3B0aW9ucywgcmVzcG9uc2l2ZU9wdGlvbnMpOw=="></div><button class="button" data-toggle-visible="#example-simple-bar-code">Show code and comments</button><pre id="example-simple-bar-code"><code class="js">var data = {
|
||
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
||
series: [
|
||
[5, 4, 3, 7, 5, 10, 3, 4, 8, 10, 6, 8],
|
||
[3, 2, 9, 5, 4, 6, 4, 6, 7, 8, 7, 4]
|
||
]
|
||
};
|
||
|
||
var options = {
|
||
seriesBarDistance: 15
|
||
};
|
||
|
||
var responsiveOptions = [
|
||
['screen and (min-width: 641px) and (max-width: 1024px)', {
|
||
seriesBarDistance: 10,
|
||
axisX: {
|
||
labelInterpolationFnc: function (value) {
|
||
return value;
|
||
}
|
||
}
|
||
}],
|
||
['screen and (max-width: 640px)', {
|
||
seriesBarDistance: 5,
|
||
axisX: {
|
||
labelInterpolationFnc: function (value) {
|
||
return value[0];
|
||
}
|
||
}
|
||
}]
|
||
];
|
||
|
||
new Chartist.Bar('.ct-chart', data, options, responsiveOptions);</code></pre><div class="hint hint-cross-browser"><div class="title">Cross-browser support</div><div class="content">For IE9 you need to use a matchMedia polyfill. You should take a look at <a href="https://github.com/paulirish/matchMedia.js/">Paul Irish's matchMedia polyfill</a>. Make sure you include matchMedia.js as well as matchMedia.addListener.js as always both are needed to polyfill the full specification of window.matchMedia.</div></div></div><div class="sub-section"><h4 id="different-configuration-for-different-series">Different configuration for different series</h4><p>Chartist also allows you to add specific configuration overrides for your series. This is useful if you want to combine different looks for your series on the same chart.<p>You can even take this one step further by again overriding your series configuration in some responsive settings overrides. This sounds complicated but it actually is very simple. Check the example code with inline comments below to see how easy it is.<div id="example-line-series-override" class="ct-chart ct-golden-section" data-example="dmFyIGNoYXJ0ID0gbmV3IENoYXJ0aXN0LkxpbmUoJy5jdC1jaGFydCcsIHsKICBsYWJlbHM6IFsnMScsICcyJywgJzMnLCAnNCcsICc1JywgJzYnLCAnNycsICc4J10sCiAgLy8gTmFtaW5nIHRoZSBzZXJpZXMgd2l0aCB0aGUgc2VyaWVzIG9iamVjdCBhcnJheSBub3RhdGlvbgogIHNlcmllczogW3sKICAgIG5hbWU6ICdzZXJpZXMtMScsCiAgICBkYXRhOiBbNSwgMiwgLTQsIDIsIDAsIC0yLCA1LCAtM10KICB9LCB7CiAgICBuYW1lOiAnc2VyaWVzLTInLAogICAgZGF0YTogWzQsIDMsIDUsIDMsIDEsIDMsIDYsIDRdCiAgfSwgewogICAgbmFtZTogJ3Nlcmllcy0zJywKICAgIGRhdGE6IFsyLCA0LCAzLCAxLCA0LCA1LCAzLCAyXQogIH1dCn0sIHsKICBmdWxsV2lkdGg6IHRydWUsCiAgLy8gV2l0aGluIHRoZSBzZXJpZXMgb3B0aW9ucyB5b3UgY2FuIHVzZSB0aGUgc2VyaWVzIG5hbWVzCiAgLy8gdG8gc3BlY2lmeSBjb25maWd1cmF0aW9uIHRoYXQgd2lsbCBvbmx5IGJlIHVzZWQgZm9yIHRoZQogIC8vIHNwZWNpZmljIHNlcmllcy4KICBzZXJpZXM6IHsKICAgICdzZXJpZXMtMSc6IHsKICAgICAgbGluZVNtb290aDogQ2hhcnRpc3QuSW50ZXJwb2xhdGlvbi5zdGVwKCkKICAgIH0sCiAgICAnc2VyaWVzLTInOiB7CiAgICAgIGxpbmVTbW9vdGg6IENoYXJ0aXN0LkludGVycG9sYXRpb24uc2ltcGxlKCksCiAgICAgIHNob3dBcmVhOiB0cnVlCiAgICB9LAogICAgJ3Nlcmllcy0zJzogewogICAgICBzaG93UG9pbnQ6IGZhbHNlCiAgICB9CiAgfQp9LCBbCiAgLy8gWW91IGNhbiBldmVuIHVzZSByZXNwb25zaXZlIGNvbmZpZ3VyYXRpb24gb3ZlcnJpZGVzIHRvCiAgLy8gY3VzdG9taXplIHlvdXIgc2VyaWVzIGNvbmZpZ3VyYXRpb24gZXZlbiBmdXJ0aGVyIQogIFsnc2NyZWVuIGFuZCAobWF4LXdpZHRoOiAzMjBweCknLCB7CiAgICBzZXJpZXM6IHsKICAgICAgJ3Nlcmllcy0xJzogewogICAgICAgIGxpbmVTbW9vdGg6IENoYXJ0aXN0LkludGVycG9sYXRpb24ubm9uZSgpCiAgICAgIH0sCiAgICAgICdzZXJpZXMtMic6IHsKICAgICAgICBsaW5lU21vb3RoOiBDaGFydGlzdC5JbnRlcnBvbGF0aW9uLm5vbmUoKSwKICAgICAgICBzaG93QXJlYTogZmFsc2UKICAgICAgfSwKICAgICAgJ3Nlcmllcy0zJzogewogICAgICAgIGxpbmVTbW9vdGg6IENoYXJ0aXN0LkludGVycG9sYXRpb24ubm9uZSgpLAogICAgICAgIHNob3dQb2ludDogdHJ1ZQogICAgICB9CiAgICB9CiAgfV0KXSk7Cg=="></div><button class="button" data-toggle-visible="#example-line-series-override-code">Show code</button><pre id="example-line-series-override-code"><code class="js">var chart = new Chartist.Line('.ct-chart', {
|
||
labels: ['1', '2', '3', '4', '5', '6', '7', '8'],
|
||
// Naming the series with the series object array notation
|
||
series: [{
|
||
name: 'series-1',
|
||
data: [5, 2, -4, 2, 0, -2, 5, -3]
|
||
}, {
|
||
name: 'series-2',
|
||
data: [4, 3, 5, 3, 1, 3, 6, 4]
|
||
}, {
|
||
name: 'series-3',
|
||
data: [2, 4, 3, 1, 4, 5, 3, 2]
|
||
}]
|
||
}, {
|
||
fullWidth: true,
|
||
// Within the series options you can use the series names
|
||
// to specify configuration that will only be used for the
|
||
// specific series.
|
||
series: {
|
||
'series-1': {
|
||
lineSmooth: Chartist.Interpolation.step()
|
||
},
|
||
'series-2': {
|
||
lineSmooth: Chartist.Interpolation.simple(),
|
||
showArea: true
|
||
},
|
||
'series-3': {
|
||
showPoint: false
|
||
}
|
||
}
|
||
}, [
|
||
// You can even use responsive configuration overrides to
|
||
// customize your series configuration even further!
|
||
['screen and (max-width: 320px)', {
|
||
series: {
|
||
'series-1': {
|
||
lineSmooth: Chartist.Interpolation.none()
|
||
},
|
||
'series-2': {
|
||
lineSmooth: Chartist.Interpolation.none(),
|
||
showArea: false
|
||
},
|
||
'series-3': {
|
||
lineSmooth: Chartist.Interpolation.none(),
|
||
showPoint: true
|
||
}
|
||
}
|
||
}]
|
||
]);
|
||
</code></pre></div></div></section><section class="documentation-section full"><header><h3 id="styling-your-chart">Styling your chart</h3></header><div class="content"><p>You should always use the power of CSS to make your data pop into your visitors eyes. I know I’m telling this over and over but it’s all about a clean separation of concerns. In this chapter you’ll find some useful information on how to style your charts with CSS.<div class="sub-section"><h4 id="customizing-the-default-css">Customizing the default CSS</h4><p>Chartist comes with a highly customizable Sass file that allows you to customize all sorts of appearance relevant things on your charts including colours used for series, line styles, thickness and other properties. If you have the advantage of having a Sass build process at your disposal, I highly recommend you to use the Sass version of Chartist instead of the already prebuilt CSS. For more information on how to use the Sass version please <a href="#the-sass-way">check out the Sass way of Chartist</a>.<p>Chartist generates predefined classes for series by default. Those class names are alphabetically ordered and always start with <code>ct-series-a</code>, where the letter a will be iterated with each series count (a, b, c, d etc.). To address a specific series in styling, you’ll need to create some styles for the corresponding series class name.<p>Here is a list of selectors from the different chart types with some comments to explain what properties can be used to influence the visual style of your charts.<div class="sub-section"><h5 id="line-chart">Line chart</h5><pre id="custom-style-line-chart"><code class="css">/* Use this selector to override the line style on a given series */
|
||
.ct-series-a .ct-line {
|
||
/* Set the colour of this series line */
|
||
stroke: red;
|
||
/* Control the thikness of your lines */
|
||
stroke-width: 5px;
|
||
/* Create a dashed line with a pattern */
|
||
stroke-dasharray: 10px 20px;
|
||
}
|
||
|
||
/* This selector overrides the points style on line charts. Points on line charts are actually just very short strokes. This allows you to customize even the point size in CSS */
|
||
.ct-series-a .ct-point {
|
||
/* Colour of your points */
|
||
stroke: red;
|
||
/* Size of your points */
|
||
stroke-width: 20px;
|
||
/* Make your points appear as squares */
|
||
stroke-linecap: square;
|
||
}
|
||
</code></pre></div><div class="sub-section"><h5 id="bar-chart">Bar chart</h5><pre id="custom-style-bar-chart"><code class="css">/* Use this selector to override bar styles on bar charts. Bars are also strokes so you have maximum freedom in styling them. */
|
||
.ct-series-a .ct-bar {
|
||
/* Colour of your bars */
|
||
stroke: red;
|
||
/* The width of your bars */
|
||
stroke-width: 20px;
|
||
/* Yes! Dashed bars! */
|
||
stroke-dasharray: 20px;
|
||
/* Maybe you like round corners on your bars? */
|
||
stroke-linecap: round;
|
||
}
|
||
</code></pre></div><div class="sub-section"><h5 id="pie-chart">Pie chart</h5><pre id="custom-style-pie-chart"><code class="css">/* Pie charts consist of solid slices where you can use this selector to override the default style. */
|
||
.ct-series-a .ct-slice-pie {
|
||
/* fill of the pie slieces */
|
||
fill: hsl(120, 40%, 60%);
|
||
/* give your pie slices some outline or separate them visually by using the background color here */
|
||
stroke: white;
|
||
/* outline width */
|
||
stroke-width: 4px;
|
||
}
|
||
</code></pre></div><div class="sub-section"><h5 id="donut-chart">Donut chart</h5><pre id="custom-style-donut-chart"><code class="css">/* Donut charts get built from Pie charts but with a fundamentally difference in the drawing approach. The donut is drawn using arc strokes for maximum freedom in styling */
|
||
.ct-series-a .ct-slice-donut {
|
||
/* give the donut slice a custom colour */
|
||
stroke: blue;
|
||
/* customize stroke width of the donut slices in CSS. Note that this property is already set in JavaScript and label positioning also relies on this. In the right situation though it can be very useful to style this property. You need to use !important to override the style attribute */
|
||
stroke-width: 5px !important;
|
||
/* create modern looking rounded donut charts */
|
||
stroke-linecap: round;
|
||
}
|
||
</code></pre></div></div><div class="sub-section"><h4 id="colour-up-your-charts">Colour up your charts</h4><p>Colour is a core attribute of appearance and as you already know, we believe in strong separation of concerns in web development. Therefore, Chartist does not include any options within the JavaScript API to control colour of your charts.<p>This might first seem very inconvenient, but you’ll agree that it’s the right choice once you need to change some colours in your web project where you’d need to go through some nasty find-and-replace adventures in your JavaScript files to fix some colour mismatches.<p>The prebuilt CSS version of Chartist ships with 15 default colours that will be applied to your chart series elements. If you just want to override some of these colours I recommend you use the information found in <a href="#customizing-the-default-css">how to customize the default CSS of Chartist</a>.<p>The following example illustrates how you’d override the colours of your line chart line and point elements, within the two first sieries (ct-series-a and ct-series-b).<pre id="colour-override-line-chart"><code class="css">.ct-series-a .ct-line,
|
||
.ct-series-a .ct-point {
|
||
stroke: blue;
|
||
}
|
||
|
||
.ct-series-b .ct-line,
|
||
.ct-series-b .ct-point {
|
||
stroke: green;
|
||
}
|
||
</code></pre><p>Note that on SVG elements there are two CSS properties for colourization. For strokes you should use the <code>stroke</code> property and assign a CSS colour value. For fill areas you can use the <code>fill</code> property. More information can be found in the above topics.<div class="sub-section"><h5 id="dynamic-colouring">Dynamic colouring</h5><p>Often, predefined classes which can be used to colour your charts are fine but sometimes CSS is not flexible enough to control all facets of dynamic appearance. While we could build semantic classes like level1, level2, level3 and so on, we could then assign a class dynamically, but still we’d need to rely on discrete values defined in CSS. One lack of CSS today is that it does not incorporate dynamic values like mouse position or placeholder variables that can be linked to JavaScript.<p>So, how do you go about your heat map chart or dynamically calculated line chart strokes based on your data?<p>Chartist offers you a powerful tool for such kind of chart manipulations. The intrusive event pipeline of Chartist allows you to hook into a <code>draw</code> event that allows you to modify all your charts elements on the go while they’re drawn.<p>The following live code example shows you how to make a dynamically coloured chart based on some data. Please go ahead and play around with the example, that’s what live coding is for! For more information on how to use the <code>Chartist.Svg</code> API, please <a href="http://gionkunz.github.io/chartist-js/api-documentation.html#module-chartistsvg">check the API documentation</a>.</div><section class="live-example" id="example-dynamic-colours" data-live-example="dmFyIGNvdW50ID0gNDU7CnZhciBtYXggPSAxMDA7CgovLyBDcmVhdGluZyBhIGJhciBjaGFydCB3aXRoIG5vIGxhYmVscyBhbmQgYSBzZXJpZXMgYXJyYXkgd2l0aCBvbmUgc2VyaWVzLiBGb3IgdGhlIHNlcmllc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CBnb3QgZHJhd24KICAgIGNvbnRleHQuZWxlbWVudC5hdHRyKHsKICAgICAgLy8gTm93IHdlIHNldCB0aGUgc3R5bGUgYXR0cmlidXRlIG9uIG91ciBiYXIgdG8gb3ZlcnJpZGUgdGhlIGRlZmF1bHQgY29sb3Igb2YgdGhlIGJhci4gQnkgdXNpbmcgYSBIU0wgY29sb3VyIHdlIGNhbiBlYXNpbHkgc2V0IHRoZSBodWUgb2YgdGhlIGNvbG91ciBkeW5hbWljYWxseSB3aGlsZSBrZWVwaW5nIHRoZSBzYW1lIHNhdHVyYXRpb24gYW5kIGxpZ2h0bmVzcy4gRnJvbSB0aGUgY29udGV4dCB3ZSBjYW4gYWxzbyBnZXQgdGhlIGN1cnJlbnQgdmFsdWUgb2YgdGhlIGJhci4gV2UgdXNlIHRoYXQgdmFsdWUgdG8gY2FsY3VsYXRlIGEgaHVlIGJldHdlZW4gMCBhbmQgMTAwIGRlZ3JlZS4gVGhpcyB3aWxsIG1ha2Ugb3VyIGJhcnMgYXBwZWFyIGdyZWVuIHdoZW4gY2xvc2UgdG8gdGhlIG1heGltdW0gYW5kIHJlZCB3aGVuIGNsb3NlIHRvIHplcm8uCiAgICAgIHN0eWxlOiAnc3Ryb2tlOiBoc2woJyArIE1hdGguZmxvb3IoQ2hhcnRpc3QuZ2V0TXVsdGlWYWx1ZShjb250ZXh0LnZhbHVlKSAvIG1heCAqIDEwMCkgKyAnLCA1MCUsIDUwJSk7JwogICAgfSk7CiAgfQp9KTsK"><header class="live-example-header"><h5>Using draw events to modify chart elements</h5></header><div class="chart"><div class="ct-chart ct-golden-section"></div></div><aside class="live-code"><div class="introduction"><p class="text">By using the intrusive event pipeline of Chartist, you can easily change the behaviour of your charts in a consistent and convenient way.</p><button class="edit-button">Edit Example</button></div><div class="editor-area"><textarea class="code-editor"></textarea><button class="close-edit-button">Close Editor</button></div></aside></section></div></div></section><section class="documentation-section full"><header><h3 id="advanced">Advanced</h3></header><div class="content"><p>In the following chapter you'll find some advanced usage examples that might be of interest for you. Chartist is very flexible because it relies on standard technology. This also means that you will need to implement certain things yourself. This topic should cover some of these use-cases and give you some basic idea why and how to implement certain functionality.<div class="sub-section"><h4 id="animations-using-chartistsvg">Animations using Chartist.Svg</h4><p>Usually we recommend using CSS for animations as it's closer to a clean separation of concerns. However, sometimes you would want to animate SVG properties that are not available in CSS to animate. For this purpose we have added a simple but powerful animation API that allows you to create SMIL animations in a more convenient way.<p>In combination with the draw events of Chartist the animations are a very powerful and flexible tool. You can intercept almost any step in chartist and if there is an SVG element involved you can animate it using <a href="api-documentation.html#chartistsvg-function-animate">Chartist.Svg.animate</a>.<p>The following simple example shows you how to created a delayed fade in effect for the a scatter chart. You can also edit the example to play around with the settings.<section class="live-example" id="example-simple-svg-animation" data-live-example="dmFyIGNoYXJ0ID0gbmV3IENoYXJ0aXN0LkxpbmUoJy5jdC1jaGFydCcsIHsKICBsYWJlbHM6IFsnMScsICcyJywgJzMnLCAnNCcsICc1JywgJzYnLCAnNycsICc4JywgJzknLCAnMTAnLCAnMTEnLCAnMTInXSwKICBzZXJpZXM6IFsKICAgIFsxMiwgNCwgMiwgOCwgNSwgNCwgNiwgMiwgMywgMywgNCwgNl0sCiAgICBbNCwgOCwgOSwgMywgNywgMiwgMTAsIDUsIDgsIDEsIDcsIDEwXQogIF0KfSwgewogIGxvdzogMCwKICBzaG93TGluZTogZmFsc2UsCiAgYXhpc1g6IHsKICAgIHNob3dMYWJlbDogZmFsc2UsCiAgICBvZmZzZXQ6IDAKICB9LAogIGF4aXNZOiB7CiAgICBzaG93TGFiZWw6IGZhbHNlLAogICAgb2Zmc2V0OiAwCiAgfQp9KTsKCi8vIExldCdzIHB1dCBhIHNlcXVlbmNlIG51bWJlciBhc2lkZSBzbyB3ZSBjYW4gdXNlIGl0IGluIHRoZSBldmVudCBjYWxsYmFja3MKdmFyIHNlcSA9IDA7CgovLyBPbmNlIHRoZSBjaGFydCBpcyBmdWxseSBjcmVhdGVkIHdlIHJlc2V0IHR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VzZSBlYXNpbmcgZnVuY3Rpb25zIGZyb20gQ2hhcnRpc3QuU3ZnLkVhc2luZyBkaXJlY3RseQogICAgICAgIGVhc2luZzogQ2hhcnRpc3QuU3ZnLkVhc2luZy5lYXNlT3V0UXVhcnQKICAgICAgfQogICAgfSk7CiAgfQp9KTsKCi8vIEZvciB0aGUgc2FrZSBvZiB0aGUgZXhhbXBsZSB3ZSB1cGRhdGUgdGhlIGNoYXJ0IGV2ZXJ5IHRpbWUgaXQncyBjcmVhdGVkIHdpdGggYSBkZWxheSBvZiA4IHNlY29uZHMKY2hhcnQub24oJ2NyZWF0ZWQnLCBmdW5jdGlvbigpIHsKICBpZih3aW5kb3cuX19hbmltMDk4NzQzMjU5ODcyMykgewogICAgY2xlYXJUaW1lb3V0KHdpbmRvdy5fX2FuaW0wOTg3NDMyNTk4NzIzKTsKICAgIHdpbmRvdy5fX2FuaW0wOTg3NDMyNTk4NzIzID0gbnVsbDsKICB9CiAgd2luZG93Ll9fYW5pbTA5ODc0MzI1OTg3MjMgPSBzZXRUaW1lb3V0KGNoYXJ0LnVwZGF0ZS5iaW5kKGNoYXJ0KSwgODAwMCk7Cn0pOwoK"><header class="live-example-header"><h5>Some SVG Animations can only be done with SMIL</h5></header><div class="chart"><div class="ct-chart ct-golden-section"></div></div><aside class="live-code"><div class="introduction"><p class="text">Edit this example to figure out how to tweak animations. The force is strong in you young padawan!</p><button class="edit-button">Edit Example</button></div><div class="editor-area"><textarea class="code-editor"></textarea><button class="close-edit-button">Close Editor</button></div></aside></section></div><div class="sub-section"><h4 id="switching-axis-type">Switching axis type</h4><p>The default configuration of the line chart is that it will use a step based X-Axis and an automatic linear scale for the Y-Axis. This is all happening under the hood of Chartist and already satisfies a lot of use-cases.<p>Sometimes though, it's not enough to have a fixed step chart and you'd need something a bit more complex. Something that allows you to plot those values along the X- and Y-Axis, instead of just the Y-Axis. Sometimes, you'd also want to specify the ticks on your chart manually rather than having them auto calculated from Chartist.<p>Of course Chartist wouldn't let you down with all those ideas you have in mind on how to visualize your data!<div class="sub-section"><h5 id="a-line-chart-is-only-1dimensional">A line chart is only 1-dimensional?!</h5><p>By default, Chartist uses <code>Chartist.StepAxis</code> for the X-Axis and <code>Chartist.AutoScaleAxis</code> for the Y-Axis. Please read the <a href="api-documentation.html">API documentation</a> if you'd like to get more details, or available options on axis configuration.<p>The step based axis will not use any value for projection but rather rely on the index of the given value to determine the position. This is fine for discrete steps of one dimensional data, like we know it from regular Chartist charts:<pre id="1-dimension-values"><code class="js">var data = {
|
||
labels: ['A', 'B', 'C'],
|
||
series: [[10, 8, 14]]
|
||
};
|
||
</code></pre><p>What really happens with such one dimensional series data under the hood is that it will be transformed into two dimensional data like so:<pre id="2-dimensions-values"><code class="js">var data = {
|
||
labels: ['A', 'B', 'C'],
|
||
series: [[
|
||
{x: undefined, y: 10},
|
||
{x: undefined, y: 8},
|
||
{x: undefined, y: 14}
|
||
]]
|
||
};
|
||
</code></pre><p>You can see that Chartist will automatically convert one dimensional data into two dimensional values where the previous value is assigned to <code>y</code> and <code>x</code> will be set to <code>undefined</code>. As the default axis for projecting the <code>x</code> value is a <code>Chartist.StepAxis</code> that relies on the value index rather than the value, this is perfectly fine for the default setup.</div><div class="sub-section"><h5 id="creating-an-xyplot-chart">Creating an XY-plot chart</h5><p>In order to plot on the X-Axis too, we'd need to switch the standard axis type <code>Chartist.StepAxis</code> to something more continuous. Let's create a full fledged auto scale chart that scales both the Y- and X-Axis automatically using the <code>Chartist.AutoScaleAxis</code>!<section class="live-example" id="example-axis-auto" data-live-example="bmV3IENoYXJ0aXN0LkxpbmUoJy5jdC1jaGFydCcsIHsKICBzZXJpZXM6IFtbCiAgICB7eDogMSwgeTogMTAwfSwKICAgIHt4OiAyLCB5OiA1MH0sCiAgICB7eDogMywgeTogMjV9LAogICAge3g6IDUsIHk6IDEyLjV9LAogICAge3g6IDgsIHk6IDYuMjV9CiAgXV0KfSwgewogIGF4aXNYOiB7CiAgICB0eXBlOiBDaGFydGlzdC5BdXRvU2NhbGVBeGlzLAogICAgb25seUludGVnZXI6IHRydWUKICB9Cn0pOwo="><header class="live-example-header"><h6>Configure your axis type</h6></header><div class="chart"><div class="ct-chart ct-golden-section"></div></div><aside class="live-code"><div class="introduction"><p class="text">Note that we have just specified the X-Axis because the Y-Axis is configured to <code>Chartist.AutoScaleAxis</code> by default.</p><button class="edit-button">Edit Example</button></div><div class="editor-area"><textarea class="code-editor"></textarea><button class="close-edit-button">Close Editor</button></div></aside></section><p>A few things are different in this chart. Because the <code>labels</code> array of our data is just used to be mapped as <code>ticks</code> option for the default <code>Chartist.StepAxis</code> X-Axis, we can completely remove the labels from our data, once we use a different axis than the step based one. Also you can see now from the data series is that we are specifying 2-dimensional values directly.</div><div class="sub-section"><h5 id="fixed-stuff-can-be-sweet-too">Fixed stuff can be sweet too!</h5><p>The following example shows how to create an axis with some fixed ticks. The <code>Chartist.FixedScaleAxis</code> can be used to create a more rudimentary continuous linear scale, where ticks can be fixed either with an array of values or with a divisor. For the detailed options please check the <a href="api-documentation.html">API documentation</a>.<section class="live-example" id="example-axis-fixed-and-auto" data-live-example="bmV3IENoYXJ0aXN0LkxpbmUoJy5jdC1jaGFydCcsIHsKICBzZXJpZXM6IFtbCiAgICB7eDogMSwgeTogMTAwfSwKICAgIHt4OiAyLCB5OiA1MH0sCiAgICB7eDogMywgeTogMjV9LAogICAge3g6IDUsIHk6IDEyLjV9LAogICAge3g6IDgsIHk6IDYuMjV9CiAgXV0KfSwgewogIGF4aXNYOiB7CiAgICB0eXBlOiBDaGFydGlzdC5BdXRvU2NhbGVBeGlzLAogICAgb25seUludGVnZXI6IHRydWUKICB9LAogIGF4aXNZOiB7CiAgICB0eXBlOiBDaGFydGlzdC5GaXhlZFNjYWxlQXhpcywKICAgIHRpY2tzOiBbMCwgNTAsIDc1LCA4Ny41LCAxMDBdLAogICAgbG93OiAwCiAgfSwKICBsaW5lU21vb3RoOiBDaGFydGlzdC5JbnRlcnBvbGF0aW9uLnN0ZXAoKSwKICBzaG93UG9pbnQ6IGZhbHNlCn0pOwo="><header class="live-example-header"><h6>Unleash your creativity...</h6></header><div class="chart"><div class="ct-chart ct-golden-section"></div></div><aside class="live-code"><div class="introduction"><p class="text">Let's say we'd like to fix a few ticks on the Y-Axis on our chart as those are the only ones we're interested in. The X-Axis should be continuous too, but let's make that axis a <code>Chartist.AutoScaleAxis</code>.</p><button class="edit-button">Edit Example</button></div><div class="editor-area"><textarea class="code-editor"></textarea><button class="close-edit-button">Close Editor</button></div></aside></section></div></div></div></section></div></article></section><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||
|
||
ga('create', 'UA-53685926-1', 'auto');
|
||
ga('require', 'displayfeatures');
|
||
ga('send', 'pageview');</script><script async src="scripts/all.js"></script><!-- Take web fonts off the critical path but risk FOUT --><script type="text/javascript">WebFontConfig = {
|
||
google: { families: ['Oxygen:400,300,700', 'Source+Code+Pro:400,700'] },
|
||
custom: {
|
||
families: [ 'FontAwesome' ],
|
||
urls: [ '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css']
|
||
}
|
||
};
|
||
(function() {
|
||
var wf = document.createElement('script');
|
||
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
|
||
'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
|
||
wf.type = 'text/javascript';
|
||
wf.async = 'true';
|
||
var s = document.getElementsByTagName('script')[0];
|
||
s.parentNode.insertBefore(wf, s);
|
||
})();</script> |