Comparar commits
33 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| f838fbe485 | |||
| 7d3bd4b7b0 | |||
| b5ec7a1135 | |||
| 7d524ffca0 | |||
| f02b2cf5db | |||
| 57c2552821 | |||
| 2fe169f9c6 | |||
| 03ac436c3c | |||
| 3cf1095215 | |||
| f8b82ee43b | |||
| df5e345ca0 | |||
| a882dffed8 | |||
| e84d7bb609 | |||
| 5ea763028b | |||
| b58c45e6ff | |||
| e5fc19d46b | |||
| 9a1d60c1c5 | |||
| 596cc4de4d | |||
| a09cf5a613 | |||
| 962abec90a | |||
| d978336e0e | |||
| c42f2b5907 | |||
| e451655884 | |||
| 49d23f5f56 | |||
| 18a1a2217e | |||
| 72f0edbf06 | |||
| 552fcb567b | |||
| 2af6c30fd5 | |||
| 0126897526 | |||
| 9ff153db75 | |||
| a8fc520ae3 | |||
| d3f7d77299 | |||
| 81ed8c52eb |
+4
-7
@@ -1,7 +1,4 @@
|
||||
|
||||
.DS_Store
|
||||
|
||||
node_modules/*
|
||||
custom/*
|
||||
|
||||
docs/index.md
|
||||
_site
|
||||
node_modules
|
||||
coverage
|
||||
Gemfile.lock
|
||||
|
||||
+5
-13
@@ -1,13 +1,5 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.11"
|
||||
- "0.10"
|
||||
|
||||
before_script:
|
||||
- npm install
|
||||
|
||||
script:
|
||||
- gulp test
|
||||
|
||||
notifications:
|
||||
slack: chartjs:pcfCZR6ugg5TEcaLtmIfQYuA
|
||||
sudo: false
|
||||
language: ruby
|
||||
script: "bundle exec jekyll build"
|
||||
rvm:
|
||||
- 2.1.0
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
www.chartjs.org
|
||||
@@ -1,55 +0,0 @@
|
||||
Contributing to Chart.js
|
||||
========================
|
||||
|
||||
Contributions to Chart.js are welcome and encouraged, but please have a look through the guidelines in this document before raising an issue, or writing code for the project.
|
||||
|
||||
|
||||
Using issues
|
||||
------------
|
||||
|
||||
The [issue tracker](https://github.com/nnnick/Chart.js/issues) is the preferred channel for reporting bugs, requesting new features and submitting pull requests.
|
||||
|
||||
If you're suggesting a new chart type, please take a look at [writing new chart types](https://github.com/nnnick/Chart.js/blob/master/docs/06-Advanced.md#writing-new-chart-types) in the documentation, and some of the [community extensions](https://github.com/nnnick/Chart.js/blob/master/docs/06-Advanced.md#community-extensions) that have been created already.
|
||||
|
||||
To keep the library lightweight for everyone, it's unlikely we'll add many more chart types to the core of Chart.js, but issues are a good medium to design and spec out how new chart types could work and look.
|
||||
|
||||
Please do not use issues for support requests. For help using Chart.js, please take a look at the [`chartjs`](http://stackoverflow.com/questions/tagged/chartjs) tag on Stack Overflow.
|
||||
|
||||
|
||||
Reporting bugs
|
||||
--------------
|
||||
|
||||
Well structured, detailed bug reports are hugely valuable for the project.
|
||||
|
||||
Guidlines for reporting bugs:
|
||||
|
||||
- Check the issue search to see if it has already been reported
|
||||
- Isolate the problem to a simple test case
|
||||
- Provide a demonstration of the problem on [JS Bin](http://jsbin.com) or similar
|
||||
|
||||
Please provide any additional details associated with the bug, if it's browser or screen density specific, or only happens with a certain configuration or data.
|
||||
|
||||
|
||||
Pull requests
|
||||
-------------
|
||||
|
||||
Clear, concise pull requests are excellent at continuing the project's community driven growth. But please review [these guidelines](https://github.com/blog/1943-how-to-write-the-perfect-pull-request) and the guidelines below before starting work on the project.
|
||||
|
||||
Guidlines:
|
||||
|
||||
- Please create an issue first:
|
||||
- For bugs, we can discuss the fixing approach
|
||||
- For enhancements, we can discuss if it is within the project scope and avoid duplicate effort
|
||||
- Please make changes to the files in [`/src`](https://github.com/nnnick/Chart.js/tree/master/src), not `Chart.js` or `Chart.min.js` in the repo root directory, this avoids merge conflicts
|
||||
- Tabs for indentation, not spaces please
|
||||
- If adding new functionality, please also update the relevant `.md` file in [`/docs`](https://github.com/nnnick/Chart.js/tree/master/docs)
|
||||
- Please make your commits in logical sections with clear commit messages
|
||||
|
||||
Joining the Project
|
||||
-------------
|
||||
- Active committers and contributors are invited to introduce yourself and request commit access to this project. Please send an email to hello@nickdownie.com or file an issue.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
By contributing your code, you agree to license your contribution under the [MIT license](https://github.com/nnnick/Chart.js/blob/master/LICENSE.md).
|
||||
externo
-3477
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -0,0 +1,3 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'github-pages', group: :jekyll_plugins
|
||||
@@ -1,7 +0,0 @@
|
||||
Copyright (c) 2013-2015 Nick Downie
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
+16
-15
@@ -1,20 +1,21 @@
|
||||
# Chart.js
|
||||
About this branch
|
||||
=================
|
||||
|
||||
[](https://travis-ci.org/nnnick/Chart.js) [](https://codeclimate.com/github/nnnick/Chart.js)
|
||||
This branch provides documentation for the Chart.js project. It is set up to
|
||||
provide the hosting for <http://www.chartjs.org/>
|
||||
|
||||
Running and building locally
|
||||
============================
|
||||
|
||||
*Simple HTML5 Charts using the canvas element* [chartjs.org](http://www.chartjs.org)
|
||||
The documentation is written using Markdown and Jekyll. See GitHub's Jekyll
|
||||
documentation at <https://help.github.com/articles/using-jekyll-with-pages/> and
|
||||
see GitHub's `pages-gem` at <https://github.com/github/pages-gem> regarding how
|
||||
to set up the identical build environment locally.
|
||||
|
||||
## Documentation
|
||||
Syncing
|
||||
=======
|
||||
|
||||
You can find documentation at [chartjs.org/docs](http://www.chartjs.org/docs/). The markdown files that build the site are available under `/docs`. Please note - in some of the json examples of configuration you might notice some liquid tags - this is just for the generating the site html, please disregard.
|
||||
|
||||
## Bugs, issues and contributing
|
||||
|
||||
Before submitting an issue or a pull request to the project, please take a moment to look over the [contributing guidelines](https://github.com/nnnick/Chart.js/blob/master/CONTRIBUTING.md) first.
|
||||
|
||||
For support using Chart.js, please post questions with the [`chartjs` tag on Stack Overflow](http://stackoverflow.com/questions/tagged/chartjs).
|
||||
|
||||
## License
|
||||
|
||||
Chart.js is available under the [MIT license](http://opensource.org/licenses/MIT).
|
||||
The contents of the `master` branch's `docs` directory should be copied to this
|
||||
`gh-pages` branch's `_doc-parts` directory. Please submit a pull request to do
|
||||
this whenever updating the `master` branch, unless the `master `branch is
|
||||
preparing to make an alpha release.
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# Base URL to work with github pages
|
||||
baseurl: /Chart.js
|
||||
|
||||
repository: nnnick/Chart.js
|
||||
|
||||
# Collections of files
|
||||
collections:
|
||||
doc-parts:
|
||||
output: false
|
||||
doc-parts-v2:
|
||||
output: false
|
||||
|
||||
markdown: kramdown
|
||||
|
||||
future: true
|
||||
@@ -0,0 +1,247 @@
|
||||
---
|
||||
title: Getting started
|
||||
anchor: getting-started
|
||||
---
|
||||
|
||||
### Download Chart.js
|
||||
|
||||
To download a zip, go to the [Chart.js on Github](https://github.com/nnnick/Chart.js)
|
||||
|
||||
To install via npm / bower:
|
||||
|
||||
```bash
|
||||
npm install chart.js --save
|
||||
```
|
||||
```bash
|
||||
bower install Chart.js --save
|
||||
```
|
||||
|
||||
CDN: https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.0.0/Chart.js
|
||||
|
||||
### Install Chart.js
|
||||
|
||||
To import Chart.js using an old-school script tag:
|
||||
|
||||
```html
|
||||
<script src="Chart.js"></script>
|
||||
<script>
|
||||
var myChart = new Chart({...})
|
||||
</script>
|
||||
```
|
||||
|
||||
To import Chart.js using an awesome module loader:
|
||||
|
||||
```javascript
|
||||
|
||||
// Using CommonJS
|
||||
var Chart = require('chart.js')
|
||||
var myChart = new Chart({...})
|
||||
|
||||
// ES6
|
||||
import Chart from 'chart.js'
|
||||
let myChart = new Chart({...})
|
||||
|
||||
// Using requirejs
|
||||
require(['path/to/Chartjs'], function(Chart){
|
||||
var myChart = new Chart({...})
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
### Creating a Chart
|
||||
|
||||
To create a chart, we need to instantiate the `Chart` class. To do this, we need to pass in the node, jQuery instance, or 2d context of the canvas of where we want to draw the chart. Here's an example.
|
||||
|
||||
```html
|
||||
<canvas id="myChart" width="400" height="400"></canvas>
|
||||
```
|
||||
|
||||
```javascript
|
||||
// Any of the following formats may be used
|
||||
var ctx = document.getElementById("myChart");
|
||||
var ctx = document.getElementById("myChart").getContext("2d");
|
||||
var ctx = $("#myChart");
|
||||
```
|
||||
|
||||
Once you have the element or context, you're ready to instantiate a pre-defined chart-type or create your own!
|
||||
|
||||
The following example instantiates a bar chart showing the number of votes for different colors and the y-axis starting at 0.
|
||||
|
||||
```html
|
||||
<canvas id="myChart" width="400" height="400"></canvas>
|
||||
<script>
|
||||
var ctx = document.getElementById("myChart");
|
||||
var myChart = new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
|
||||
datasets: [{
|
||||
label: '# of Votes',
|
||||
data: [12, 19, 3, 5, 2, 3]
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
scales: {
|
||||
yAxes: [{
|
||||
ticks: {
|
||||
beginAtZero:true
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
```
|
||||
|
||||
It's that easy to get started using Chart.js! From here you can explore the many options that can help you customise your charts with scales, tooltips, labels, colors, custom actions, and much more.
|
||||
|
||||
### Global chart configuration
|
||||
|
||||
This concept was introduced in Chart.js 1.0 to keep configuration DRY, and allow for changing options globally across chart types, avoiding the need to specify options for each instance, or the default for a particular chart type.
|
||||
|
||||
Chart.js merges configurations and options in a few places with the global defaults using chart type defaults and scales defaults. This way you can be as specific as you want in your individual chart configs, or change the defaults for Chart.js as a whole.
|
||||
|
||||
The global options are defined in `Chart.defaults.global`.
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- | --- | --- | ---
|
||||
responsive | Boolean | true | Resizes when the canvas container does.
|
||||
responsiveAnimationDuration | Number | 0 | Duration in milliseconds it takes to animate to new size after a resize event.
|
||||
maintainAspectRatio | Boolean | true | Maintain the original canvas aspect ratio `(width / height)` when resizing
|
||||
events | Array[String] | `["mousemove", "mouseout", "click", "touchstart", "touchmove", "touchend"]` | Events that the chart should listen to for tooltips and hovering
|
||||
hover |-|-|-
|
||||
*hover*.onHover | Function | null | Called when any of the events fire. Called in the context of the chart and passed an array of active elements (bars, points, etc)
|
||||
*hover*.mode | String | 'single' | Sets which elements hover. Acceptable options are `'single'`, `'label'`, or `'dataset'`. `single` highlights the closest element. `label` highlights elements in all datasets at the same `X` value. `dataset` highlights the closest dataset.
|
||||
*hover*.animationDuration | Number | 400 | Duration in milliseconds it takes to animate hover style changes
|
||||
onClick | Function | null | Called if the event is of type 'mouseup' or 'click'. Called in the context of the chart and passed an array of active elements
|
||||
defaultColor | Color | 'rgba(0,0,0,0.1)' |
|
||||
defaultFontColor | Color | '#666' | Default font color for all text
|
||||
defaultFontFamily | String | "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif" | Default font family for all text
|
||||
defaultFontSize | Number | 12 | Default font size (in px) for text. Does not apply to radialLinear scale point labels
|
||||
defaultFontStyle | String | 'normal' | Default font style. Does not apply to tooltip title or footer. Does not apply to chart title
|
||||
legendCallback | Function | ` function (chart) { }` | Function to generate a legend. Receives the chart object to generate a legend from. Default implementation returns an HTML string.
|
||||
|
||||
The global options for the chart title is defined in `Chart.defaults.global.title`
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- | --- | --- | ---
|
||||
display | Boolean | true | Show the title block
|
||||
position | String | 'top' | Position of the title. 'top' or 'bottom' are allowed
|
||||
fullWidth | Boolean | true | Marks that this box should take the full width of the canvas (pushing down other boxes)
|
||||
fontColor | Color | '#666' | Text color
|
||||
fontFamily | String | 'Helvetica Neue' |
|
||||
fontSize | Number | 12 |
|
||||
fontStyle | String | 'bold' |
|
||||
padding | Number | 10 | Number of pixels to add above and below the title text
|
||||
text | String | '' | Title text
|
||||
|
||||
The global options for the chart legend is defined in `Chart.defaults.global.legend`
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- | --- | --- | ---
|
||||
display | Boolean | true | Is the legend displayed
|
||||
position | String | 'top' | Position of the legend. Options are 'top' or 'bottom'
|
||||
fullWidth | Boolean | true | Marks that this box should take the full width of the canvas (pushing down other boxes)
|
||||
onClick | Function | `function(event, legendItem) {}` | A callback that is called when a click is registered on top of a label item
|
||||
labels |-|-|-
|
||||
*labels*boxWidth | Number | 40 | Width of coloured box
|
||||
*labels*fontSize | Number | 12 | Font size
|
||||
*labels*fontStyle | String | "normal" |
|
||||
*labels*fontColor | Color | "#666" |
|
||||
*labels*fontFamily | String | "Helvetica Neue" |
|
||||
*labels*padding | Number | 10 | Padding between rows of colored boxes
|
||||
*labels*generateLabels: | Function | `function(data) { }` | Generates legend items for each thing in the legend. Default implementation returns the text + styling for the color box. Styles that can be returned are `fillStyle`, `strokeStyle`, `lineCap`, `lineDash`, `lineDashOffset`, `lineWidth`, `lineJoin`. Return a `hidden` attribute to indicate that the label refers to something that is not visible. A strikethrough style will be given to the text in this case.
|
||||
|
||||
The global options for tooltips are defined in `Chart.defaults.global.tooltips`.
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- |:---:| --- | ---
|
||||
enabled | Boolean | true |
|
||||
custom | | null |
|
||||
mode | String | 'single' | Sets which elements appear in the tooltip. Acceptable options are `'single'` or `'label'`. `single` highlights the closest element. `label` highlights elements in all datasets at the same `X` value.
|
||||
backgroundColor | Color | 'rgba(0,0,0,0.8)' | Background color of the tooltip
|
||||
| | |
|
||||
Label | | | There are three labels you can control. `title`, `body`, `footer` the star (\*) represents one of these three. *(i.e. titleFontFamily, footerSpacing)*
|
||||
\*FontFamily | String | "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif" |
|
||||
\*FontSize | Number | 12 |
|
||||
\*FontStyle | String | title - "bold", body - "normal", footer - "bold" |
|
||||
\*Spacing | Number | 2 |
|
||||
\*Color | Color | "#fff" |
|
||||
\*Align | String | "left" | text alignment. See [MDN Canvas Documentation](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textAlign)
|
||||
titleMarginBottom | Number | 6 | Margin to add on bottom of title section
|
||||
footerMarginTop | Number | 6 | Margin to add before drawing the footer
|
||||
xPadding | Number | 6 | Padding to add on left and right of tooltip
|
||||
yPadding | Number | 6 | Padding to add on top and bottom of tooltip
|
||||
caretSize | Number | 5 | Size, in px, of the tooltip arrow
|
||||
cornerRadius | Number | 6 | Radius of tooltip corner curves
|
||||
multiKeyBackground | Color | "#fff" | Color to draw behind the colored boxes when multiple items are in the tooltip
|
||||
| | |
|
||||
callbacks | - | - | V2.0 introduces callback functions as a replacement for the template engine in v1. The tooltip has the following callbacks for providing text. For all functions, 'this' will be the tooltip object create from the Chart.Tooltip constructor
|
||||
**Callback Functions** | | | All functions are called with the same arguments
|
||||
xLabel | String or Array[Strings] | | This is the xDataValue for each item to be displayed in the tooltip
|
||||
yLabel | String or Array[Strings] | | This is the yDataValue for each item to be displayed in the tooltip
|
||||
index | Number | | Data index.
|
||||
data | Object | | Data object passed to chart.
|
||||
`return`| String or Array[Strings] | | All functions must return either a string or an array of strings. Arrays of strings are treated as multiple lines of text.
|
||||
| | |
|
||||
*callbacks*.beforeTitle | Function | none | Text to render before the title
|
||||
*callbacks*.title | Function | `function(tooltipItems, data) { //Pick first xLabel }` | Text to render as the title
|
||||
*callbacks*.afterTitle | Function | none | Text to render after the ttiel
|
||||
*callbacks*.beforeBody | Function | none | Text to render before the body section
|
||||
*callbacks*.beforeLabel | Function | none | Text to render before an individual label
|
||||
*callbacks*.label | Function | `function(tooltipItem, data) { // Returns "datasetLabel: tooltipItem.yLabel" }` | Text to render as label
|
||||
*callbacks*.afterLabel | Function | none | Text to render after an individual label
|
||||
*callbacks*.afterBody | Function | none | Text to render after the body section
|
||||
*callbacks*.beforeFooter | Function | none | Text to render before the footer section
|
||||
*callbacks*.footer | Function | none | Text to render as the footer
|
||||
*callbacks*.afterFooter | Function | none | Text to render after the footer section
|
||||
|
||||
The global options for animations are defined in `Chart.defaults.global.animation`.
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- |:---:| --- | ---
|
||||
duration | Number | 1000 | The number of milliseconds an animation takes.
|
||||
easing | String | "easeOutQuart" | Easing function to use.
|
||||
onProgress | Function | none | Callback called on each step of an animation. Passed a single argument, an object, containing the chart instance and an object with details of the animation.
|
||||
onComplete | Function | none | Callback called at the end of an animation. Passed the same arguments as `onProgress`
|
||||
|
||||
The global options for elements are defined in `Chart.defaults.global.elements`.
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- |:---:| --- | ---
|
||||
arc | - | - | -
|
||||
*arc*.backgroundColor | Color | `Chart.defaults.global.defaultColor` | Default fill color for arcs
|
||||
*arc*.borderColor | Color | "#fff" | Default stroke color for arcs
|
||||
*arc*.borderWidth | Number | 2 | Default stroke width for arcs
|
||||
line | - | - | -
|
||||
*line*.tension | Number | 0.4 | Default bezier curve tension. Set to `0` for no bezier curves.
|
||||
*line*.backgroundColor | Color | `Chart.defaults.global.defaultColor` | Default line fill color
|
||||
*line*.borderWidth | Number | 3 | Default line stroke width
|
||||
*line*.borderColor | Color | `Chart.defaults.global.defaultColor` | Default line stroke color
|
||||
*line*.borderCapStyle | String | 'butt' | Default line cap style. See [MDN](https://developer.mozilla.org/en/docs/Web/API/CanvasRenderingContext2D/lineCap)
|
||||
*line*.borderDash | Array | `[]` | Default line dash. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash)
|
||||
*line*.borderDashOffset | Number | 0.0 | Default line dash offset. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset)
|
||||
*line*.borderJoinStyle | String | 'miter' | Default line join style. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin)
|
||||
*line*.fill | Boolean | true |
|
||||
point | - | - | -
|
||||
*point*.radius | Number | 3 | Default point radius
|
||||
*point*.pointStyle | String | 'circle' | Default point style
|
||||
*point*.backgroundColor | Color | `Chart.defaults.global.defaultColor` | Default point fill color
|
||||
*point*.borderWidth | Number | 1 | Default point stroke width
|
||||
*point*.borderColor | Color | `Chart.defaults.global.defaultColor` | Default point stroke color
|
||||
*point*.hitRadius | Number | 1 | Extra radius added to point radius for hit detection
|
||||
*point*.hoverRadius | Number | 4 | Default point radius when hovered
|
||||
*point*.hoverBorderWidth | Number | 1 | Default stroke width when hovered
|
||||
rectangle | - | - | -
|
||||
*rectangle*.backgroundColor | Color | `Chart.defaults.global.defaultColor` | Default bar fill color
|
||||
*rectangle*.borderWidth | Number | 0 | Default bar stroke width
|
||||
*rectangle*.borderColor | Color | `Chart.defaults.global.defaultColor` | Default bar stroke color
|
||||
*rectangle*.borderSkipped | String | 'bottom' | Default skipped (excluded) border for rectangle. Can be one of `bottom`, `left`, `top`, `right`
|
||||
|
||||
If for example, you wanted all charts created to be responsive, and resize when the browser window does, the following setting can be changed:
|
||||
|
||||
```javascript
|
||||
Chart.defaults.global.responsive = true;
|
||||
```
|
||||
|
||||
Now, every time we create a chart, `options.responsive` will be `true`.
|
||||
@@ -0,0 +1,297 @@
|
||||
---
|
||||
title: Scales
|
||||
anchor: scales
|
||||
---
|
||||
|
||||
Scales in v2.0 of Chart.js are significantly more powerful, but also different than those of v1.0.
|
||||
* Multiple x & y axes are now supported.
|
||||
* A built-in label auto-skip feature now detects would-be overlapping ticks and labels and removes every nth label to keep things displaying normally.
|
||||
* Scale titles are now supported
|
||||
* New scale types can be extended without writing an entirely new chart type
|
||||
|
||||
Every scale extends a core scale class with the following options:
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- |:---:| --- | ---
|
||||
type | String | Chart specific. | Type of scale being employed. Custom scales can be created and registered with a string key. Options: ["category"](#scales-category-scale), ["linear"](#scales-linear-scale), ["logarithmic"](#scales-logarithmic-scale), ["time"](#scales-time-scale), ["radialLinear"](#scales-radial-linear-scale)
|
||||
display | Boolean | true | If true, show the scale including gridlines, ticks, and labels. Overrides *gridLines.display*, *scaleLabel.display*, and *ticks.display*.
|
||||
beforeUpdate | Function | undefined | Callback called before the update process starts. Passed a single argument, the scale instance.
|
||||
beforeSetDimensions | Function | undefined | Callback that runs before dimensions are set. Passed a single argument, the scale instance.
|
||||
afterSetDimensions | Function | undefined | Callback that runs after dimensions are set. Passed a single argument, the scale instance.
|
||||
beforeDataLimits | Function | undefined | Callback that runs before data limits are determined. Passed a single argument, the scale instance.
|
||||
afterDataLimits | Function | undefined | Callback that runs after data limits are determined. Passed a single argument, the scale instance.
|
||||
beforeBuildTicks | Function | undefined | Callback that runs before ticks are created. Passed a single argument, the scale instance.
|
||||
afterBuildTicks | Function | undefined | Callback that runs after ticks are created. Useful for filtering ticks. Passed a single argument, the scale instance.
|
||||
beforeTickToLabelConversion | Function | undefined | Callback that runs before ticks are converted into strings. Passed a single argument, the scale instance.
|
||||
afterTickToLabelConversion | Function | undefined | Callback that runs after ticks are converted into strings. Passed a single argument, the scale instance.
|
||||
beforeCalculateTickRotation | Function | undefined | Callback that runs before tick rotation is determined. Passed a single argument, the scale instance.
|
||||
afterCalculateTickRotation | Function | undefined | Callback that runs after tick rotation is determined. Passed a single argument, the scale instance.
|
||||
beforeFit | Function | undefined | Callback that runs before the scale fits to the canvas. Passed a single argument, the scale instance.
|
||||
afterFit | Function | undefined | Callback that runs after the scale fits to the canvas. Passed a single argument, the scale instance.
|
||||
afterUpdate | Function | undefined | Callback that runs at the end of the update process. Passed a single argument, the scale instance.
|
||||
**gridLines** | Array | - | Options for the grid lines that run perpendicular to the axis.
|
||||
*gridLines*.display | Boolean | true |
|
||||
*gridLines*.color | Color | "rgba(0, 0, 0, 0.1)" | Color of the grid lines.
|
||||
*gridLines*.lineWidth | Number | 1 | Stroke width of grid lines
|
||||
*gridLines*.drawOnChartArea | Boolean | true | If true, draw lines on the chart area inside the axis lines. This is useful when there are multiple axes and you need to control which grid lines are drawn
|
||||
*gridLines*.drawTicks | Boolean | true | If true, draw lines beside the ticks in the axis area beside the chart.
|
||||
*gridLines*.zeroLineWidth | Number | 1 | Stroke width of the grid line for the first index (index 0).
|
||||
*gridLines*.zeroLineColor | Color | "rgba(0, 0, 0, 0.25)" | Stroke color of the grid line for the first index (index 0).
|
||||
*gridLines*.offsetGridLines | Boolean | false | If true, offset labels from grid lines.
|
||||
**scaleLabel** | Array | | Title for the entire axis.
|
||||
*scaleLabel*.display | Boolean | false |
|
||||
*scaleLabel*.labelString | String | "" | The text for the title. (i.e. "# of People", "Response Choices")
|
||||
*scaleLabel*.fontColor | Color | "#666" | Font color for the scale title.
|
||||
*scaleLabel*.fontFamily| String | "Helvetica Neue" | Font family for the scale title, follows CSS font-family options.
|
||||
*scaleLabel*.fontSize | Number | 12 | Font size for the scale title.
|
||||
*scaleLabel*.fontStyle | String | "normal" | Font style for the scale title, follows CSS font-style options (i.e. normal, italic, oblique, initial, inherit).
|
||||
**ticks** | Array | | Settings for the labels that run along the axis.
|
||||
*ticks*.beginAtZero | Boolean | false | If true the scale will be begin at 0, if false the ticks will begin at your smallest data value.
|
||||
*ticks*.fontColor | Color | "#666" | Font color for the tick labels.
|
||||
*ticks*.fontFamily | String | "Helvetica Neue" | Font family for the tick labels, follows CSS font-family options.
|
||||
*ticks*.fontSize | Number | 12 | Font size for the tick labels.
|
||||
*ticks*.fontStyle | String | "normal" | Font style for the tick labels, follows CSS font-style options (i.e. normal, italic, oblique, initial, inherit).
|
||||
*ticks*.maxRotation | Number | 90 | Maximum rotation for tick labels when rotating to condense labels. Note: Rotation doesn't occur until necessary. *Note: Only applicable to horizontal scales.*
|
||||
*ticks*.minRotation | Number | 20 | *currently not-implemented* Minimum rotation for tick labels when condensing is necessary. *Note: Only applicable to horizontal scales.*
|
||||
*ticks*.maxTicksLimit | Number | 11 | Maximum number of ticks and gridlines to show. If not defined, it will limit to 11 ticks but will show all gridlines.
|
||||
*ticks*.padding | Number | 10 | Padding between the tick label and the axis. *Note: Only applicable to horizontal scales.*
|
||||
*ticks*.mirror | Boolean | false | Flips tick labels around axis, displaying the labels inside the chart instead of outside. *Note: Only applicable to vertical scales.*
|
||||
*ticks*.reverse | Boolean | false | Reverses order of tick labels.
|
||||
*ticks*.display | Boolean | true | If true, show the ticks.
|
||||
*ticks*.suggestedMin | Number | - | User defined minimum number for the scale, overrides minimum value *except for if* it is higher than the minimum value.
|
||||
*ticks*.suggestedMax | Number | - | User defined maximum number for the scale, overrides maximum value *except for if* it is lower than the maximum value.
|
||||
*ticks*.min | Number | - | User defined minimum number for the scale, overrides minimum value
|
||||
*ticks*.max | Number | - | User defined minimum number for the scale, overrides maximum value
|
||||
*ticks*.autoSkip | Boolean | true | If true, automatically calculates how many labels that can be shown and hides labels accordingly. Turn it off to show all labels no matter what
|
||||
*ticks*.callback | Function | `function(value) { return '' + value; } ` | Returns the string representation of the tick value as it should be displayed on the chart.
|
||||
|
||||
The `callback` method may be used for advanced tick customization. The following callback would display every label in scientific notation
|
||||
```javascript
|
||||
{
|
||||
scales: {
|
||||
xAxes: [{
|
||||
ticks: {
|
||||
// Return an empty string to draw the tick line but hide the tick label
|
||||
// Return `null` or `undefined` to hide the tick line entirely
|
||||
userCallback: function(value, index, values) {
|
||||
return value.toExponential();
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Category Scale
|
||||
The category scale will be familiar to those who have used v1.0. Labels are drawn in from the labels array included in the chart data.
|
||||
|
||||
The category scale extends the core scale class with the following tick template:
|
||||
|
||||
```javascript
|
||||
{
|
||||
position: "bottom",
|
||||
}
|
||||
```
|
||||
|
||||
### Linear Scale
|
||||
The linear scale can be used to display numerical data. It can be placed on either the x or y axis. The scatter chart type automatically configures a line chart to use one of these scales for the x axis.
|
||||
|
||||
The linear scale extends the core scale class with the following tick template:
|
||||
|
||||
```javascript
|
||||
{
|
||||
position: "left",
|
||||
ticks: {
|
||||
callback: function(tickValue, index, ticks) {
|
||||
var delta = ticks[1] - ticks[0];
|
||||
|
||||
// If we have a number like 2.5 as the delta, figure out how many decimal places we need
|
||||
if (Math.abs(delta) > 1) {
|
||||
if (tickValue !== Math.floor(tickValue)) {
|
||||
// not an integer
|
||||
delta = tickValue - Math.floor(tickValue);
|
||||
}
|
||||
}
|
||||
|
||||
var logDelta = helpers.log10(Math.abs(delta));
|
||||
var tickString = '';
|
||||
|
||||
if (tickValue !== 0) {
|
||||
var numDecimal = -1 * Math.floor(logDelta);
|
||||
numDecimal = Math.max(Math.min(numDecimal, 20), 0); // toFixed has a max of 20 decimal places
|
||||
tickString = tickValue.toFixed(numDecimal);
|
||||
} else {
|
||||
tickString = '0'; // never show decimal places for 0
|
||||
}
|
||||
|
||||
return tickString;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
It also provides additional configuration options:
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- |:---:| --- | ---
|
||||
*ticks*.stepSize | Number | - | User defined fixed step size for the scale. If set, the scale ticks will be enumerated by multiple of stepSize, having one tick per increment. If not set, the ticks are labeled automatically using the nice numbers algorithm.
|
||||
|
||||
### Logarithmic Scale
|
||||
The logarithmic scale is used to display logarithmic data of course. It can be placed on either the x or y axis.
|
||||
|
||||
The log scale extends the core scale class with the following tick template:
|
||||
|
||||
```javascript
|
||||
{
|
||||
position: "left",
|
||||
ticks: {
|
||||
callback: function(value) {
|
||||
var remain = value / (Math.pow(10, Math.floor(Chart.helpers.log10(value))));
|
||||
|
||||
if (remain === 1 || remain === 2 || remain === 5) {
|
||||
return value.toExponential();
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Time Scale
|
||||
The time scale is used to display times and dates. It can be placed on the x axis. When building its ticks, it will automatically calculate the most comfortable unit base on the size of the scale.
|
||||
|
||||
The time scale extends the core scale class with the following tick template:
|
||||
|
||||
```javascript
|
||||
{
|
||||
position: "bottom",
|
||||
time: {
|
||||
// string/callback - By default, date objects are expected. You may use a pattern string from http://momentjs.com/docs/#/parsing/string-format/ to parse a time string format, or use a callback function that is passed the label, and must return a moment() instance.
|
||||
parser: false,
|
||||
// string - By default, unit will automatically be detected. Override with 'week', 'month', 'year', etc. (see supported time measurements)
|
||||
unit: false,
|
||||
|
||||
// Number - The number of steps of the above unit between ticks
|
||||
unitStepSize: 1
|
||||
|
||||
// string - By default, no rounding is applied. To round, set to a supported time unit eg. 'week', 'month', 'year', etc.
|
||||
round: false,
|
||||
|
||||
// Moment js for each of the units. Replaces `displayFormat`
|
||||
// To override, use a pattern string from http://momentjs.com/docs/#/displaying/format/
|
||||
displayFormats: {
|
||||
'millisecond': 'SSS [ms]',
|
||||
'second': 'h:mm:ss a', // 11:20:01 AM
|
||||
'minute': 'h:mm:ss a', // 11:20:01 AM
|
||||
'hour': 'MMM D, hA', // Sept 4, 5PM
|
||||
'day': 'll', // Sep 4 2015
|
||||
'week': 'll', // Week 46, or maybe "[W]WW - YYYY" ?
|
||||
'month': 'MMM YYYY', // Sept 2015
|
||||
'quarter': '[Q]Q - YYYY', // Q3
|
||||
'year': 'YYYY', // 2015
|
||||
},
|
||||
// Sets the display format used in tooltip generation
|
||||
tooltipFormat: ''
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
The following time measurements are supported:
|
||||
|
||||
```javascript
|
||||
{
|
||||
'millisecond': {
|
||||
display: 'SSS [ms]', // 002 ms
|
||||
maxStep: 1000,
|
||||
},
|
||||
'second': {
|
||||
display: 'h:mm:ss a', // 11:20:01 AM
|
||||
maxStep: 60,
|
||||
},
|
||||
'minute': {
|
||||
display: 'h:mm:ss a', // 11:20:01 AM
|
||||
maxStep: 60,
|
||||
},
|
||||
'hour': {
|
||||
display: 'MMM D, hA', // Sept 4, 5PM
|
||||
maxStep: 24,
|
||||
},
|
||||
'day': {
|
||||
display: 'll', // Sep 4 2015
|
||||
maxStep: 7,
|
||||
},
|
||||
'week': {
|
||||
display: 'll', // Week 46, or maybe "[W]WW - YYYY" ?
|
||||
maxStep: 4.3333,
|
||||
},
|
||||
'month': {
|
||||
display: 'MMM YYYY', // Sept 2015
|
||||
maxStep: 12,
|
||||
},
|
||||
'quarter': {
|
||||
display: '[Q]Q - YYYY', // Q3
|
||||
maxStep: 4,
|
||||
},
|
||||
'year': {
|
||||
display: 'YYYY', // 2015
|
||||
maxStep: false,
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
### Radial Linear Scale
|
||||
The radial linear scale is used specifically for the radar chart type.
|
||||
|
||||
The radial linear scale extends the core scale class with the following tick template:
|
||||
|
||||
```javascript
|
||||
{
|
||||
animate: true,
|
||||
lineArc: false,
|
||||
position: "chartArea",
|
||||
|
||||
angleLines: {
|
||||
display: true,
|
||||
color: "rgba(0, 0, 0, 0.1)",
|
||||
lineWidth: 1
|
||||
},
|
||||
|
||||
// label settings
|
||||
ticks: {
|
||||
//Boolean - Show a backdrop to the scale label
|
||||
showLabelBackdrop: true,
|
||||
|
||||
//String - The colour of the label backdrop
|
||||
backdropColor: "rgba(255,255,255,0.75)",
|
||||
|
||||
//Number - The backdrop padding above & below the label in pixels
|
||||
backdropPaddingY: 2,
|
||||
|
||||
//Number - The backdrop padding to the side of the label in pixels
|
||||
backdropPaddingX: 2,
|
||||
|
||||
//Number - Limit the maximum number of ticks and gridlines
|
||||
maxTicksLimit: 11,
|
||||
},
|
||||
|
||||
pointLabels: {
|
||||
//String - Point label font declaration
|
||||
fontFamily: "'Arial'",
|
||||
|
||||
//String - Point label font weight
|
||||
fontStyle: "normal",
|
||||
|
||||
//Number - Point label font size in pixels
|
||||
fontSize: 10,
|
||||
|
||||
//String - Point label font colour
|
||||
fontColor: "#666",
|
||||
|
||||
//Function - Used to determine point labels to show in scale
|
||||
callback: function(pointLabel) {
|
||||
return pointLabel;
|
||||
}
|
||||
},
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,155 @@
|
||||
---
|
||||
title: Line Chart
|
||||
anchor: line-chart
|
||||
---
|
||||
### Introduction
|
||||
A line chart is a way of plotting data points on a line.
|
||||
|
||||
Often, it is used to show trend data, and the comparison of two data sets.
|
||||
|
||||
<div class="canvas-holder">
|
||||
<canvas width="250" height="125"></canvas>
|
||||
</div>
|
||||
|
||||
### Example usage
|
||||
```javascript
|
||||
var myLineChart = new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: data,
|
||||
options: options
|
||||
});
|
||||
```
|
||||
|
||||
Alternatively a line chart can be created using syntax similar to the v1.0 syntax
|
||||
```javascript
|
||||
var myLineChart = Chart.Line(ctx, {
|
||||
data: data,
|
||||
options: options
|
||||
});
|
||||
```
|
||||
### Data structure
|
||||
|
||||
```javascript
|
||||
var data = {
|
||||
labels: ["January", "February", "March", "April", "May", "June", "July"],
|
||||
datasets: [
|
||||
{
|
||||
label: "My First dataset",
|
||||
|
||||
// Boolean - if true fill the area under the line
|
||||
fill: false,
|
||||
|
||||
// String - the color to fill the area under the line with if fill is true
|
||||
backgroundColor: "rgba(220,220,220,0.2)",
|
||||
|
||||
// The properties below allow an array to be specified to change the value of the item at the given index
|
||||
|
||||
// String or array - Line color
|
||||
borderColor: "rgba(220,220,220,1)",
|
||||
|
||||
// String - cap style of the line. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineCap
|
||||
borderCapStyle: 'butt',
|
||||
|
||||
// Array - Length and spacing of dashes. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash
|
||||
borderDash: [],
|
||||
|
||||
// Number - Offset for line dashes. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineDashOffset
|
||||
borderDashOffset: 0.0,
|
||||
|
||||
// String - line join style. See https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/lineJoin
|
||||
borderJoinStyle: 'miter',
|
||||
|
||||
// String or array - Point stroke color
|
||||
pointBorderColor: "rgba(220,220,220,1)",
|
||||
|
||||
// String or array - Point fill color
|
||||
pointBackgroundColor: "#fff",
|
||||
|
||||
// Number or array - Stroke width of point border
|
||||
pointBorderWidth: 1,
|
||||
|
||||
// Number or array - Radius of point when hovered
|
||||
pointHoverRadius: 5,
|
||||
|
||||
// String or array - point background color when hovered
|
||||
pointHoverBackgroundColor: "rgba(220,220,220,1)",
|
||||
|
||||
// Point border color when hovered
|
||||
pointHoverBorderColor: "rgba(220,220,220,1)",
|
||||
|
||||
// Number or array - border width of point when hovered
|
||||
pointHoverBorderWidth: 2,
|
||||
|
||||
// Tension - bezier curve tension of the line. Set to 0 to draw straight Wlines connecting points
|
||||
tension: 0.1,
|
||||
|
||||
// The actual data
|
||||
data: [65, 59, 80, 81, 56, 55, 40],
|
||||
|
||||
// String - If specified, binds the dataset to a certain y-axis. If not specified, the first y-axis is used. First id is y-axis-0
|
||||
yAxisID: "y-axis-0",
|
||||
},
|
||||
{
|
||||
label: "My Second dataset",
|
||||
fill: false,
|
||||
backgroundColor: "rgba(220,220,220,0.2)",
|
||||
borderColor: "rgba(220,220,220,1)",
|
||||
pointBorderColor: "rgba(220,220,220,1)",
|
||||
pointBackgroundColor: "#fff",
|
||||
pointBorderWidth: 1,
|
||||
pointHoverRadius: 5,
|
||||
pointHoverBackgroundColor: "rgba(220,220,220,1)",
|
||||
pointHoverBorderColor: "rgba(220,220,220,1)",
|
||||
pointHoverBorderWidth: 2,
|
||||
data: [28, 48, 40, 19, 86, 27, 90]
|
||||
}
|
||||
]
|
||||
};
|
||||
```
|
||||
|
||||
The line chart requires an array of labels. This labels are shown on the X axis. There must be one label for each data point. More labels than datapoints are allowed, in which case the line ends at the last data point.
|
||||
The data for line charts is broken up into an array of datasets. Each dataset has a colour for the fill, a colour for the line and colours for the points and strokes of the points. These colours are strings just like CSS. You can use RGBA, RGB, HEX or HSL notation.
|
||||
|
||||
The label key on each dataset is optional, and can be used when generating a scale for the chart.
|
||||
|
||||
### Chart options
|
||||
|
||||
These are the customisation options specific to Line charts. These options are merged with the [global chart configuration options](#getting-started-global-chart-configuration), and form the options of the chart.
|
||||
|
||||
The default options for line chart are defined in `Chart.defaults.Line`.
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- | --- | --- | ---
|
||||
showLines | Boolean | true | If false, the lines between points are not drawn
|
||||
stacked | Boolean | false | If true, lines stack on top of each other along the y axis.
|
||||
*hover*.mode | String | "label" | Label's hover mode. "label" is used since the x axis displays data by the index in the dataset.
|
||||
scales | - | - | -
|
||||
*scales*.xAxes | Array | `[{type:"category","id":"x-axis-1"}]` | Defines all of the x axes used in the chart. See the [scale documentation](#getting-started-scales) for details on the available options.
|
||||
*Options for xAxes* | | |
|
||||
type | String | "category" | As defined in ["Category"](#scales-category-scale).
|
||||
id | String | "x-axis-1" | Id of the axis so that data can bind to it.
|
||||
| | |
|
||||
*scales*.yAxes | Array | `[{type:"linear","id":"y-axis-1"}]` | Defines all of the x axes used in the chart. See the [scale documentation](#getting-started-scales) for details on the available options.
|
||||
*Options for yAxes* | | |
|
||||
type | String | "linear" | As defined in ["Linear"](#scales-linear-scale).
|
||||
id | String | "y-axis-1" | Id of the axis so that data can bind to it.
|
||||
|
||||
You can override these for your `Chart` instance by passing a member `options` into the `Line` method.
|
||||
|
||||
For example, we could have a line chart display without an x axis by doing the following. The config merge is smart enough to handle arrays so that you do not need to specify all axis settings to change one thing.
|
||||
|
||||
```javascript
|
||||
new Chart(ctx, {
|
||||
type: 'line',
|
||||
data: data,
|
||||
options: {
|
||||
xAxes: [{
|
||||
display: false
|
||||
}]
|
||||
}
|
||||
});
|
||||
// This will create a chart with all of the default options, merged from the global config,
|
||||
// and the Line chart defaults, but this particular instance will have the x axis not displaying.
|
||||
```
|
||||
|
||||
We can also change these defaults values for each Line type that is created, this object is available at `Chart.defaults.line`.
|
||||
@@ -0,0 +1,155 @@
|
||||
---
|
||||
title: Bar Chart
|
||||
anchor: bar-chart
|
||||
---
|
||||
|
||||
### Introduction
|
||||
A bar chart is a way of showing data as bars.
|
||||
|
||||
It is sometimes used to show trend data, and the comparison of multiple data sets side by side.
|
||||
|
||||
<div class="canvas-holder">
|
||||
<canvas width="250" height="125"></canvas>
|
||||
</div>
|
||||
|
||||
### Example usage
|
||||
```javascript
|
||||
var myBarChart = new Chart(ctx, {
|
||||
type: 'bar',
|
||||
data: data,
|
||||
options: options
|
||||
});
|
||||
```
|
||||
|
||||
### Data structure
|
||||
|
||||
```javascript
|
||||
var data = {
|
||||
labels: ["January", "February", "March", "April", "May", "June", "July"],
|
||||
datasets: [
|
||||
{
|
||||
label: "My First dataset",
|
||||
|
||||
// The properties below allow an array to be specified to change the value of the item at the given index
|
||||
// String or array - the bar color
|
||||
backgroundColor: "rgba(220,220,220,0.2)",
|
||||
|
||||
// String or array - bar stroke color
|
||||
borderColor: "rgba(220,220,220,1)",
|
||||
|
||||
// Number or array - bar border width
|
||||
borderWidth: 1,
|
||||
|
||||
// String or array - fill color when hovered
|
||||
hoverBackgroundColor: "rgba(220,220,220,0.2)",
|
||||
|
||||
// String or array - border color when hovered
|
||||
hoverBorderColor: "rgba(220,220,220,1)",
|
||||
|
||||
// The actual data
|
||||
data: [65, 59, 80, 81, 56, 55, 40],
|
||||
|
||||
// String - If specified, binds the dataset to a certain y-axis. If not specified, the first y-axis is used.
|
||||
yAxisID: "y-axis-0",
|
||||
},
|
||||
{
|
||||
label: "My Second dataset",
|
||||
backgroundColor: "rgba(220,220,220,0.2)",
|
||||
borderColor: "rgba(220,220,220,1)",
|
||||
borderWidth: 1,
|
||||
hoverBackgroundColor: "rgba(220,220,220,0.2)",
|
||||
hoverBorderColor: "rgba(220,220,220,1)",
|
||||
data: [28, 48, 40, 19, 86, 27, 90]
|
||||
}
|
||||
]
|
||||
};
|
||||
```
|
||||
The bar chart has the a very similar data structure to the line chart, and has an array of datasets, each with colours and an array of data. Again, colours are in CSS format.
|
||||
We have an array of labels too for display. In the example, we are showing the same data as the previous line chart example.
|
||||
|
||||
The label key on each dataset is optional, and can be used when generating a scale for the chart.
|
||||
|
||||
### Chart Options
|
||||
|
||||
These are the customisation options specific to Bar charts. These options are merged with the [global chart configuration options](#getting-started-global-chart-configuration), and form the options of the chart.
|
||||
|
||||
The default options for bar chart are defined in `Chart.defaults.Bar`.
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- |:---:| --- | ---
|
||||
stacked | Boolean | false |
|
||||
*hover*.mode | String | "label" | Label's hover mode. "label" is used since the x axis displays data by the index in the dataset.
|
||||
scales | Array | - | -
|
||||
*scales*.xAxes | Array | | The bar chart officially supports only 1 x-axis but uses an array to keep the API consistent. Use a scatter chart if you need multiple x axes.
|
||||
*Options for xAxes* | | |
|
||||
type | String | "Category" | As defined in [Scales](#scales-category-scale).
|
||||
display | Boolean | true | If true, show the scale.
|
||||
position | String | "bottom" | Position of the scale. Options are "top" and "bottom" for dataset scales.
|
||||
id | String | "x-axis-1" | Id of the axis so that data can bind to it
|
||||
categoryPercentage | Number | 0.8 | Percent (0-1) of the available width (the space between the gridlines for small datasets) for each data-point to use for the bars. [Read More](#bar-chart-barpercentage-vs-categorypercentage)
|
||||
barPercentage | Number | 0.9 | Percent (0-1) of the available width each bar should be within the category percentage. 1.0 will take the whole category width and put the bars right next to each other. [Read More](#bar-chart-barpercentage-vs-categorypercentage)
|
||||
gridLines | Array | [See Scales](#scales) |
|
||||
*gridLines*.offsetGridLines | Boolean | true | If true, the bars for a particular data point fall between the grid lines. If false, the grid line will go right down the middle of the bars.
|
||||
scaleLabel | Array | [See Scales](#scales) |
|
||||
ticks | Array | [See Scales](#scales) |
|
||||
| | |
|
||||
*scales*.yAxes | Array | `[{ type: "linear" }]` |
|
||||
*Options for xAxes* | | |
|
||||
type | String | "linear" | As defined in [Scales](#scales-linear-scale).
|
||||
display | Boolean | true | If true, show the scale.
|
||||
position | String | "left" | Position of the scale. Options are "left" and "right" for dataset scales.
|
||||
id | String | "y-axis-1" | Id of the axis so that data can bind to it.
|
||||
gridLines | Array | [See Scales](#scales) |
|
||||
scaleLabel | Array | [See Scales](#scales) |
|
||||
ticks | Array | [See Scales](#scales) |
|
||||
|
||||
You can override these for your `Chart` instance by passing a second argument into the `Bar` method as an object with the keys you want to override.
|
||||
|
||||
For example, we could have a bar chart without a stroke on each bar by doing the following:
|
||||
|
||||
```javascript
|
||||
new Chart(ctx, {
|
||||
type: "bar",
|
||||
data: data,
|
||||
options: {
|
||||
scales: {
|
||||
xAxes: [{
|
||||
stacked: true
|
||||
}],
|
||||
yAxes: [{
|
||||
stacked: true
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// This will create a chart with all of the default options, merged from the global config,
|
||||
// and the Bar chart defaults but this particular instance will have `stacked` set to true
|
||||
// for both x and y axes.
|
||||
```
|
||||
|
||||
We can also change these defaults values for each Bar type that is created, this object is available at `Chart.defaults.Bar`.
|
||||
|
||||
#### barPercentage vs categoryPercentage
|
||||
|
||||
The following shows the relationship between the bar percentage option and the category percentage option.
|
||||
|
||||
```text
|
||||
// categoryPercentage: 1.0
|
||||
// barPercentage: 1.0
|
||||
Bar: | 1.0 | 1.0 |
|
||||
Category: | 1.0 |
|
||||
Sample: |===========|
|
||||
|
||||
// categoryPercentage: 1.0
|
||||
// barPercentage: 0.5
|
||||
Bar: |.5| |.5|
|
||||
Category: | 1.0 |
|
||||
Sample: |==============|
|
||||
|
||||
// categoryPercentage: 0.5
|
||||
// barPercentage: 1.0
|
||||
Bar: |1.||1.|
|
||||
Category: | .5 |
|
||||
Sample: |==============|
|
||||
```
|
||||
@@ -0,0 +1,93 @@
|
||||
---
|
||||
title: Radar Chart
|
||||
anchor: radar-chart
|
||||
---
|
||||
|
||||
### Introduction
|
||||
A radar chart is a way of showing multiple data points and the variation between them.
|
||||
|
||||
They are often useful for comparing the points of two or more different data sets.
|
||||
|
||||
<div class="canvas-holder">
|
||||
<canvas width="250" height="125"></canvas>
|
||||
</div>
|
||||
|
||||
### Example usage
|
||||
|
||||
```javascript
|
||||
var myRadarChart = new Chart(ctx, {
|
||||
type: 'radar',
|
||||
data: data,
|
||||
options: options
|
||||
});
|
||||
```
|
||||
|
||||
### Data structure
|
||||
```javascript
|
||||
var data = {
|
||||
labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
|
||||
datasets: [
|
||||
{
|
||||
label: "My First dataset",
|
||||
backgroundColor: "rgba(220,220,220,0.2)",
|
||||
borderColor: "rgba(220,220,220,1)",
|
||||
pointBackgroundColor: "rgba(220,220,220,1)",
|
||||
pointBorderColor: "#fff",
|
||||
pointHoverBackgroundColor: "#fff",
|
||||
pointHoverBorderColor: "rgba(220,220,220,1)",
|
||||
data: [65, 59, 90, 81, 56, 55, 40]
|
||||
},
|
||||
{
|
||||
label: "My Second dataset",
|
||||
backgroundColor: "rgba(151,187,205,0.2)",
|
||||
borderColor: "rgba(151,187,205,1)",
|
||||
pointBackgroundColor: "rgba(151,187,205,1)",
|
||||
pointBorderColor: "#fff",
|
||||
pointHoverBackgroundColor: "#fff",
|
||||
pointHoverBorderColor: "rgba(151,187,205,1)",
|
||||
data: [28, 48, 40, 19, 96, 27, 100]
|
||||
}
|
||||
]
|
||||
};
|
||||
```
|
||||
For a radar chart, to provide context of what each point means, we include an array of strings that show around each point in the chart.
|
||||
For the radar chart data, we have an array of datasets. Each of these is an object, with a fill colour, a stroke colour, a colour for the fill of each point, and a colour for the stroke of each point. We also have an array of data values.
|
||||
The label key on each dataset is optional, and can be used when generating a scale for the chart.
|
||||
|
||||
|
||||
### Chart Options
|
||||
|
||||
These are the customisation options specific to Radar charts. These options are merged with the [global chart configuration options](#getting-started-global-chart-configuration), and form the options of the chart.
|
||||
|
||||
The default options for radar chart are defined in `Chart.defaults.radar`.
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- | --- | --- | ---
|
||||
scale | Array | [See Scales](#scales) and [Defaults for Radial Linear Scale](#scales-radial-linear-scale) | Options for the one scale used on the chart. Use this to style the ticks, labels, and grid lines.
|
||||
*scale*.type | String |"radialLinear" | As defined in ["Radial Linear"](#scales-radial-linear-scale).
|
||||
*elements*.line | Array | | Options for all line elements used on the chart, as defined in the global elements, duplicated here to show Radar chart specific defaults.
|
||||
*elements.line*.tension | Number | 0 | Tension exhibited by lines when calculating splineCurve. Setting to 0 creates straight lines.
|
||||
|
||||
You can override these for your `Chart` instance by passing a second argument into the `Radar` method as an object with the keys you want to override.
|
||||
|
||||
For example, we could have a radar chart without a point for each on piece of data by doing the following:
|
||||
|
||||
```javascript
|
||||
new Chart(ctx, {
|
||||
type: "radar",
|
||||
data: data,
|
||||
options: {
|
||||
scale: {
|
||||
reverse: true,
|
||||
ticks: {
|
||||
beginAtZero: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// This will create a chart with all of the default options, merged from the global config,
|
||||
// and the Radar chart defaults but this particular instance's scale will be reversed as
|
||||
// well as the ticks beginning at zero.
|
||||
```
|
||||
|
||||
We can also change these defaults values for each Radar type that is created, this object is available at `Chart.defaults.radar`.
|
||||
@@ -0,0 +1,91 @@
|
||||
---
|
||||
title: Polar Area Chart
|
||||
anchor: polar-area-chart
|
||||
---
|
||||
### Introduction
|
||||
Polar area charts are similar to pie charts, but each segment has the same angle - the radius of the segment differs depending on the value.
|
||||
|
||||
This type of chart is often useful when we want to show a comparison data similar to a pie chart, but also show a scale of values for context.
|
||||
|
||||
<div class="canvas-holder">
|
||||
<canvas width="250" height="125"></canvas>
|
||||
</div>
|
||||
|
||||
### Example usage
|
||||
|
||||
```javascript
|
||||
new Chart(ctx, {
|
||||
data: data,
|
||||
type: 'polarArea',
|
||||
options: options
|
||||
});
|
||||
```
|
||||
|
||||
### Data structure
|
||||
|
||||
```javascript
|
||||
var data = {
|
||||
datasets: [{
|
||||
data: [
|
||||
10,
|
||||
32,
|
||||
53,
|
||||
14,
|
||||
22,
|
||||
],
|
||||
backgroundColor: [
|
||||
"#F7464A",
|
||||
"#46BFBD",
|
||||
"#FDB45C",
|
||||
"#949FB1",
|
||||
"#4D5360",
|
||||
],
|
||||
label: 'My dataset' // for legend
|
||||
}],
|
||||
labels: [
|
||||
"Red",
|
||||
"Green",
|
||||
"Yellow",
|
||||
"Grey",
|
||||
"Dark Grey"
|
||||
]
|
||||
};
|
||||
```
|
||||
As you can see, for the chart data you pass in an array of objects, with a value and a colour. The value attribute should be a number, while the color attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL.
|
||||
|
||||
### Chart options
|
||||
|
||||
These are the customisation options specific to Polar Area charts. These options are merged with the [global chart configuration options](#getting-started-global-chart-configuration), and form the options of the chart.
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- | --- | --- | ---
|
||||
scale | Array | [See Scales](#scales) and [Defaults for Radial Linear Scale](#getting-started-radial-linear-scale) | Options for the one scale used on the chart. Use this to style the ticks, labels, and grid.
|
||||
*scale*.type | String |"radialLinear" | As defined in ["Radial Linear"](#scales-radial-linear-scale).
|
||||
*scale*.lineArc | Boolean | true | When true, lines are circular.
|
||||
animateRotate | Boolean |true | If true, will animate the rotation of the chart.
|
||||
animateScale | Boolean | true | If true, will animate scaling the chart.
|
||||
*legend*.*labels*.generateLabels | Function | `function(data) {} ` | Returns labels for each the legend
|
||||
*legend*.onClick | Function | function(event, legendItem) {} ` | Handles clicking an individual legend item
|
||||
legendCallback | Function | `function(chart) ` | Generates the HTML legend via calls to `generateLegend`
|
||||
|
||||
You can override these for your `Chart` instance by passing a second argument into the `PolarArea` method as an object with the keys you want to override.
|
||||
|
||||
For example, we could have a polar area chart with a black stroke on each segment like so:
|
||||
|
||||
```javascript
|
||||
new Chart(ctx, {
|
||||
data: data,
|
||||
type: "polarArea",
|
||||
options: {
|
||||
elements: {
|
||||
arc: {
|
||||
borderColor: "#000000"
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// This will create a chart with all of the default options, merged from the global config,
|
||||
// and the PolarArea chart defaults but this particular instance will have `elements.arc.borderColor` set to `"#000000"`.
|
||||
```
|
||||
|
||||
We can also change these defaults values for each PolarArea type that is created, this object is available at `Chart.defaults.polarArea`.
|
||||
@@ -0,0 +1,99 @@
|
||||
---
|
||||
title: Pie & Doughnut Charts
|
||||
anchor: doughnut-pie-chart
|
||||
---
|
||||
### Introduction
|
||||
Pie and doughnut charts are probably the most commonly used chart there are. They are divided into segments, the arc of each segment shows the proportional value of each piece of data.
|
||||
|
||||
They are excellent at showing the relational proportions between data.
|
||||
|
||||
Pie and doughnut charts are effectively the same class in Chart.js, but have one different default value - their `percentageInnerCutout`. This equates what percentage of the inner should be cut out. This defaults to `0` for pie charts, and `50` for doughnuts.
|
||||
|
||||
They are also registered under two aliases in the `Chart` core. Other than their different default value, and different alias, they are exactly the same.
|
||||
|
||||
<div class="canvas-holder half">
|
||||
<canvas width="250" height="125"></canvas>
|
||||
</div>
|
||||
|
||||
<div class="canvas-holder half">
|
||||
<canvas width="250" height="125"></canvas>
|
||||
</div>
|
||||
|
||||
|
||||
### Example usage
|
||||
|
||||
```javascript
|
||||
// For a pie chart
|
||||
var myPieChart = new Chart(ctx[0],{
|
||||
type:'pie',
|
||||
data: data,
|
||||
options: options
|
||||
});
|
||||
|
||||
// And for a doughnut chart
|
||||
var myDoughnutChart = new Chart(ctx[1], {
|
||||
type:'doughnut',
|
||||
data: data,
|
||||
options: options
|
||||
});
|
||||
```
|
||||
|
||||
### Data structure
|
||||
|
||||
```javascript
|
||||
var data = {
|
||||
labels: [
|
||||
"Red",
|
||||
"Green",
|
||||
"Yellow"
|
||||
],
|
||||
datasets: [
|
||||
{
|
||||
data: [300, 50, 100],
|
||||
backgroundColor: [
|
||||
"#F7464A",
|
||||
"#46BFBD",
|
||||
"#FDB45C"
|
||||
],
|
||||
hoverBackgroundColor: [
|
||||
"#FF5A5E",
|
||||
"#5AD3D1",
|
||||
"#FFC870"
|
||||
]
|
||||
}]
|
||||
};
|
||||
```
|
||||
|
||||
For a pie chart, you must pass in an array of objects with a value and an optional color property. The value attribute should be a number, Chart.js will total all of the numbers and calculate the relative proportion of each. The color attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL.
|
||||
|
||||
### Chart options
|
||||
|
||||
These are the customisation options specific to Pie & Doughnut charts. These options are merged with the [global chart configuration options](#getting-started-global-chart-configuration), and form the options of the chart.
|
||||
|
||||
Name | Type | Default | Description
|
||||
--- | --- | --- | ---
|
||||
cutoutPercentage | Number | 50 - for doughnut, 0 - for pie | The percentage of the chart that is cut out of the middle.
|
||||
scale | Array | [See Scales](#scales) and [Defaults for Radial Linear Scale](#getting-started-radial-linear-scale) | Options for the one scale used on the chart. Use this to style the ticks, labels, and grid.
|
||||
*scale*.type | String |"radialLinear" | As defined in ["Radial Linear"](#scales-radial-linear-scale).
|
||||
*scale*.lineArc | Boolean | true | When true, lines are arced compared to straight when false.
|
||||
*animation*.animateRotate | Boolean |true | If true, will animate the rotation of the chart.
|
||||
*animation*.animateScale | Boolean | false | If true, will animate scaling the Doughnut from the centre.
|
||||
*legend*.*labels*.generateLabels | Function | `function(data) {} ` | Returns labels for each the legend
|
||||
*legend*.onClick | Function | function(event, legendItem) {} ` | Handles clicking an individual legend item
|
||||
|
||||
You can override these for your `Chart` instance by passing a second argument into the `Doughnut` method as an object with the keys you want to override.
|
||||
|
||||
For example, we could have a doughnut chart that animates by scaling out from the centre like so:
|
||||
|
||||
```javascript
|
||||
new Chart(ctx,{
|
||||
type:"doughnut",
|
||||
animation:{
|
||||
animateScale:true
|
||||
}
|
||||
});
|
||||
// This will create a chart with all of the default options, merged from the global config,
|
||||
// and the Doughnut chart defaults but this particular instance will have `animateScale` set to `true`.
|
||||
```
|
||||
|
||||
We can also change these default values for each Doughnut type that is created, this object is available at `Chart.defaults.Doughnut`. Pie charts also have a clone of these defaults available to change at `Chart.defaults.Pie`, with the only difference being `percentageInnerCutout` being set to 0.
|
||||
@@ -0,0 +1,386 @@
|
||||
---
|
||||
title: Advanced usage
|
||||
anchor: advanced-usage
|
||||
---
|
||||
|
||||
|
||||
### Prototype methods
|
||||
|
||||
For each chart, there are a set of global prototype methods on the shared `ChartType` which you may find useful. These are available on all charts created with Chart.js, but for the examples, let's use a line chart we've made.
|
||||
|
||||
```javascript
|
||||
// For example:
|
||||
var myLineChart = new Chart(ctx, config);
|
||||
```
|
||||
|
||||
#### .destroy()
|
||||
|
||||
Use this to destroy any chart instances that are created. This will clean up any references stored to the chart object within Chart.js, along with any associated event listeners attached by Chart.js.
|
||||
This must be called before the canvas is reused for a new chart.
|
||||
|
||||
```javascript
|
||||
// Destroys a specific chart instance
|
||||
myLineChart.destroy();
|
||||
```
|
||||
|
||||
#### .update(duration, lazy)
|
||||
|
||||
Triggers an update of the chart. This can be safely called after replacing the entire data object. This will update all scales, legends, and then re-render the chart.
|
||||
|
||||
```javascript
|
||||
// duration is the time for the animation of the redraw in miliseconds
|
||||
// lazy is a boolean. if true, the animation can be interupted by other animations
|
||||
myLineChart.data.datasets[0].data[2] = 50; // Would update the first dataset's value of 'March' to be 50
|
||||
myLineChart.update(); // Calling update now animates the position of March from 90 to 50.
|
||||
```
|
||||
|
||||
#### .render(duration, lazy)
|
||||
|
||||
Triggers a redraw of all chart elements. Note, this does not update elements for new data. Use `.update()` in that case.
|
||||
|
||||
```javascript
|
||||
// duration is the time for the animation of the redraw in miliseconds
|
||||
// lazy is a boolean. if true, the animation can be interupted by other animations
|
||||
myLineChart.render(duration, lazy);
|
||||
```
|
||||
|
||||
#### .stop()
|
||||
|
||||
Use this to stop any current animation loop. This will pause the chart during any current animation frame. Call `.render()` to re-animate.
|
||||
|
||||
```javascript
|
||||
// Stops the charts animation loop at its current frame
|
||||
myLineChart.stop();
|
||||
// => returns 'this' for chainability
|
||||
```
|
||||
|
||||
#### .resize()
|
||||
|
||||
Use this to manually resize the canvas element. This is run each time the canvas container is resized, but you can call this method manually if you change the size of the canvas nodes container element.
|
||||
|
||||
```javascript
|
||||
// Resizes & redraws to fill its container element
|
||||
myLineChart.resize();
|
||||
// => returns 'this' for chainability
|
||||
```
|
||||
|
||||
#### .clear()
|
||||
|
||||
Will clear the chart canvas. Used extensively internally between animation frames, but you might find it useful.
|
||||
|
||||
```javascript
|
||||
// Will clear the canvas that myLineChart is drawn on
|
||||
myLineChart.clear();
|
||||
// => returns 'this' for chainability
|
||||
```
|
||||
|
||||
#### .toBase64Image()
|
||||
|
||||
This returns a base 64 encoded string of the chart in it's current state.
|
||||
|
||||
```javascript
|
||||
myLineChart.toBase64Image();
|
||||
// => returns png data url of the image on the canvas
|
||||
```
|
||||
|
||||
#### .generateLegend()
|
||||
|
||||
Returns an HTML string of a legend for that chart. The legend is generated from the `legendCallback` in the options.
|
||||
|
||||
```javascript
|
||||
myLineChart.generateLegend();
|
||||
// => returns HTML string of a legend for this chart
|
||||
```
|
||||
|
||||
#### .getElementAtEvent(e)
|
||||
|
||||
Calling `getElementAtEvent(event)` on your Chart instance passing an argument of an event, or jQuery event, will return the single element at the event position. If there are multiple items within range, only the first is returned
|
||||
|
||||
```javascript
|
||||
myLineChart.getElementAtEvent(e);
|
||||
// => returns the first element at the event point.
|
||||
```
|
||||
|
||||
#### .getElementsAtEvent(e)
|
||||
|
||||
Looks for the element under the event point, then returns all elements at the same data index. This is used internally for 'label' mode highlighting.
|
||||
|
||||
Calling `getElementsAtEvent(event)` on your Chart instance passing an argument of an event, or jQuery event, will return the point elements that are at that the same position of that event.
|
||||
|
||||
```javascript
|
||||
canvas.onclick = function(evt){
|
||||
var activePoints = myLineChart.getElementsAtEvent(evt);
|
||||
// => activePoints is an array of points on the canvas that are at the same position as the click event.
|
||||
};
|
||||
```
|
||||
|
||||
This functionality may be useful for implementing DOM based tooltips, or triggering custom behaviour in your application.
|
||||
|
||||
#### .getDatasetAtEvent(e)
|
||||
|
||||
Looks for the element under the event point, then returns all elements from that dataset. This is used internally for 'dataset' mode highlighting
|
||||
|
||||
```javascript
|
||||
myLineChart.getDatasetAtEvent(e);
|
||||
// => returns an array of elements
|
||||
```
|
||||
|
||||
### External Tooltips
|
||||
|
||||
You can enable custom tooltips in the global or chart configuration like so:
|
||||
|
||||
```javascript
|
||||
var myPieChart = new Chart(ctx, {
|
||||
type: 'pie',
|
||||
data: data,
|
||||
options: {
|
||||
tooltips: {
|
||||
custom: function(tooltip) {
|
||||
// tooltip will be false if tooltip is not visible or should be hidden
|
||||
if (!tooltip) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, tooltip will be an object with all tooltip properties like:
|
||||
|
||||
// tooltip.caretHeight
|
||||
// tooltip.caretPadding
|
||||
// tooltip.chart
|
||||
// tooltip.cornerRadius
|
||||
// tooltip.fillColor
|
||||
// tooltip.font...
|
||||
// tooltip.text
|
||||
// tooltip.x
|
||||
// tooltip.y
|
||||
// etc...
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
See `sample/line-customTooltips.html` for examples on how to get started.
|
||||
|
||||
### Writing new scale types
|
||||
|
||||
Starting with Chart.js 2.0 scales can be individually extended. Scales should always derive from Chart.Scale.
|
||||
|
||||
```javascript
|
||||
var MyScale = Chart.Scale.extend({
|
||||
/* extensions ... */
|
||||
});
|
||||
|
||||
// MyScale is now derived from Chart.Scale
|
||||
```
|
||||
|
||||
Once you have created your scale class, you need to register it with the global chart object so that it can be used. A default config for the scale may be provided when registering the constructor. The first parameter to the register function is a string key that is used later to identify which scale type to use for a chart.
|
||||
|
||||
```javascript
|
||||
Chart.scaleService.registerScaleType('myScale', MyScale, defaultConfigObject);
|
||||
```
|
||||
|
||||
To use the new scale, simply pass in the string key to the config when creating a chart.
|
||||
|
||||
```javascript
|
||||
var lineChart = new Chart(ctx, {
|
||||
data: data,
|
||||
type: 'line',
|
||||
options: {
|
||||
scales: {
|
||||
yAxes: [{
|
||||
type: 'myScale' // this is the same key that was passed to the registerScaleType function
|
||||
}]
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
#### Scale Properties
|
||||
|
||||
Scale instances are given the following properties during the fitting process.
|
||||
|
||||
```javascript
|
||||
{
|
||||
left: Number, // left edge of the scale bounding box
|
||||
right: Number, // right edge of the bounding box'
|
||||
top: Number,
|
||||
bottom: Number,
|
||||
width: Number, // the same as right - left
|
||||
height: Number, // the same as bottom - top
|
||||
|
||||
// Margin on each side. Like css, this is outside the bounding box.
|
||||
margins: {
|
||||
left: Number,
|
||||
right: Number,
|
||||
top: Number,
|
||||
bottom: Number,
|
||||
},
|
||||
|
||||
// Amount of padding on the inside of the bounding box (like CSS)
|
||||
paddingLeft: Number,
|
||||
paddingRight: Number,
|
||||
paddingTop: Number,
|
||||
paddingBottom: Number,
|
||||
}
|
||||
```
|
||||
|
||||
#### Scale Interface
|
||||
To work with Chart.js, custom scale types must implement the following interface.
|
||||
|
||||
```javascript
|
||||
{
|
||||
// Determines the data limits. Should set this.min and this.max to be the data max/min
|
||||
determineDataLimits: function() {},
|
||||
|
||||
// Generate tick marks. this.chart is the chart instance. The data object can be accessed as this.chart.data
|
||||
// buildTicks() should create a ticks array on the scale instance, if you intend to use any of the implementations from the base class
|
||||
buildTicks: function() {},
|
||||
|
||||
// Get the value to show for the data at the given index of the the given dataset, ie this.chart.data.datasets[datasetIndex].data[index]
|
||||
getLabelForIndex: function(index, datasetIndex) {},
|
||||
|
||||
// Get the pixel (x coordinate for horizontal scale, y coordinate for vertical scales) for a given value
|
||||
// @param index: index into the ticks array
|
||||
// @param includeOffset: if true, get the pixel halway between the given tick and the next
|
||||
getPixelForTick: function(index, includeOffset) {},
|
||||
|
||||
// Get the pixel (x coordinate for horizontal scale, y coordinate for vertical scales) for a given value
|
||||
// @param value : the value to get the pixel for
|
||||
// @param index : index into the data array of the value
|
||||
// @param datasetIndex : index of the dataset the value comes from
|
||||
// @param includeOffset : if true, get the pixel halway between the given tick and the next
|
||||
getPixelForValue: function(value, index, datasetIndex, includeOffset) {}
|
||||
}
|
||||
```
|
||||
|
||||
Optionally, the following methods may also be overwritten, but an implementation is already provided by the `Chart.Scale` base class.
|
||||
|
||||
```javascript
|
||||
// Transform the ticks array of the scale instance into strings. The default implementation simply calls this.options.ticks.callback(numericalTick, index, ticks);
|
||||
convertTicksToLabels: function() {},
|
||||
|
||||
// Determine how much the labels will rotate by. The default implementation will only rotate labels if the scale is horizontal.
|
||||
calculateTickRotation: function() {},
|
||||
|
||||
// Fits the scale into the canvas.
|
||||
// this.maxWidth and this.maxHeight will tell you the maximum dimensions the scale instance can be. Scales should endeavour to be as efficient as possible with canvas space.
|
||||
// this.margins is the amount of space you have on either side of your scale that you may expand in to. This is used already for calculating the best label rotation
|
||||
// You must set this.minSize to be the size of your scale. It must be an object containing 2 properties: width and height.
|
||||
// You must set this.width to be the width and this.height to be the height of the scale
|
||||
fit: function() {},
|
||||
|
||||
// Draws the scale onto the canvas. this.(left|right|top|bottom) will have been populated to tell you the area on the canvas to draw in
|
||||
// @param chartArea : an object containing four properties: left, right, top, bottom. This is the rectangle that lines, bars, etc will be drawn in. It may be used, for example, to draw grid lines.
|
||||
draw: function(chartArea) {},
|
||||
```
|
||||
|
||||
The Core.Scale base class also has some utility functions that you may find useful.
|
||||
```javascript
|
||||
{
|
||||
// Returns true if the scale instance is horizontal
|
||||
isHorizontal: function() {},
|
||||
|
||||
// Get the correct value from the value from this.chart.data.datasets[x].data[]
|
||||
// If dataValue is an object, returns .x or .y depending on the return of isHorizontal()
|
||||
// If the value is undefined, returns NaN
|
||||
// Otherwise returns the value.
|
||||
// Note that in all cases, the returned value is not guaranteed to be a Number
|
||||
getRightValue: function(dataValue) {},
|
||||
}
|
||||
```
|
||||
|
||||
### Writing new chart types
|
||||
|
||||
Chart.js 2.0 introduces the concept of controllers for each dataset. Like scales, new controllers can be written as needed.
|
||||
|
||||
```javascript
|
||||
Chart.controllers.MyType = Chart.DatasetController.extend({
|
||||
|
||||
});
|
||||
|
||||
|
||||
// Now we can create a new instance of our chart, using the Chart.js API
|
||||
new Chart(ctx, {
|
||||
// this is the string the constructor was registered at, ie Chart.controllers.MyType
|
||||
type: 'MyType',
|
||||
data: data,
|
||||
options: options
|
||||
});
|
||||
```
|
||||
|
||||
#### Dataset Controller Interface
|
||||
|
||||
Dataset controllers must implement the following interface.
|
||||
|
||||
```javascript
|
||||
{
|
||||
// Create elements for each piece of data in the dataset. Store elements in an array on the dataset as dataset.metaData
|
||||
addElements: function() {},
|
||||
|
||||
// Create a single element for the data at the given index and reset its state
|
||||
addElementAndReset: function(index) {},
|
||||
|
||||
// Draw the representation of the dataset
|
||||
// @param ease : if specified, this number represents how far to transition elements. See the implementation of draw() in any of the provided controllers to see how this should be used
|
||||
draw: function(ease) {},
|
||||
|
||||
// Remove hover styling from the given element
|
||||
removeHoverStyle: function(element) {},
|
||||
|
||||
// Add hover styling to the given element
|
||||
setHoverStyle: function(element) {},
|
||||
|
||||
// Update the elements in response to new data
|
||||
// @param reset : if true, put the elements into a reset state so they can animate to their final values
|
||||
update: function(reset) {},
|
||||
}
|
||||
```
|
||||
|
||||
The following methods may optionally be overridden by derived dataset controllers
|
||||
```javascript
|
||||
{
|
||||
// Initializes the controller
|
||||
initialize: function(chart, datasetIndex) {},
|
||||
|
||||
// Ensures that the dataset represented by this controller is linked to a scale. Overridden to helpers.noop in the polar area and doughnut controllers as these
|
||||
// chart types using a single scale
|
||||
linkScales: function() {},
|
||||
|
||||
// Called by the main chart controller when an update is triggered. The default implementation handles the number of data points changing and creating elements appropriately.
|
||||
buildOrUpdateElements: function() {}
|
||||
}
|
||||
```
|
||||
|
||||
### Extending existing chart types
|
||||
|
||||
Extending or replacing an existing controller type is easy. Simply replace the constructor for one of the built in types with your own.
|
||||
|
||||
The built in controller types are:
|
||||
* `Chart.controllers.line`
|
||||
* `Chart.controllers.bar`
|
||||
* `Chart.controllers.radar`
|
||||
* `Chart.controllers.doughnut`
|
||||
* `Chart.controllers.polarArea`
|
||||
* `Chart.controllers.bubble`
|
||||
|
||||
#### Bar Controller
|
||||
The bar controller has a special property that you should be aware of. To correctly calculate the width of a bar, the controller must determine the number of datasets that map to bars. To do this, the bar controller attaches a property `bar` to the dataset during initialization. If you are creating a replacement or updated bar controller, you should do the same. This will ensure that charts with regular bars and your new derived bars will work seamlessly.
|
||||
|
||||
### Building Chart.js
|
||||
|
||||
Chart.js uses <a href="http://gulpjs.com/" target="_blank">gulp</a> to build the library into a single JavaScript file.
|
||||
|
||||
Firstly, we need to ensure development dependencies are installed. With node and npm installed, after cloning the Chart.js repo to a local directory, and navigating to that directory in the command line, we can run the following:
|
||||
|
||||
```bash
|
||||
npm install
|
||||
npm install -g gulp
|
||||
```
|
||||
|
||||
This will install the local development dependencies for Chart.js, along with a CLI for the JavaScript task runner <a href="http://gulpjs.com/" target="_blank">gulp</a>.
|
||||
|
||||
Now, we can run the `gulp build` task.
|
||||
|
||||
```bash
|
||||
gulp build
|
||||
```
|
||||
@@ -11,14 +11,14 @@ First we need to include the Chart.js library on the page. The library occupies
|
||||
<script src="Chart.js"></script>
|
||||
```
|
||||
|
||||
Alternatively, if you're using an AMD loader for JavaScript modules, that is also supported in the Chart.js core. Please note: the library will still occupy a global variable of `Chart`, even if it detects `define` and `define.amd`. If this is a problem, you can call `noConflict` to restore the global Chart variable to it's previous owner.
|
||||
Alternatively, if you're using an AMD loader for JavaScript modules, that is also supported in the Chart.js core. Please note: the library will still occupy a global variable of `Chart`, even if it detects `define` and `define.amd`. If this is a problem, you can call `noConflict` to restore the global Chart variable to its previous owner.
|
||||
|
||||
```javascript
|
||||
// Using requirejs
|
||||
require(['path/to/Chartjs'], function(Chart){
|
||||
// Use Chart.js as normal here.
|
||||
|
||||
// Chart.noConflict restores the Chart global variable to it's previous owner
|
||||
// Chart.noConflict restores the Chart global variable to its previous owner
|
||||
// The function returns what was previously Chart, allowing you to reassign.
|
||||
var Chartjs = Chart.noConflict();
|
||||
|
||||
@@ -31,6 +31,16 @@ You can also grab Chart.js using bower:
|
||||
bower install Chart.js --save
|
||||
```
|
||||
|
||||
or NPM:
|
||||
|
||||
```bash
|
||||
npm install chart.js --save
|
||||
```
|
||||
|
||||
Also, Chart.js is available from CDN:
|
||||
|
||||
https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js
|
||||
|
||||
###Creating a chart
|
||||
|
||||
To create a chart, we need to instantiate the `Chart` class. To do this, we need to pass in the 2d context of where we want to draw the chart. Here's an example.
|
||||
@@ -68,6 +78,10 @@ We call a method of the name of the chart we want to create. We pass in the data
|
||||
|
||||
This concept was introduced in Chart.js 1.0 to keep configuration DRY, and allow for changing options globally across chart types, avoiding the need to specify options for each instance, or the default for a particular chart type.
|
||||
|
||||
Templates are based on micro templating by John Resig:
|
||||
|
||||
http://ejohn.org/blog/javascript-micro-templating/
|
||||
|
||||
```javascript
|
||||
Chart.defaults.global = {
|
||||
// Boolean - Whether to animate the chart
|
||||
@@ -77,6 +91,14 @@ Chart.defaults.global = {
|
||||
animationSteps: 60,
|
||||
|
||||
// String - Animation easing effect
|
||||
// Possible effects are:
|
||||
// [easeInOutQuart, linear, easeOutBounce, easeInBack, easeInOutQuad,
|
||||
// easeOutQuart, easeOutQuad, easeInOutBounce, easeOutSine, easeInOutCubic,
|
||||
// easeInExpo, easeInOutBack, easeInCirc, easeInOutElastic, easeOutBack,
|
||||
// easeInQuad, easeInOutExpo, easeInQuart, easeOutQuint, easeInOutCirc,
|
||||
// easeInSine, easeOutExpo, easeOutCirc, easeOutCubic, easeInQuint,
|
||||
// easeInElastic, easeInOutSine, easeInOutQuint, easeInBounce,
|
||||
// easeOutElastic, easeInCubic]
|
||||
animationEasing: "easeOutQuart",
|
||||
|
||||
// Boolean - If we should show the scale at all
|
||||
@@ -132,7 +154,7 @@ Chart.defaults.global = {
|
||||
// Boolean - Determines whether to draw tooltips on the canvas or not
|
||||
showTooltips: true,
|
||||
|
||||
// Function - Determines whether to execute the customTooltips function instead of drawing the built in tooltips (See [Advanced - External Tooltips](#advanced-usage-custom-tooltips))
|
||||
// Function - Determines whether to execute the customTooltips function instead of drawing the built in tooltips (See [Advanced - External Tooltips](#advanced-usage-external-tooltips))
|
||||
customTooltips: false,
|
||||
|
||||
// Array - Array of string names to attach tooltip events
|
||||
@@ -165,6 +187,9 @@ Chart.defaults.global = {
|
||||
// String - Tooltip title font colour
|
||||
tooltipTitleFontColor: "#fff",
|
||||
|
||||
// String - Tooltip title template
|
||||
tooltipTitleTemplate: "<%= label%>",
|
||||
|
||||
// Number - pixel width of padding around tooltip text
|
||||
tooltipYPadding: 6,
|
||||
|
||||
@@ -100,8 +100,11 @@ These are the customisation options specific to Line charts. These options are m
|
||||
datasetFill : true,
|
||||
{% raw %}
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>"
|
||||
{% endraw %}
|
||||
|
||||
//Boolean - Whether to horizontally center the label and point dot inside the grid
|
||||
offsetGridLines : false
|
||||
};
|
||||
```
|
||||
|
||||
@@ -84,7 +84,7 @@ These are the customisation options specific to Bar charts. These options are me
|
||||
barDatasetSpacing : 1,
|
||||
{% raw %}
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].fillColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].fillColor%>\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>"
|
||||
{% endraw %}
|
||||
}
|
||||
```
|
||||
@@ -110,7 +110,7 @@ These are the customisation options specific to Radar charts. These options are
|
||||
datasetFill : true,
|
||||
{% raw %}
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"><%if(datasets[i].label){%><%=datasets[i].label%><%}%></span></li><%}%></ul>"
|
||||
{% endraw %}
|
||||
}
|
||||
```
|
||||
@@ -83,7 +83,7 @@ These are the customisation options specific to Polar Area charts. These options
|
||||
//Boolean - Stroke a line around each segment in the chart
|
||||
segmentShowStroke : true,
|
||||
|
||||
//String - The colour of the stroke on each segement.
|
||||
//String - The colour of the stroke on each segment.
|
||||
segmentStrokeColor : "#fff",
|
||||
|
||||
//Number - The width of the stroke value in pixels
|
||||
@@ -102,7 +102,7 @@ These are the customisation options specific to Polar Area charts. These options
|
||||
animateScale : false,
|
||||
{% raw %}
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"><%if(segments[i].label){%><%=segments[i].label%><%}%></span></li><%}%></ul>"
|
||||
{% endraw %}
|
||||
}
|
||||
```
|
||||
@@ -169,4 +169,4 @@ Calling `removeData(index)` on your Chart instance will remove segment at that p
|
||||
```javascript
|
||||
myPolarAreaChart.removeData();
|
||||
// Other segments will update to fill the empty space left.
|
||||
```
|
||||
```
|
||||
@@ -55,7 +55,7 @@ var data = [
|
||||
]
|
||||
```
|
||||
|
||||
For a pie chart, you must pass in an array of objects with a value and a color property. The value attribute should be a number, Chart.js will total all of the numbers and calculate the relative proportion of each. The color attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL.
|
||||
For a pie chart, you must pass in an array of objects with a value and an optional color property. The value attribute should be a number, Chart.js will total all of the numbers and calculate the relative proportion of each. The color attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL.
|
||||
|
||||
### Chart options
|
||||
|
||||
@@ -88,7 +88,7 @@ These are the customisation options specific to Pie & Doughnut charts. These opt
|
||||
animateScale : false,
|
||||
{% raw %}
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"><%if(segments[i].label){%><%=segments[i].label%><%}%></span></li><%}%></ul>"
|
||||
{% endraw %}
|
||||
}
|
||||
```
|
||||
@@ -54,7 +54,7 @@ myLineChart.destroy();
|
||||
|
||||
#### .toBase64Image()
|
||||
|
||||
This returns a base 64 encoded string of the chart in it's current state.
|
||||
This returns a base 64 encoded string of the chart in its current state.
|
||||
|
||||
```javascript
|
||||
myLineChart.toBase64Image();
|
||||
@@ -158,8 +158,10 @@ new Chart(ctx).LineAlt(data);
|
||||
|
||||
### Community extensions
|
||||
|
||||
- <a href="https://github.com/Regaddi/Chart.StackedBar.js" target"_blank">Stacked Bar Chart</a> by <a href="https://twitter.com/Regaddi" target="_blank">@Regaddi</a>
|
||||
- <a href="https://github.com/CAYdenberg/Chart.js" target"_blank">Error bars (bar and line charts)</a> by <a href="https://twitter.com/CAYdenberg" target="_blank">@CAYdenberg</a>
|
||||
- <a href="https://github.com/Regaddi/Chart.StackedBar.js" target="_blank">Stacked Bar Chart</a> by <a href="https://twitter.com/Regaddi" target="_blank">@Regaddi</a>
|
||||
- <a href="https://github.com/tannerlinsley/Chart.StackedArea.js" target="_blank">Stacked Bar Chart</a> by <a href="https://twitter.com/tannerlinsley" target="_blank">@tannerlinsley</a>
|
||||
- <a href="https://github.com/CAYdenberg/Chart.js" target="_blank">Error bars (bar and line charts)</a> by <a href="https://twitter.com/CAYdenberg" target="_blank">@CAYdenberg</a>
|
||||
- <a href="http://dima117.github.io/Chart.Scatter/" target="_blank">Scatter chart (number & date scales are supported)</a> by <a href="https://github.com/dima117" target="_blank">@dima117</a>
|
||||
|
||||
### Creating custom builds
|
||||
|
||||
@@ -174,7 +176,7 @@ npm install -g gulp
|
||||
|
||||
This will install the local development dependencies for Chart.js, along with a CLI for the JavaScript task runner <a href="http://gulpjs.com/" target="_blank">gulp</a>.
|
||||
|
||||
Now, we can run the `gulp build` task, and pass in a comma seperated list of types as an argument to build a custom version of Chart.js with only specified chart types.
|
||||
Now, we can run the `gulp build` task, and pass in a comma-separated list of types as an argument to build a custom version of Chart.js with only specified chart types.
|
||||
|
||||
Here we will create a version of Chart.js with only Line, Radar and Bar charts included:
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
---
|
||||
title: Notes
|
||||
anchor: notes
|
||||
---
|
||||
|
||||
### Browser support
|
||||
Browser support for the canvas element is available in all modern & major mobile browsers <a href="http://caniuse.com/canvas" target="_blank">(caniuse.com/canvas)</a>.
|
||||
|
||||
For IE8 & below, I would recommend using the polyfill ExplorerCanvas - available at <a href="https://code.google.com/p/explorercanvas/" target="_blank">https://code.google.com/p/explorercanvas/</a>. It falls back to Internet explorer's format VML when canvas support is not available. Example use:
|
||||
|
||||
```html
|
||||
<head>
|
||||
<!--[if lte IE 8]>
|
||||
<script src="excanvas.js"></script>
|
||||
<![endif]-->
|
||||
</head>
|
||||
```
|
||||
|
||||
Usually I would recommend feature detection to choose whether or not to load a polyfill, rather than IE conditional comments, however in this case, VML is a Microsoft proprietary format, so it will only work in IE.
|
||||
|
||||
Some important points to note in my experience using ExplorerCanvas as a fallback.
|
||||
|
||||
- Initialise charts on load rather than DOMContentReady when using the library, as sometimes a race condition will occur, and it will result in an error when trying to get the 2d context of a canvas.
|
||||
- New VML DOM elements are being created for each animation frame and there is no hardware acceleration. As a result animation is usually slow and jerky, with flashing text. It is a good idea to dynamically turn off animation based on canvas support. I recommend using the excellent <a href="http://modernizr.com/" target="_blank">Modernizr</a> to do this.
|
||||
- When declaring fonts, the library explorercanvas requires the font name to be in single quotes inside the string. For example, instead of your scaleFontFamily property being simply "Arial", explorercanvas support, use "'Arial'" instead. Chart.js does this for default values.
|
||||
|
||||
### Bugs & issues
|
||||
|
||||
Please report these on the GitHub page - at <a href="https://github.com/nnnick/Chart.js" target="_blank">github.com/nnnick/Chart.js</a>. If you could include a link to a simple <a href="http://jsbin.com/" target="_blank">jsbin</a> or similar to demonstrate the issue, that'd be really helpful.
|
||||
|
||||
|
||||
### Contributing
|
||||
New contributions to the library are welcome, just a couple of guidelines:
|
||||
|
||||
- Tabs for indentation, not spaces please.
|
||||
- Please ensure you're changing the individual files in `/src`, not the concatenated output in the `Chart.js` file in the root of the repo.
|
||||
- Please check that your code will pass `jshint` code standards, `gulp jshint` will run this for you.
|
||||
- Please keep pull requests concise, and document new functionality in the relevant `.md` file.
|
||||
- Consider whether your changes are useful for all users, or if creating a Chart.js extension would be more appropriate.
|
||||
|
||||
### License
|
||||
Chart.js is open source and available under the <a href="http://opensource.org/licenses/MIT" target="_blank">MIT license</a>.
|
||||
@@ -0,0 +1,673 @@
|
||||
* {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
color: inherit;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
*,
|
||||
*:before,
|
||||
*:after {
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
position: relative;
|
||||
font-family: "proxima-nova", 'Helvetica Neue', 'Helvetica', 'sans-serif';
|
||||
color: #232830;
|
||||
}
|
||||
lesshat-selector {
|
||||
-lh-property: 0; }
|
||||
::selection{color: #dfe1e8; background: #5b90bf}
|
||||
::-moz-selection{color: #dfe1e8; background: #5b90bf;
|
||||
}
|
||||
.hll {
|
||||
background-color: #ffffcc;
|
||||
}
|
||||
.c {
|
||||
color: #999988;
|
||||
font-style: italic;
|
||||
}
|
||||
/* Comment */
|
||||
.err {
|
||||
color: #a61717;
|
||||
background-color: #e3d2d2;
|
||||
}
|
||||
/* Error */
|
||||
.k {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Keyword */
|
||||
.o {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Operator */
|
||||
.cm {
|
||||
color: #999988;
|
||||
font-style: italic;
|
||||
}
|
||||
/* Comment.Multiline */
|
||||
.cp {
|
||||
color: #999999;
|
||||
font-weight: bold;
|
||||
font-style: italic;
|
||||
}
|
||||
/* Comment.Preproc */
|
||||
.c1 {
|
||||
color: #999988;
|
||||
font-style: italic;
|
||||
}
|
||||
/* Comment.Single */
|
||||
.cs {
|
||||
color: #999999;
|
||||
font-weight: bold;
|
||||
font-style: italic;
|
||||
}
|
||||
/* Comment.Special */
|
||||
.gd {
|
||||
color: #000000;
|
||||
background-color: #ffdddd;
|
||||
}
|
||||
/* Generic.Deleted */
|
||||
.ge {
|
||||
color: #000000;
|
||||
font-style: italic;
|
||||
}
|
||||
/* Generic.Emph */
|
||||
.gr {
|
||||
color: #aa0000;
|
||||
}
|
||||
/* Generic.Error */
|
||||
.gh {
|
||||
color: #999999;
|
||||
}
|
||||
/* Generic.Heading */
|
||||
.gi {
|
||||
color: #000000;
|
||||
background-color: #ddffdd;
|
||||
}
|
||||
/* Generic.Inserted */
|
||||
.go {
|
||||
color: #888888;
|
||||
}
|
||||
/* Generic.Output */
|
||||
.gp {
|
||||
color: #555555;
|
||||
}
|
||||
/* Generic.Prompt */
|
||||
.gs {
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Generic.Strong */
|
||||
.gu {
|
||||
color: #aaaaaa;
|
||||
}
|
||||
/* Generic.Subheading */
|
||||
.gt {
|
||||
color: #aa0000;
|
||||
}
|
||||
/* Generic.Traceback */
|
||||
.kc {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Keyword.Constant */
|
||||
.kd {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Keyword.Declaration */
|
||||
.kn {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Keyword.Namespace */
|
||||
.kp {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Keyword.Pseudo */
|
||||
.kr {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Keyword.Reserved */
|
||||
.kt {
|
||||
color: #445588;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Keyword.Type */
|
||||
.m {
|
||||
color: #009999;
|
||||
}
|
||||
/* Literal.Number */
|
||||
.s {
|
||||
color: #d01040;
|
||||
}
|
||||
/* Literal.String */
|
||||
.na {
|
||||
color: #008080;
|
||||
}
|
||||
/* Name.Attribute */
|
||||
.nb {
|
||||
color: #0086b3;
|
||||
}
|
||||
/* Name.Builtin */
|
||||
.nc {
|
||||
color: #445588;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Name.Class */
|
||||
.no {
|
||||
color: #008080;
|
||||
}
|
||||
/* Name.Constant */
|
||||
.nd {
|
||||
color: #3c5d5d;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Name.Decorator */
|
||||
.ni {
|
||||
color: #800080;
|
||||
}
|
||||
/* Name.Entity */
|
||||
.ne {
|
||||
color: #990000;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Name.Exception */
|
||||
.nf {
|
||||
color: #990000;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Name.Function */
|
||||
.nl {
|
||||
color: #990000;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Name.Label */
|
||||
.nn {
|
||||
color: #555555;
|
||||
}
|
||||
/* Name.Namespace */
|
||||
.nt {
|
||||
color: #000080;
|
||||
}
|
||||
/* Name.Tag */
|
||||
.nv {
|
||||
color: #008080;
|
||||
}
|
||||
/* Name.Variable */
|
||||
.ow {
|
||||
color: #000000;
|
||||
font-weight: bold;
|
||||
}
|
||||
/* Operator.Word */
|
||||
.w {
|
||||
color: #bbbbbb;
|
||||
}
|
||||
/* Text.Whitespace */
|
||||
.mf {
|
||||
color: #009999;
|
||||
}
|
||||
/* Literal.Number.Float */
|
||||
.mh {
|
||||
color: #009999;
|
||||
}
|
||||
/* Literal.Number.Hex */
|
||||
.mi {
|
||||
color: #009999;
|
||||
}
|
||||
/* Literal.Number.Integer */
|
||||
.mo {
|
||||
color: #009999;
|
||||
}
|
||||
/* Literal.Number.Oct */
|
||||
.sb {
|
||||
color: #d01040;
|
||||
}
|
||||
/* Literal.String.Backtick */
|
||||
.sc {
|
||||
color: #d01040;
|
||||
}
|
||||
/* Literal.String.Char */
|
||||
.sd {
|
||||
color: #d01040;
|
||||
}
|
||||
/* Literal.String.Doc */
|
||||
.s2 {
|
||||
color: #d01040;
|
||||
}
|
||||
/* Literal.String.Double */
|
||||
.se {
|
||||
color: #d01040;
|
||||
}
|
||||
/* Literal.String.Escape */
|
||||
.sh {
|
||||
color: #d01040;
|
||||
}
|
||||
/* Literal.String.Heredoc */
|
||||
.si {
|
||||
color: #d01040;
|
||||
}
|
||||
/* Literal.String.Interpol */
|
||||
.sx {
|
||||
color: #d01040;
|
||||
}
|
||||
/* Literal.String.Other */
|
||||
.sr {
|
||||
color: #009926;
|
||||
}
|
||||
/* Literal.String.Regex */
|
||||
.s1 {
|
||||
color: #d01040;
|
||||
}
|
||||
/* Literal.String.Single */
|
||||
.ss {
|
||||
color: #990073;
|
||||
}
|
||||
/* Literal.String.Symbol */
|
||||
.bp {
|
||||
color: #999999;
|
||||
}
|
||||
/* Name.Builtin.Pseudo */
|
||||
.vc {
|
||||
color: #008080;
|
||||
}
|
||||
/* Name.Variable.Class */
|
||||
.vg {
|
||||
color: #008080;
|
||||
}
|
||||
/* Name.Variable.Global */
|
||||
.vi {
|
||||
color: #008080;
|
||||
}
|
||||
/* Name.Variable.Instance */
|
||||
.il {
|
||||
color: #009999;
|
||||
}
|
||||
/* Literal.Number.Integer.Long */
|
||||
lesshat-selector {
|
||||
-lh-property: 0; }
|
||||
@-webkit-keyframes hamburger-top{ 0%{ -webkit-transform: translate3d(0,0,0) rotate(0); } 50%{ -webkit-transform: translate3d(0,8px,0) rotate(0); } 100%{ -webkit-transform: translate3d(0,8px,0) rotate(45deg); }}
|
||||
@-moz-keyframes hamburger-top{ 0%{ -moz-transform: translate3d(0,0,0) rotate(0); } 50%{ -moz-transform: translate3d(0,8px,0) rotate(0); } 100%{ -moz-transform: translate3d(0,8px,0) rotate(45deg); }}
|
||||
@-o-keyframes hamburger-top{ 0%{ -o-transform: translate3d(0,0,0) rotate(0); } 50%{ -o-transform: translate3d(0,8px,0) rotate(0); } 100%{ -o-transform: translate3d(0,8px,0) rotate(45deg); }}
|
||||
@keyframes hamburger-top{ 0%{-webkit-transform: translate3d(0,0,0) rotate(0);-moz-transform: translate3d(0,0,0) rotate(0);-ms-transform: translate3d(0,0,0) rotate(0);transform: translate3d(0,0,0) rotate(0); } 50%{-webkit-transform: translate3d(0,8px,0) rotate(0);-moz-transform: translate3d(0,8px,0) rotate(0);-ms-transform: translate3d(0,8px,0) rotate(0);transform: translate3d(0,8px,0) rotate(0); } 100%{-webkit-transform: translate3d(0,8px,0) rotate(45deg);-moz-transform: translate3d(0,8px,0) rotate(45deg);-ms-transform: translate3d(0,8px,0) rotate(45deg);transform: translate3d(0,8px,0) rotate(45deg); }
|
||||
}
|
||||
lesshat-selector {
|
||||
-lh-property: 0; }
|
||||
@-webkit-keyframes hamburger-middle{ 0%{ opacity:1; } 50%{ opacity: 1; } 51%{ opacity:0; } 100%{ opacity:0; }}
|
||||
@-moz-keyframes hamburger-middle{ 0%{ opacity:1; } 50%{ opacity: 1; } 51%{ opacity:0; } 100%{ opacity:0; }}
|
||||
@-o-keyframes hamburger-middle{ 0%{ opacity:1; } 50%{ opacity: 1; } 51%{ opacity:0; } 100%{ opacity:0; }}
|
||||
@keyframes hamburger-middle{ 0%{ opacity:1; } 50%{ opacity: 1; } 51%{ opacity:0; } 100%{ opacity:0; }
|
||||
}
|
||||
lesshat-selector {
|
||||
-lh-property: 0; }
|
||||
@-webkit-keyframes hamburger-bottom{ 0%{ -webkit-transform: translate3d(0,0,0) rotate(0); } 50%{ -webkit-transform: translate3d(0,-8px,0) rotate(0); } 100%{ -webkit-transform: translate3d(0,-8px,0) rotate(-45deg); }}
|
||||
@-moz-keyframes hamburger-bottom{ 0%{ -moz-transform: translate3d(0,0,0) rotate(0); } 50%{ -moz-transform: translate3d(0,-8px,0) rotate(0); } 100%{ -moz-transform: translate3d(0,-8px,0) rotate(-45deg); }}
|
||||
@-o-keyframes hamburger-bottom{ 0%{ -o-transform: translate3d(0,0,0) rotate(0); } 50%{ -o-transform: translate3d(0,-8px,0) rotate(0); } 100%{ -o-transform: translate3d(0,-8px,0) rotate(-45deg); }}
|
||||
@keyframes hamburger-bottom{ 0%{-webkit-transform: translate3d(0,0,0) rotate(0);-moz-transform: translate3d(0,0,0) rotate(0);-ms-transform: translate3d(0,0,0) rotate(0);transform: translate3d(0,0,0) rotate(0); } 50%{-webkit-transform: translate3d(0,-8px,0) rotate(0);-moz-transform: translate3d(0,-8px,0) rotate(0);-ms-transform: translate3d(0,-8px,0) rotate(0);transform: translate3d(0,-8px,0) rotate(0); } 100%{-webkit-transform: translate3d(0,-8px,0) rotate(-45deg);-moz-transform: translate3d(0,-8px,0) rotate(-45deg);-ms-transform: translate3d(0,-8px,0) rotate(-45deg);transform: translate3d(0,-8px,0) rotate(-45deg); }
|
||||
}
|
||||
lesshat-selector {
|
||||
-lh-property: 0; }
|
||||
@-webkit-keyframes hamburger-top-reverse{ 100%{ -webkit-transform: translate3d(0,0,0) rotate(0); } 50%{ -webkit-transform: translate3d(0,8px,0) rotate(0); } 0%{ -webkit-transform: translate3d(0,8px,0) rotate(45deg); }}
|
||||
@-moz-keyframes hamburger-top-reverse{ 100%{ -moz-transform: translate3d(0,0,0) rotate(0); } 50%{ -moz-transform: translate3d(0,8px,0) rotate(0); } 0%{ -moz-transform: translate3d(0,8px,0) rotate(45deg); }}
|
||||
@-o-keyframes hamburger-top-reverse{ 100%{ -o-transform: translate3d(0,0,0) rotate(0); } 50%{ -o-transform: translate3d(0,8px,0) rotate(0); } 0%{ -o-transform: translate3d(0,8px,0) rotate(45deg); }}
|
||||
@keyframes hamburger-top-reverse{ 100%{-webkit-transform: translate3d(0,0,0) rotate(0);-moz-transform: translate3d(0,0,0) rotate(0);-ms-transform: translate3d(0,0,0) rotate(0);transform: translate3d(0,0,0) rotate(0); } 50%{-webkit-transform: translate3d(0,8px,0) rotate(0);-moz-transform: translate3d(0,8px,0) rotate(0);-ms-transform: translate3d(0,8px,0) rotate(0);transform: translate3d(0,8px,0) rotate(0); } 0%{-webkit-transform: translate3d(0,8px,0) rotate(45deg);-moz-transform: translate3d(0,8px,0) rotate(45deg);-ms-transform: translate3d(0,8px,0) rotate(45deg);transform: translate3d(0,8px,0) rotate(45deg); }
|
||||
}
|
||||
lesshat-selector {
|
||||
-lh-property: 0; }
|
||||
@-webkit-keyframes hamburger-middle-reverse{ 100%{ opacity:1; } 51%{ opacity:1; } 50%{ opacity: 0; } 0%{ opacity:0; }}
|
||||
@-moz-keyframes hamburger-middle-reverse{ 100%{ opacity:1; } 51%{ opacity:1; } 50%{ opacity: 0; } 0%{ opacity:0; }}
|
||||
@-o-keyframes hamburger-middle-reverse{ 100%{ opacity:1; } 51%{ opacity:1; } 50%{ opacity: 0; } 0%{ opacity:0; }}
|
||||
@keyframes hamburger-middle-reverse{ 100%{ opacity:1; } 51%{ opacity:1; } 50%{ opacity: 0; } 0%{ opacity:0; }
|
||||
}
|
||||
lesshat-selector {
|
||||
-lh-property: 0; }
|
||||
@-webkit-keyframes hamburger-bottom-reverse{ 100%{ -webkit-transform: translate3d(0,0,0) rotate(0); } 50%{ -webkit-transform: translate3d(0,-8px,0) rotate(0); } 0%{ -webkit-transform: translate3d(0,-8px,0) rotate(-45deg); }}
|
||||
@-moz-keyframes hamburger-bottom-reverse{ 100%{ -moz-transform: translate3d(0,0,0) rotate(0); } 50%{ -moz-transform: translate3d(0,-8px,0) rotate(0); } 0%{ -moz-transform: translate3d(0,-8px,0) rotate(-45deg); }}
|
||||
@-o-keyframes hamburger-bottom-reverse{ 100%{ -o-transform: translate3d(0,0,0) rotate(0); } 50%{ -o-transform: translate3d(0,-8px,0) rotate(0); } 0%{ -o-transform: translate3d(0,-8px,0) rotate(-45deg); }}
|
||||
@keyframes hamburger-bottom-reverse{ 100%{-webkit-transform: translate3d(0,0,0) rotate(0);-moz-transform: translate3d(0,0,0) rotate(0);-ms-transform: translate3d(0,0,0) rotate(0);transform: translate3d(0,0,0) rotate(0); } 50%{-webkit-transform: translate3d(0,-8px,0) rotate(0);-moz-transform: translate3d(0,-8px,0) rotate(0);-ms-transform: translate3d(0,-8px,0) rotate(0);transform: translate3d(0,-8px,0) rotate(0); } 0%{-webkit-transform: translate3d(0,-8px,0) rotate(-45deg);-moz-transform: translate3d(0,-8px,0) rotate(-45deg);-ms-transform: translate3d(0,-8px,0) rotate(-45deg);transform: translate3d(0,-8px,0) rotate(-45deg); }
|
||||
}
|
||||
body {
|
||||
-webkit-text-size-adjust: 100%;
|
||||
padding-left: 250px;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
@media only screen and (max-width: 978px) {
|
||||
body {
|
||||
padding-left: 200px;
|
||||
}
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
body {
|
||||
padding-left: 0px;
|
||||
padding-top: 40px;
|
||||
}
|
||||
body.open-menu aside {
|
||||
-webkit-transform: translateX(0);
|
||||
-moz-transform: translateX(0);
|
||||
-o-transform: translateX(0);
|
||||
-ms-transform: translateX(0);
|
||||
transform: translateX(0);
|
||||
}
|
||||
body.open-menu .docs-container {
|
||||
pointer-events: none;
|
||||
-webkit-transform: translateX(250px);
|
||||
-moz-transform: translateX(250px);
|
||||
-o-transform: translateX(250px);
|
||||
-ms-transform: translateX(250px);
|
||||
transform: translateX(250px);
|
||||
}
|
||||
}
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
color: #232830;
|
||||
}
|
||||
h1 {
|
||||
font-size: 42px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
h1 {
|
||||
font-size: 28px;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
}
|
||||
h2 {
|
||||
font-size: 32px;
|
||||
padding-top: 12px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
h2 {
|
||||
font-size: 22px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
}
|
||||
h3 {
|
||||
clear: both;
|
||||
font-size: 22px;
|
||||
margin-bottom: 12px;
|
||||
padding-top: 32px;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
h3 {
|
||||
font-size: 18px;
|
||||
}
|
||||
}
|
||||
h4 {
|
||||
font-size: 18px;
|
||||
margin-bottom: 10px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
h4 {
|
||||
font-size: 16px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
}
|
||||
p {
|
||||
color: #566076;
|
||||
margin-bottom: 12px;
|
||||
line-height: 22px;
|
||||
}
|
||||
p code {
|
||||
background-color: #fafafa;
|
||||
padding: 4px 8px;
|
||||
border-radius: 6px;
|
||||
color: #232830;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
p {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
code {
|
||||
font-family: 'source-code-pro', monospace;
|
||||
font-size: 14px;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
code {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
canvas {
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
.half {
|
||||
width: 50%;
|
||||
float: left;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
.half {
|
||||
float: none;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
.docs-container {
|
||||
padding: 40px 80px;
|
||||
max-width: 978px;
|
||||
margin: 0 auto;
|
||||
-webkit-transition: -webkit-transform 200ms ease-in-out;
|
||||
-moz-transition: -moz-transform 200ms ease-in-out;
|
||||
-o-transition: -o-transform 200ms ease-in-out;
|
||||
transition: -webkit-transform 200ms ease-in-out,-moz-transform 200ms ease-in-out,-o-transform 200ms ease-in-out,transform 200ms ease-in-out;
|
||||
}
|
||||
@media only screen and (max-width: 978px) {
|
||||
.docs-container {
|
||||
padding: 40px;
|
||||
}
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
.docs-container {
|
||||
padding: 20px;
|
||||
}
|
||||
}
|
||||
.highlight {
|
||||
padding: 8px 12px;
|
||||
margin: 20px 0;
|
||||
background-color: #fafafa;
|
||||
border-radius: 6px;
|
||||
overflow: scroll;
|
||||
overflow-x: visible;
|
||||
overflow-y: hidden;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
-ms-overflow-style: -ms-autohiding-scrollbar;
|
||||
}
|
||||
.intro h3 {
|
||||
color: #566076;
|
||||
font-weight: normal;
|
||||
}
|
||||
article {
|
||||
border-bottom: 1px solid #e1e1e1;
|
||||
padding-bottom: 40px;
|
||||
padding-top: 40px;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
article {
|
||||
padding-top: 20px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
}
|
||||
article:first-child {
|
||||
padding-top: 0;
|
||||
}
|
||||
article ul {
|
||||
padding-left: 20px;
|
||||
}
|
||||
article ul li {
|
||||
color: #566076;
|
||||
margin-bottom: 12px;
|
||||
line-height: 22px;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
article ul li {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
/* Styles for the tables in v2 documentation */
|
||||
table {
|
||||
margin-top: 10px;
|
||||
margin-bottom: 10px;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
th, td {
|
||||
border: 1px solid #e1e1e1;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
td {
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
thead {
|
||||
background-color:
|
||||
}
|
||||
|
||||
tbody tr:nth-child(even) {
|
||||
background-color: #ffffff
|
||||
}
|
||||
|
||||
tbody tr:nth-child(odd) {
|
||||
background-color: #eeeeee;
|
||||
}
|
||||
|
||||
/* Left navigation menu */
|
||||
aside {
|
||||
position: fixed;
|
||||
height: 100%;
|
||||
background-color: #232830;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 250px;
|
||||
border-right: 10px solid #5b90bf;
|
||||
z-index: 10;
|
||||
-webkit-transition: -webkit-transform 200ms ease-in-out;
|
||||
-moz-transition: -moz-transform 200ms ease-in-out;
|
||||
-o-transition: -o-transform 200ms ease-in-out;
|
||||
transition: -webkit-transform 200ms ease-in-out,-moz-transform 200ms ease-in-out,-o-transform 200ms ease-in-out,transform 200ms ease-in-out;
|
||||
}
|
||||
aside .hamburger-menu {
|
||||
display: none;
|
||||
cursor: pointer;
|
||||
padding: 10px;
|
||||
}
|
||||
aside .hamburger-menu li {
|
||||
list-style: none;
|
||||
height: 4px;
|
||||
margin-bottom: 4px;
|
||||
display: block;
|
||||
background-color: #fafafa;
|
||||
-webkit-transition: -webkit-transform 400ms ease-out;
|
||||
-moz-transition: -moz-transform 400ms ease-out;
|
||||
-o-transition: -o-transform 400ms ease-out;
|
||||
transition: -webkit-transform 400ms ease-out,-moz-transform 400ms ease-out,-o-transform 400ms ease-out,transform 400ms ease-out;
|
||||
}
|
||||
aside .hamburger-menu li:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
@media only screen and (max-width: 978px) {
|
||||
aside {
|
||||
width: 200px;
|
||||
}
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
aside {
|
||||
width: 250px;
|
||||
-webkit-transform: translateX(-250px);
|
||||
-moz-transform: translateX(-250px);
|
||||
-o-transform: translateX(-250px);
|
||||
-ms-transform: translateX(-250px);
|
||||
transform: translateX(-250px);
|
||||
}
|
||||
aside .hamburger-menu {
|
||||
display: block;
|
||||
position: absolute;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
top: 0;
|
||||
right: -50px;
|
||||
background-color: #232830;
|
||||
}
|
||||
.open-menu aside .hamburger-menu li {
|
||||
-webkit-animation: hamburger-middle 400ms ease-out forwards;
|
||||
-moz-animation: hamburger-middle 400ms ease-out forwards;
|
||||
-o-animation: hamburger-middle 400ms ease-out forwards;
|
||||
animation: hamburger-middle 400ms ease-out forwards;
|
||||
}
|
||||
.open-menu aside .hamburger-menu li:first-child {
|
||||
-webkit-animation: hamburger-top 400ms ease-out forwards;
|
||||
-moz-animation: hamburger-top 400ms ease-out forwards;
|
||||
-o-animation: hamburger-top 400ms ease-out forwards;
|
||||
animation: hamburger-top 400ms ease-out forwards;
|
||||
}
|
||||
.open-menu aside .hamburger-menu li:last-child {
|
||||
-webkit-animation: hamburger-bottom 400ms ease-out forwards;
|
||||
-moz-animation: hamburger-bottom 400ms ease-out forwards;
|
||||
-o-animation: hamburger-bottom 400ms ease-out forwards;
|
||||
animation: hamburger-bottom 400ms ease-out forwards;
|
||||
}
|
||||
.closed-menu aside .hamburger-menu li {
|
||||
-webkit-animation: hamburger-middle-reverse 400ms ease-out forwards;
|
||||
-moz-animation: hamburger-middle-reverse 400ms ease-out forwards;
|
||||
-o-animation: hamburger-middle-reverse 400ms ease-out forwards;
|
||||
animation: hamburger-middle-reverse 400ms ease-out forwards;
|
||||
}
|
||||
.closed-menu aside .hamburger-menu li:first-child {
|
||||
-webkit-animation: hamburger-top-reverse 400ms ease-out forwards;
|
||||
-moz-animation: hamburger-top-reverse 400ms ease-out forwards;
|
||||
-o-animation: hamburger-top-reverse 400ms ease-out forwards;
|
||||
animation: hamburger-top-reverse 400ms ease-out forwards;
|
||||
}
|
||||
.closed-menu aside .hamburger-menu li:last-child {
|
||||
-webkit-animation: hamburger-bottom-reverse 400ms ease-out forwards;
|
||||
-moz-animation: hamburger-bottom-reverse 400ms ease-out forwards;
|
||||
-o-animation: hamburger-bottom-reverse 400ms ease-out forwards;
|
||||
animation: hamburger-bottom-reverse 400ms ease-out forwards;
|
||||
}
|
||||
}
|
||||
aside nav {
|
||||
height: 100%;
|
||||
padding-bottom: 20px;
|
||||
overflow: auto;
|
||||
overflow-x: hidden;
|
||||
overflow-y: scroll;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
-ms-overflow-style: -ms-autohiding-scrollbar;
|
||||
}
|
||||
aside nav li {
|
||||
display: block;
|
||||
}
|
||||
aside nav li a {
|
||||
display: block;
|
||||
color: #fafafa;
|
||||
padding: 10px 12px;
|
||||
text-decoration: none;
|
||||
-webkit-transition: background-color 200ms ease-in-out;
|
||||
-moz-transition: background-color 200ms ease-in-out;
|
||||
-o-transition: background-color 200ms ease-in-out;
|
||||
transition: background-color 200ms ease-in-out;
|
||||
}
|
||||
aside nav li a:hover {
|
||||
background-color: #2b303b;
|
||||
}
|
||||
aside .subsection-navigation li {
|
||||
font-size: 12px;
|
||||
margin-left: 12px;
|
||||
border-left: 1px solid #2b303b;
|
||||
}
|
||||
aside .subsection-navigation li a {
|
||||
padding: 6px 12px;
|
||||
}
|
||||
Diff do arquivo suprimido porque uma ou mais linhas são muito longas
|
Depois Largura: | Altura: | Tamanho: 66 KiB |
@@ -0,0 +1,404 @@
|
||||
* {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
color: inherit;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
*,
|
||||
*:before,
|
||||
*:after {
|
||||
-webkit-box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
position: relative;
|
||||
font-family: "proxima-nova", 'Helvetica Neue', 'Helvetica', 'sans-serif';
|
||||
color: #232830;
|
||||
}
|
||||
lesshat-selector {
|
||||
-lh-property: 0; }
|
||||
::selection{color: #dfe1e8; background: #5b90bf}
|
||||
::-moz-selection{color: #dfe1e8; background: #5b90bf;
|
||||
}
|
||||
.aspect-ratio {
|
||||
width: 100%;
|
||||
padding-bottom: 40%;
|
||||
position: relative;
|
||||
background-color: #232830;
|
||||
border-bottom: 10px solid #5b90bf;
|
||||
}
|
||||
header {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
top: 50%;
|
||||
-webkit-transform: translateY(-50%);
|
||||
-moz-transform: translateY(-50%);
|
||||
-o-transform: translateY(-50%);
|
||||
-ms-transform: translateY(-50%);
|
||||
transform: translateY(-50%);
|
||||
text-align: center;
|
||||
color: #dfe1e8;
|
||||
z-index: 3;
|
||||
}
|
||||
header h1 {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
header h2 {
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
header {
|
||||
color: #232830;
|
||||
top: 100%;
|
||||
margin-top: 10px;
|
||||
padding: 40px 10px;
|
||||
background-color: #fafafa;
|
||||
border-bottom: 1px solid #e1e1e1;
|
||||
-webkit-transform: translateY(0%);
|
||||
-moz-transform: translateY(0%);
|
||||
-o-transform: translateY(0%);
|
||||
-ms-transform: translateY(0%);
|
||||
transform: translateY(0%);
|
||||
}
|
||||
header h1 {
|
||||
font-size: 38px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
header h2 {
|
||||
font-size: 16px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
header .btn {
|
||||
min-width: 136px;
|
||||
font-size: 14px;
|
||||
padding: 18px 20px;
|
||||
margin: 0 5px;
|
||||
}
|
||||
}
|
||||
.content-main {
|
||||
background-color: #fff;
|
||||
z-index: 2;
|
||||
position: relative;
|
||||
max-width: 1440px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
.content-main {
|
||||
padding-top: 256px;
|
||||
}
|
||||
}
|
||||
.container {
|
||||
margin: 0 auto;
|
||||
}
|
||||
.container:after {
|
||||
content: '';
|
||||
display: table;
|
||||
}
|
||||
.canvas-holder {
|
||||
padding: 4px 0;
|
||||
margin: 20px 0;
|
||||
position: relative;
|
||||
}
|
||||
.canvas-holder img {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
.aspect-spacer {
|
||||
width: 100% !important;
|
||||
height: auto !important;
|
||||
display: inline-block;
|
||||
}
|
||||
.canvas-node-demo {
|
||||
position: relative;
|
||||
}
|
||||
.canvas-node-demo code {
|
||||
z-index: -1;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
top: 50%;
|
||||
-webkit-transform: translateY(-50%);
|
||||
-moz-transform: translateY(-50%);
|
||||
-o-transform: translateY(-50%);
|
||||
-ms-transform: translateY(-50%);
|
||||
transform: translateY(-50%);
|
||||
font-family: "proxima-nova", 'Helvetica Neue', 'Helvetica', 'sans-serif';
|
||||
text-align: center;
|
||||
color: #b0bace;
|
||||
}
|
||||
.canvas-node-demo .operator {
|
||||
font-size: 36px;
|
||||
}
|
||||
.canvas-node-demo .node-name {
|
||||
font-size: 50px;
|
||||
}
|
||||
.labeled-chart-container {
|
||||
padding-right: 150px;
|
||||
min-height: 180px;
|
||||
position: relative;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
.labeled-chart-container {
|
||||
padding-right: 130px;
|
||||
}
|
||||
}
|
||||
.doughnut-legend {
|
||||
list-style: none;
|
||||
position: absolute;
|
||||
right: 8px;
|
||||
top: 0;
|
||||
}
|
||||
.doughnut-legend li {
|
||||
display: block;
|
||||
padding-left: 30px;
|
||||
position: relative;
|
||||
margin-bottom: 4px;
|
||||
border-radius: 5px;
|
||||
padding: 2px 8px 2px 28px;
|
||||
font-size: 14px;
|
||||
cursor: default;
|
||||
-webkit-transition: background-color 200ms ease-in-out;
|
||||
-moz-transition: background-color 200ms ease-in-out;
|
||||
-o-transition: background-color 200ms ease-in-out;
|
||||
transition: background-color 200ms ease-in-out;
|
||||
}
|
||||
.doughnut-legend li:hover {
|
||||
background-color: #fafafa;
|
||||
}
|
||||
.doughnut-legend li span {
|
||||
display: block;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 20px;
|
||||
height: 100%;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.carousel {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
}
|
||||
.carousel canvas {
|
||||
display: inline-block;
|
||||
-webkit-transition: -webkit-transform 400ms ease-out;
|
||||
-moz-transition: -moz-transform 400ms ease-out;
|
||||
-o-transition: -o-transform 400ms ease-out;
|
||||
transition: -webkit-transform 400ms ease-out,-moz-transform 400ms ease-out,-o-transform 400ms ease-out,transform 400ms ease-out;
|
||||
}
|
||||
.position-6 canvas {
|
||||
-webkit-transform: translateX(-500%);
|
||||
-moz-transform: translateX(-500%);
|
||||
-o-transform: translateX(-500%);
|
||||
-ms-transform: translateX(-500%);
|
||||
transform: translateX(-500%);
|
||||
}
|
||||
.position-5 canvas {
|
||||
-webkit-transform: translateX(-400%);
|
||||
-moz-transform: translateX(-400%);
|
||||
-o-transform: translateX(-400%);
|
||||
-ms-transform: translateX(-400%);
|
||||
transform: translateX(-400%);
|
||||
}
|
||||
.position-4 canvas {
|
||||
-webkit-transform: translateX(-300%);
|
||||
-moz-transform: translateX(-300%);
|
||||
-o-transform: translateX(-300%);
|
||||
-ms-transform: translateX(-300%);
|
||||
transform: translateX(-300%);
|
||||
}
|
||||
.position-3 canvas {
|
||||
-webkit-transform: translateX(-200%);
|
||||
-moz-transform: translateX(-200%);
|
||||
-o-transform: translateX(-200%);
|
||||
-ms-transform: translateX(-200%);
|
||||
transform: translateX(-200%);
|
||||
}
|
||||
.position-2 canvas {
|
||||
-webkit-transform: translateX(-100%);
|
||||
-moz-transform: translateX(-100%);
|
||||
-o-transform: translateX(-100%);
|
||||
-ms-transform: translateX(-100%);
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
.position-1 canvas {
|
||||
-webkit-transform: translateX(0%);
|
||||
-moz-transform: translateX(0%);
|
||||
-o-transform: translateX(0%);
|
||||
-ms-transform: translateX(0%);
|
||||
transform: translateX(0%);
|
||||
}
|
||||
.hover-highlight {
|
||||
border-radius: 10px;
|
||||
-webkit-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
-webkit-transition: background-color 200ms ease-in-out;
|
||||
-moz-transition: background-color 200ms ease-in-out;
|
||||
-o-transition: background-color 200ms ease-in-out;
|
||||
transition: background-color 200ms ease-in-out;
|
||||
}
|
||||
.hover-highlight:hover {
|
||||
background-color: rgba(239, 241, 245, 0.3);
|
||||
border-radius: 10px;
|
||||
}
|
||||
.hover-highlight canvas {
|
||||
cursor: pointer;
|
||||
}
|
||||
#hero-bar {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
}
|
||||
h1 {
|
||||
font-size: 62px;
|
||||
font-weight: 600;
|
||||
}
|
||||
@media only screen and (max-width: 978px) {
|
||||
h1 {
|
||||
font-size: 48px;
|
||||
}
|
||||
}
|
||||
h2 {
|
||||
font-weight: 400;
|
||||
}
|
||||
h3 {
|
||||
text-align: center;
|
||||
}
|
||||
p {
|
||||
margin: 20px 0;
|
||||
text-align: center;
|
||||
font-size: 18px;
|
||||
line-height: 28px;
|
||||
}
|
||||
a {
|
||||
color: #5b90bf;
|
||||
text-decoration: none;
|
||||
border-bottom: 1px solid;
|
||||
}
|
||||
.features article {
|
||||
width: 33.33%;
|
||||
padding: 40px;
|
||||
float: left;
|
||||
}
|
||||
@media only screen and (max-width: 978px) {
|
||||
.features article {
|
||||
width: 50%;
|
||||
}
|
||||
.features article:nth-child(2n+1) {
|
||||
clear: left;
|
||||
}
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
.features article {
|
||||
width: auto;
|
||||
float: none;
|
||||
border-bottom: 1px solid #e1e1e1;
|
||||
padding: 20px 12px;
|
||||
}
|
||||
.features article:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
}
|
||||
.features h3 {
|
||||
margin: 40px 0 60px 0;
|
||||
font-size: 32px;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
.features h3 {
|
||||
font-size: 28px;
|
||||
}
|
||||
}
|
||||
.btn {
|
||||
margin: 0 10px;
|
||||
padding: 18px 26px;
|
||||
min-width: 220px;
|
||||
border: none;
|
||||
text-align: center;
|
||||
display: inline-block;
|
||||
text-decoration: none;
|
||||
background-color: #1C1F26;
|
||||
border-radius: 5px;
|
||||
font-size: 18px;
|
||||
color: #dfe1e8;
|
||||
-webkit-transition: 200ms background-color;
|
||||
-moz-transition: 200ms background-color;
|
||||
-o-transition: 200ms background-color;
|
||||
transition: 200ms background-color;
|
||||
}
|
||||
.btn.red {
|
||||
background-color: #bf616a;
|
||||
}
|
||||
.btn.red:hover {
|
||||
background-color: #b9525c;
|
||||
}
|
||||
.btn.blue {
|
||||
background-color: #5b90bf;
|
||||
}
|
||||
.btn.blue:hover {
|
||||
background-color: #4c86b9;
|
||||
}
|
||||
.documentation-button-container {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.badge {
|
||||
background-color: #ebcb8b;
|
||||
padding: 4px 8px;
|
||||
font-size: 14px;
|
||||
border-radius: 6px;
|
||||
color: #fff;
|
||||
vertical-align: top;
|
||||
margin-left: 4px;
|
||||
}
|
||||
footer {
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
clear: both;
|
||||
}
|
||||
.download-banner {
|
||||
padding: 60px 12px;
|
||||
background-color: #eff1f5;
|
||||
}
|
||||
.download-banner h2 {
|
||||
line-height: 40px;
|
||||
}
|
||||
.download-banner h2 span {
|
||||
padding: 0 5px;
|
||||
}
|
||||
@media only screen and (max-width: 600px) {
|
||||
.download-banner h2 {
|
||||
line-height: normal;
|
||||
font-size: 22px;
|
||||
}
|
||||
.download-banner h2 span {
|
||||
display: block;
|
||||
margin: 12px 0;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
.owner-notice {
|
||||
padding: 20px 12px;
|
||||
background-color: #232830;
|
||||
color: rgba(250, 250, 250, 0.3);
|
||||
border-top: 10px solid #5b90bf;
|
||||
-webkit-transition: color 200ms ease-out;
|
||||
-moz-transition: color 200ms ease-out;
|
||||
-o-transition: color 200ms ease-out;
|
||||
transition: color 200ms ease-out;
|
||||
}
|
||||
.owner-notice a {
|
||||
color: rgba(250, 250, 250, 0.3);
|
||||
-webkit-transition: color 200ms ease-out;
|
||||
-moz-transition: color 200ms ease-out;
|
||||
-o-transition: color 200ms ease-out;
|
||||
transition: color 200ms ease-out;
|
||||
}
|
||||
.owner-notice:hover {
|
||||
color: #fafafa;
|
||||
}
|
||||
.owner-notice:hover a {
|
||||
color: #fafafa;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"name": "Chart.js",
|
||||
"version": "1.0.2",
|
||||
"description": "Simple HTML5 Charts using the canvas element",
|
||||
"homepage": "https://github.com/nnnick/Chart.js",
|
||||
"author": "nnnick",
|
||||
"main": [
|
||||
"Chart.js"
|
||||
],
|
||||
"dependencies": {}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
---
|
||||
---
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Chart.js | Documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="../assets/docs.css">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimal-ui">
|
||||
<script type="text/javascript" src="//use.typekit.net/dqv7hih.js"></script>
|
||||
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<aside id="js-toggle-menu">
|
||||
<ul class="hamburger-menu">
|
||||
<li></li>
|
||||
<li></li>
|
||||
<li></li>
|
||||
</ul>
|
||||
<nav>
|
||||
<ul>
|
||||
{% for doc in site.collections[1].docs %}
|
||||
<li id="link-{{ doc.anchor }}">
|
||||
<a href="#{{ doc.anchor }}">{{ doc.title | escape }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</nav>
|
||||
</aside>
|
||||
<section class="docs-container">
|
||||
<article class="intro">
|
||||
<h1>Chart.js V2 Documentation</h1>
|
||||
<h3>Everything you need to know to build great looking charts using Chart.js</h3>
|
||||
</article>
|
||||
|
||||
{% for doc in site.collections[1].docs %}
|
||||
<article id="{{ doc.anchor }}">
|
||||
<h2>{{ doc.title | escape }}</h2>
|
||||
{{ doc.content }}
|
||||
</article>
|
||||
{% endfor %}
|
||||
</section>
|
||||
|
||||
<script src="../assets/Chart.min.js"></script>
|
||||
<script>!function(){var e=Chart.helpers;Chart.defaults.global.responsive=!0,Chart.defaults.global.animation=!1;var t=document.getElementById("js-toggle-menu");e.addEvent(t,"click",function(){document.body.className=-1!==document.body.className.indexOf("open-menu")?"closed-menu":"open-menu"});var n=document.getElementsByTagName("article");e.each(n,function(t){if(t.id){var n=t.getElementsByTagName("canvas"),a=t.getElementsByTagName("h3"),l=t.querySelectorAll(".javascript"),i=Array.prototype.slice.call(l,0,2);if(articleId=t.id,list=document.createElement("ul"),navigationItem=document.getElementById("link-"+articleId),list.className="subsection-navigation",e.each(a,function(e){var t=document.createElement("li");e.id=articleId+"-"+e.textContent.replace(/\s+/g,"-").toLowerCase(),t.innerHTML='<a href="#'+e.id+'">'+e.textContent+"</a>",list.appendChild(t)}),a.length>0&&navigationItem.appendChild(list),n.length>0){var o="",c=[];e.each(n,function(e){c.push(e.getContext("2d"))}),c=c.length>1?c:c[0];for(var d=i.length-1;d>=0;d--)o+=i[d].textContent;new Function("ctx","options",o)(c)}}})}();</script>
|
||||
<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-28909194-3', 'auto');
|
||||
ga('send', 'pageview');</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,57 @@
|
||||
---
|
||||
---
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Chart.js | Documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="../assets/docs.css">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimal-ui">
|
||||
<script type="text/javascript" src="//use.typekit.net/dqv7hih.js"></script>
|
||||
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<aside id="js-toggle-menu">
|
||||
<ul class="hamburger-menu">
|
||||
<li></li>
|
||||
<li></li>
|
||||
<li></li>
|
||||
</ul>
|
||||
<nav>
|
||||
<ul>
|
||||
{% for doc in site.collections[0].docs %}
|
||||
<li id="link-{{ doc.anchor }}">
|
||||
<a href="#{{ doc.anchor }}">{{ doc.title | escape }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</nav>
|
||||
</aside>
|
||||
<section class="docs-container">
|
||||
<article class="intro">
|
||||
<h1>Chart.js V1 Documentation</h1>
|
||||
<h3>Everything you need to know to build great looking charts using Chart.js</h3>
|
||||
</article>
|
||||
|
||||
{% for doc in site.collections[0].docs %}
|
||||
<article id="{{ doc.anchor }}">
|
||||
<h2>{{ doc.title | escape }}</h2>
|
||||
{{ doc.content }}
|
||||
</article>
|
||||
{% endfor %}
|
||||
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
<script src="../assets/Chart.min.js"></script>
|
||||
<script>!function(){var e=Chart.helpers;Chart.defaults.global.responsive=!0,Chart.defaults.global.animation=!1;var t=document.getElementById("js-toggle-menu");e.addEvent(t,"click",function(){document.body.className=-1!==document.body.className.indexOf("open-menu")?"closed-menu":"open-menu"});var n=document.getElementsByTagName("article");e.each(n,function(t){if(t.id){var n=t.getElementsByTagName("canvas"),a=t.getElementsByTagName("h3"),l=t.querySelectorAll(".javascript"),i=Array.prototype.slice.call(l,0,2);if(articleId=t.id,list=document.createElement("ul"),navigationItem=document.getElementById("link-"+articleId),list.className="subsection-navigation",e.each(a,function(e){var t=document.createElement("li");e.id=articleId+"-"+e.textContent.replace(/\s+/g,"-").toLowerCase(),t.innerHTML='<a href="#'+e.id+'">'+e.textContent+"</a>",list.appendChild(t)}),a.length>0&&navigationItem.appendChild(list),n.length>0){var o="",c=[];e.each(n,function(e){c.push(e.getContext("2d"))}),c=c.length>1?c:c[0];for(var d=i.length-1;d>=0;d--)o+=i[d].textContent;new Function("ctx","options",o)(c)}}})}();</script>
|
||||
<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-28909194-3', 'auto');
|
||||
ga('send', 'pageview');</script>
|
||||
</body>
|
||||
</html>
|
||||
-137
@@ -1,137 +0,0 @@
|
||||
var gulp = require('gulp'),
|
||||
concat = require('gulp-concat'),
|
||||
uglify = require('gulp-uglify'),
|
||||
util = require('gulp-util'),
|
||||
jshint = require('gulp-jshint'),
|
||||
size = require('gulp-size'),
|
||||
connect = require('gulp-connect'),
|
||||
replace = require('gulp-replace'),
|
||||
htmlv = require('gulp-html-validator'),
|
||||
inquirer = require('inquirer'),
|
||||
semver = require('semver'),
|
||||
exec = require('child_process').exec,
|
||||
fs = require('fs'),
|
||||
package = require('./package.json'),
|
||||
bower = require('./bower.json');
|
||||
|
||||
var srcDir = './src/';
|
||||
/*
|
||||
* Usage : gulp build --types=Bar,Line,Doughnut
|
||||
* Output: - A built Chart.js file with Core and types Bar, Line and Doughnut concatenated together
|
||||
* - A minified version of this code, in Chart.min.js
|
||||
*/
|
||||
|
||||
gulp.task('build', function(){
|
||||
|
||||
// Default to all of the chart types, with Chart.Core first
|
||||
var srcFiles = [FileName('Core')],
|
||||
isCustom = !!(util.env.types),
|
||||
outputDir = (isCustom) ? 'custom' : '.';
|
||||
if (isCustom){
|
||||
util.env.types.split(',').forEach(function(type){ return srcFiles.push(FileName(type))});
|
||||
}
|
||||
else{
|
||||
// Seems gulp-concat remove duplicates - nice!
|
||||
// So we can use this to sort out dependency order - aka include Core first!
|
||||
srcFiles.push(srcDir+'*');
|
||||
}
|
||||
|
||||
return gulp.src(srcFiles)
|
||||
.pipe(concat('Chart.js'))
|
||||
.pipe(replace('{{ version }}', package.version))
|
||||
.pipe(gulp.dest(outputDir))
|
||||
.pipe(uglify({preserveComments:'some'}))
|
||||
.pipe(concat('Chart.min.js'))
|
||||
.pipe(gulp.dest(outputDir));
|
||||
|
||||
function FileName(moduleName){
|
||||
return srcDir+'Chart.'+moduleName+'.js';
|
||||
};
|
||||
});
|
||||
|
||||
/*
|
||||
* Usage : gulp bump
|
||||
* Prompts: Version increment to bump
|
||||
* Output: - New version number written into package.json & bower.json
|
||||
*/
|
||||
|
||||
gulp.task('bump', function(complete){
|
||||
util.log('Current version:', util.colors.cyan(package.version));
|
||||
var choices = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'].map(function(versionType){
|
||||
return versionType + ' (v' + semver.inc(package.version, versionType) + ')';
|
||||
});
|
||||
inquirer.prompt({
|
||||
type: 'list',
|
||||
name: 'version',
|
||||
message: 'What version update would you like?',
|
||||
choices: choices
|
||||
}, function(res){
|
||||
var increment = res.version.split(' ')[0],
|
||||
newVersion = semver.inc(package.version, increment);
|
||||
|
||||
// Set the new versions into the bower/package object
|
||||
package.version = newVersion;
|
||||
bower.version = newVersion;
|
||||
|
||||
// Write these to their own files, then build the output
|
||||
fs.writeFileSync('package.json', JSON.stringify(package, null, 2));
|
||||
fs.writeFileSync('bower.json', JSON.stringify(bower, null, 2));
|
||||
|
||||
complete();
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('release', ['build'], function(){
|
||||
exec('git tag -a v' + package.version);
|
||||
});
|
||||
|
||||
gulp.task('jshint', function(){
|
||||
return gulp.src(srcDir + '*.js')
|
||||
.pipe(jshint())
|
||||
.pipe(jshint.reporter('default'));
|
||||
});
|
||||
|
||||
gulp.task('valid', function(){
|
||||
return gulp.src('samples/*.html')
|
||||
.pipe(htmlv());
|
||||
});
|
||||
|
||||
gulp.task('library-size', function(){
|
||||
return gulp.src('Chart.min.js')
|
||||
.pipe(size({
|
||||
gzip: true
|
||||
}));
|
||||
});
|
||||
|
||||
gulp.task('module-sizes', function(){
|
||||
return gulp.src(srcDir + '*.js')
|
||||
.pipe(uglify({preserveComments:'some'}))
|
||||
.pipe(size({
|
||||
showFiles: true,
|
||||
gzip: true
|
||||
}))
|
||||
});
|
||||
|
||||
gulp.task('watch', function(){
|
||||
gulp.watch('./src/*', ['build']);
|
||||
});
|
||||
|
||||
gulp.task('test', ['jshint', 'valid']);
|
||||
|
||||
gulp.task('size', ['library-size', 'module-sizes']);
|
||||
|
||||
gulp.task('default', ['build', 'watch']);
|
||||
|
||||
gulp.task('server', function(){
|
||||
connect.server({
|
||||
port: 8000
|
||||
});
|
||||
});
|
||||
|
||||
// Convenience task for opening the project straight from the command line
|
||||
gulp.task('_open', function(){
|
||||
exec('open http://localhost:8000');
|
||||
exec('subl .');
|
||||
});
|
||||
|
||||
gulp.task('dev', ['server', 'default']);
|
||||
+558
@@ -0,0 +1,558 @@
|
||||
---
|
||||
---
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Chart.js | Open source HTML5 Charts for your website</title>
|
||||
<meta name="description" content="Simple, clean and engaging HTML5 based JavaScript charts. Chart.js is an easy way to include animated, interactive graphs on your website for free."/>
|
||||
<link rel="stylesheet" type="text/css" href="assets/styles.css">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimal-ui">
|
||||
<script type="text/javascript" src="//use.typekit.net/dqv7hih.js"></script>
|
||||
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div class="aspect-ratio">
|
||||
<canvas width='1200' height='480' id="hero-bar"></canvas>
|
||||
<header>
|
||||
<h1>Chart.js</h1>
|
||||
<h2>Simple, clean and engaging charts for designers and developers</h2>
|
||||
<a class="btn red" href="https://github.com/nnnick/Chart.js">Download</a>
|
||||
<div class="documentation-button-container">
|
||||
<a class="btn blue" href="{{ site.baseurl }}/docs">V1 Documentation</a>
|
||||
<a class="btn blue" href="{{ site.baseurl }}/docs-v2">V2 Documentation</a>
|
||||
</div>
|
||||
</header>
|
||||
</div>
|
||||
<div class="content-main">
|
||||
<section class="features container">
|
||||
<article>
|
||||
<h3>Six chart types</h3>
|
||||
<div id="js-carousel" class="canvas-holder hover-highlight carousel position-1"><canvas width="400" height="250" id="carousel-radar"></canvas><canvas width="400" height="250" id="carousel-polar-area"></canvas><canvas width="400" height="250" id="carousel-bar"></canvas><canvas width="400" height="250" id="carousel-doughnut"></canvas><canvas width="400" height="250" id="carousel-line"></canvas><canvas width="400" height="250" id="carousel-pie"></canvas></div>
|
||||
<p>Visualize your data in 6 different ways. Each of them animated, with a load of customisation options and interactivity extensions.</p>
|
||||
</article>
|
||||
<article>
|
||||
<h3>HTML5 based</h3>
|
||||
<div id="js-mouse-bubbles" class="canvas-holder canvas-node-demo hover-highlight">
|
||||
<code>
|
||||
<span class="operator"><</span><span class="node-name">canvas</span><span class="operator">></span>
|
||||
</code>
|
||||
<canvas width="400" height="250" class="aspect-spacer"></canvas>
|
||||
</div>
|
||||
<p>Chart.js uses the HTML5 canvas element. It's supported in all modern browsers, and polyfills support for IE7/8.</p>
|
||||
</article>
|
||||
<article>
|
||||
<h3>Simple and flexible</h3>
|
||||
<div class="canvas-holder hover-highlight">
|
||||
<canvas width="400" height="250" id="micro-line"></canvas>
|
||||
</div>
|
||||
<p>Chart.js is dependency free and super lightweight. All six core chart types are only <strong>11.01kb</strong> when minified, concatenated and served gzipped.</p>
|
||||
</article>
|
||||
<article>
|
||||
<h3>Responsive <span class="badge new">new</span></h3>
|
||||
<div class="canvas-holder">
|
||||
<img width="400" height="250" src="assets/responsive.svg"/>
|
||||
</div>
|
||||
<p>Chart.js will resize your chart if the browser changes size, along with providing the perfect scale granularity for that size</p>
|
||||
</article>
|
||||
<article>
|
||||
<h3>Modular <span class="badge new">new</span></h3>
|
||||
<div class="labeled-chart-container">
|
||||
<div class="canvas-holder">
|
||||
<canvas id="modular-doughnut" width="250" height="250">
|
||||
</canvas>
|
||||
</div>
|
||||
</div>
|
||||
<p>Chart.js is modular, and each of the chart types have been split up, so you can load only which chart types you need for your project</p>
|
||||
</article>
|
||||
<article>
|
||||
<h3>Interactive <span class="badge new">new</span></h3>
|
||||
<div class="canvas-holder half">
|
||||
<canvas id="interactive-bar" width="400" height="250">
|
||||
</canvas>
|
||||
</div>
|
||||
<p>Chart.js provides default simple support for canvas tooltips on hover/touch, but you can extend chart interactions to trigger events in your application</p>
|
||||
</article>
|
||||
</section>
|
||||
</div>
|
||||
<footer>
|
||||
<div class="download-banner">
|
||||
<h2><a href="https://github.com/nnnick/Chart.js">Download on GitHub</a><span> or </span><a href="/docs">Read detailed documentation</a></h2>
|
||||
</div>
|
||||
<div class="owner-notice">
|
||||
A project by <a href="http://www.nickdownie.com">Nick Downie</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="assets/Chart.min.js"></script>
|
||||
<script>(function(){
|
||||
// Colour variables
|
||||
var red = "#bf616a",
|
||||
blue = "#5B90BF",
|
||||
orange = "#d08770",
|
||||
yellow = "#ebcb8b",
|
||||
green = "#a3be8c",
|
||||
teal = "#96b5b4",
|
||||
pale_blue = "#8fa1b3",
|
||||
purple = "#b48ead",
|
||||
brown = "#ab7967";
|
||||
|
||||
|
||||
var baseDataset = {
|
||||
fill: 'rgba(222,225,232,0.4)',
|
||||
stroke: 'rgba(222,225,232,1)',
|
||||
highlight: 'rgba(222,225,232,0.8)',
|
||||
highlightStroke: 'rgba(222,225,232,1)'
|
||||
},
|
||||
overlayDataset = {
|
||||
fill: 'rgba(91,144,191,0.4)',
|
||||
stroke: 'rgba(91,144,191,1)',
|
||||
highlight: 'rgba(91,144,191,0.8)',
|
||||
highlightStroke: 'rgba(91,144,191,1)'
|
||||
};
|
||||
|
||||
var data = [],
|
||||
barsCount = 50,
|
||||
labels = new Array(barsCount),
|
||||
updateDelayMax = 500,
|
||||
$id = function(id){
|
||||
return document.getElementById(id);
|
||||
},
|
||||
random = function(max){ return Math.round(Math.random()*100)},
|
||||
helpers = Chart.helpers;
|
||||
|
||||
|
||||
Chart.defaults.global.responsive = true;
|
||||
|
||||
|
||||
for (var i = barsCount - 1; i >= 0; i--) {
|
||||
data.push(Math.round(Math.random() * 100));
|
||||
};
|
||||
new Chart($id('hero-bar').getContext('2d')).Bar({
|
||||
labels : labels,
|
||||
datasets : [{
|
||||
fillColor : '#2B303B',
|
||||
data : data
|
||||
}]
|
||||
},{
|
||||
showScale : false,
|
||||
barShowStroke : false,
|
||||
barValueSpacing: 1,
|
||||
showTooltips : false,
|
||||
onAnimationComplete : function(){
|
||||
// Get scope of the hero chart during updates
|
||||
var heroChart = this,
|
||||
timeout;
|
||||
// Stop this running every time the update is fired
|
||||
this.options.onAnimationComplete = randomUpdate;
|
||||
|
||||
this.options.animationEasing = 'easeOutQuint';
|
||||
|
||||
randomUpdate();
|
||||
|
||||
function randomUpdate(){
|
||||
heroChart.stop();
|
||||
clearTimeout(timeout);
|
||||
// Get a random bar
|
||||
timeout = setTimeout(function(){
|
||||
var randomNumberOfBars = Math.floor(Math.random() * barsCount),
|
||||
i;
|
||||
for (i = randomNumberOfBars - 1; i >= 0; i--) {
|
||||
heroChart.datasets[0].bars[Math.floor(Math.random() * barsCount)].value = Math.round(Math.random() * 100);
|
||||
};
|
||||
heroChart.update();
|
||||
},Math.random() * updateDelayMax);
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//Run any of the smaller demo charts here.
|
||||
|
||||
// Six up carousel
|
||||
(function(){
|
||||
var contexts = {
|
||||
polar : $id('carousel-polar-area').getContext('2d'),
|
||||
radar : $id('carousel-radar').getContext('2d'),
|
||||
line : $id('carousel-line').getContext('2d'),
|
||||
bar : $id('carousel-bar').getContext('2d'),
|
||||
doughnut : $id('carousel-doughnut').getContext('2d'),
|
||||
pie : $id('carousel-pie').getContext('2d')
|
||||
},
|
||||
chartInstances = [];
|
||||
|
||||
var data = {
|
||||
multiSets: {
|
||||
labels: ["January", "February", "March", "April", "May", "June", "July"],
|
||||
datasets: [
|
||||
{
|
||||
label: "My First dataset",
|
||||
fillColor: baseDataset.fill,
|
||||
strokeColor: baseDataset.stroke,
|
||||
pointColor: baseDataset.stroke,
|
||||
pointStrokeColor: "#fff",
|
||||
pointHighlightFill: "#fff",
|
||||
highlightFill: baseDataset.highlight,
|
||||
pointHighlightStroke: baseDataset.highlightStroke,
|
||||
data: [65, 59, 90, 81, 56, 55, 40]
|
||||
},
|
||||
{
|
||||
label: "My Second dataset",
|
||||
fillColor: overlayDataset.fill,
|
||||
strokeColor: overlayDataset.stroke,
|
||||
pointColor: overlayDataset.stroke,
|
||||
pointStrokeColor: "#fff",
|
||||
pointHighlightFill: "#fff",
|
||||
pointHighlightStroke: overlayDataset.highlightStroke,
|
||||
highlightFill: overlayDataset.highlight,
|
||||
data: [28, 48, 40, 19, 96, 27, 100]
|
||||
}
|
||||
]
|
||||
},
|
||||
segments : [
|
||||
{
|
||||
value : 25,
|
||||
color : orange,
|
||||
highlight : Colour(orange, 10),
|
||||
label : "Orange"
|
||||
},
|
||||
{
|
||||
value: 14,
|
||||
color: blue,
|
||||
highlight : Colour(blue, 10),
|
||||
label : "Blue"
|
||||
},
|
||||
{
|
||||
value: 6,
|
||||
color: yellow,
|
||||
highlight : Colour(yellow, 10),
|
||||
label : "Yellow"
|
||||
},
|
||||
{
|
||||
value : 28,
|
||||
color : purple,
|
||||
highlight : Colour(purple, 10),
|
||||
label : "Purple"
|
||||
},
|
||||
{
|
||||
value: 18,
|
||||
color: teal,
|
||||
highlight: Colour(teal, 10),
|
||||
label: "Teal"
|
||||
}
|
||||
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
var config = {
|
||||
animation: false,
|
||||
onAnimationComplete: function(){
|
||||
this.options.animation = true;
|
||||
}
|
||||
};
|
||||
chartInstances.push(new Chart(contexts.radar).Radar(data.multiSets, config));
|
||||
chartInstances.push(new Chart(contexts.polar).PolarArea(data.segments, config));
|
||||
chartInstances.push(new Chart(contexts.bar).Bar(data.multiSets, config));
|
||||
chartInstances.push(new Chart(contexts.doughnut).Doughnut(data.segments, config));
|
||||
chartInstances.push(new Chart(contexts.line).Line(data.multiSets, config));
|
||||
chartInstances.push(new Chart(contexts.pie).Pie(data.segments, config));
|
||||
|
||||
|
||||
var iteratePosition = (function(){
|
||||
var position = 1;
|
||||
|
||||
return function(){
|
||||
position++;
|
||||
return (position > chartInstances.length) ? position = 1 : position;
|
||||
};
|
||||
})();
|
||||
|
||||
var carousel = $id('js-carousel');
|
||||
|
||||
|
||||
helpers.addEvent(carousel, 'click', function(){
|
||||
var positionPrefix = 'position-',
|
||||
carouselPosition = iteratePosition(),
|
||||
chartToScrollTo = chartInstances[carouselPosition-1];
|
||||
|
||||
this.className = this.className.replace(new RegExp(positionPrefix+'[1-6]'), positionPrefix+carouselPosition);
|
||||
|
||||
chartToScrollTo.clear();
|
||||
chartToScrollTo.render();
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
// Canvas demo
|
||||
|
||||
(function(){
|
||||
var mousetrap = $id('js-mouse-bubbles'),
|
||||
canvas = mousetrap.getElementsByTagName('canvas')[0],
|
||||
ctx = canvas.getContext('2d'),
|
||||
colour = 'rgba(239,241,245, <%= alpha %>)',
|
||||
maxSize = 50;
|
||||
|
||||
helpers.retinaScale({
|
||||
canvas: canvas,
|
||||
ctx: ctx
|
||||
});
|
||||
|
||||
canvas.style.width = '100%';
|
||||
canvas.style.height = 'auto';
|
||||
|
||||
helpers.addEvent(mousetrap, 'mousemove', drawTriangle);
|
||||
|
||||
helpers.addEvent(mousetrap, 'click', function(){
|
||||
helpers.clear({
|
||||
width: canvas.width,
|
||||
height: canvas.height,
|
||||
ctx: ctx
|
||||
});
|
||||
});
|
||||
|
||||
setInterval(function(){
|
||||
setTimeout(drawTriangle, Math.random() * 400)
|
||||
}, 150);
|
||||
|
||||
function drawTriangle(){
|
||||
var x = Math.random() * canvas.width,
|
||||
y = Math.random() * canvas.height,
|
||||
width = Math.round((maxSize * Math.random() / 2)),
|
||||
height = Math.sqrt(3) * width;
|
||||
|
||||
ctx.save();
|
||||
ctx.translate(x, y);
|
||||
ctx.rotate(Math.random() * (Math.PI * 2));
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(-1 * width, 0);
|
||||
ctx.lineTo(0, -1 * height);
|
||||
ctx.lineTo(width, 0);
|
||||
ctx.closePath();
|
||||
ctx.fillStyle = colour.replace('<%= alpha %>', Math.random() + 0.2);
|
||||
ctx.fill();
|
||||
ctx.restore();
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
// Simple & flexible
|
||||
// Micro line chart
|
||||
(function(){
|
||||
var canvas = $id('micro-line'),
|
||||
ctx = canvas.getContext('2d'),
|
||||
lineChartData = [0, 6, 9, 10, 11, 14, 20];
|
||||
|
||||
var Line = new Chart(ctx).Line({
|
||||
labels: new Array(lineChartData.length),
|
||||
datasets: [{
|
||||
strokeColor: overlayDataset.stroke,
|
||||
pointColor: '#fff',
|
||||
pointStrokeColor: overlayDataset.stroke,
|
||||
data: lineChartData
|
||||
}]
|
||||
}, {
|
||||
showScale: false,
|
||||
showTooltips: false,
|
||||
datasetStrokeWidth: 6,
|
||||
datasetFill: false,
|
||||
pointDotRadius : 9,
|
||||
pointDotStrokeWidth: 4,
|
||||
animation: false,
|
||||
animationEasing: 'easeInOutQuint',
|
||||
onAnimationComplete: function(){
|
||||
this.options.animation = true;
|
||||
}
|
||||
});
|
||||
|
||||
helpers.addEvent(canvas, 'click', function(){
|
||||
lineChartData.reverse();
|
||||
Line.stop();
|
||||
helpers.each(Line.datasets[0].points, function(point, index){
|
||||
point.value = lineChartData[index];
|
||||
});
|
||||
Line.update();
|
||||
})
|
||||
})();
|
||||
|
||||
// Modular doughnut
|
||||
(function(){
|
||||
|
||||
var canvas = $id('modular-doughnut'),
|
||||
colours = {
|
||||
"Core": blue,
|
||||
"Line": orange,
|
||||
"Bar": teal,
|
||||
"Polar Area": purple,
|
||||
"Radar": brown,
|
||||
"Doughnut": green
|
||||
};
|
||||
|
||||
var moduleData = [
|
||||
|
||||
{
|
||||
value: 7.57,
|
||||
color: colours["Core"],
|
||||
highlight: Colour(colours["Core"], 10),
|
||||
label: "Core"
|
||||
},
|
||||
|
||||
{
|
||||
value: 1.63,
|
||||
color: colours["Bar"],
|
||||
highlight: Colour(colours["Bar"], 10),
|
||||
label: "Bar"
|
||||
},
|
||||
|
||||
{
|
||||
value: 1.09,
|
||||
color: colours["Doughnut"],
|
||||
highlight: Colour(colours["Doughnut"], 10),
|
||||
label: "Doughnut"
|
||||
},
|
||||
|
||||
{
|
||||
value: 1.71,
|
||||
color: colours["Radar"],
|
||||
highlight: Colour(colours["Radar"], 10),
|
||||
label: "Radar"
|
||||
},
|
||||
|
||||
{
|
||||
value: 1.64,
|
||||
color: colours["Line"],
|
||||
highlight: Colour(colours["Line"], 10),
|
||||
label: "Line"
|
||||
},
|
||||
|
||||
{
|
||||
value: 1.37,
|
||||
color: colours["Polar Area"],
|
||||
highlight: Colour(colours["Polar Area"], 10),
|
||||
label: "Polar Area"
|
||||
}
|
||||
|
||||
];
|
||||
//
|
||||
{% raw %}
|
||||
var moduleDoughnut = new Chart(canvas.getContext('2d')).Doughnut(moduleData, { tooltipTemplate : "<%if (label){%><%=label%>: <%}%><%= value %>kb", animation: false });
|
||||
{% endraw %}
|
||||
//
|
||||
var legendHolder = document.createElement('div');
|
||||
legendHolder.innerHTML = moduleDoughnut.generateLegend();
|
||||
// Include a html legend template after the module doughnut itself
|
||||
helpers.each(legendHolder.firstChild.childNodes, function(legendNode, index){
|
||||
helpers.addEvent(legendNode, 'mouseover', function(){
|
||||
var activeSegment = moduleDoughnut.segments[index];
|
||||
activeSegment.save();
|
||||
activeSegment.fillColor = activeSegment.highlightColor;
|
||||
moduleDoughnut.showTooltip([activeSegment]);
|
||||
activeSegment.restore();
|
||||
});
|
||||
});
|
||||
helpers.addEvent(legendHolder.firstChild, 'mouseout', function(){
|
||||
moduleDoughnut.draw();
|
||||
});
|
||||
canvas.parentNode.parentNode.appendChild(legendHolder.firstChild);
|
||||
|
||||
})();
|
||||
|
||||
// Interative micro bar chart
|
||||
|
||||
(function(){
|
||||
var canvas = $id('interactive-bar'),
|
||||
ctx = canvas.getContext('2d'),
|
||||
microBar = new Chart(ctx).Bar({
|
||||
labels: new Array(7),
|
||||
datasets: [{
|
||||
fillColor : "rgba(239,241,245,1)",
|
||||
strokeColor : "rgba(0,0,0,0)",
|
||||
highlightFill: "rgba(230,233,240,1)",
|
||||
data: [random(), random(), random(), random(), random(), random(), random()]
|
||||
}]
|
||||
}, {
|
||||
animation: false,
|
||||
showScale: false,
|
||||
barShowStroke: false,
|
||||
tooltipXPadding: 10,
|
||||
tooltipYPadding: 6,
|
||||
tooltipFontSize: 18,
|
||||
tooltipFontStyle: 'bold',
|
||||
// Boolean - If we want to override with a hard coded scale
|
||||
scaleOverride: true,
|
||||
|
||||
// ** Required if scaleOverride is true **
|
||||
// Number - The number of steps in a hard coded scale
|
||||
scaleSteps: 2,
|
||||
// Number - The value jump in the hard coded scale
|
||||
scaleStepWidth: 50,
|
||||
// Number - The scale starting value
|
||||
scaleStartValue: 0,
|
||||
});
|
||||
|
||||
helpers.addEvent(canvas, 'mousemove', function(evt){
|
||||
var bars =microBar.getBarsAtEvent(evt);
|
||||
if (bars.length > 0){
|
||||
canvas.style.cursor = "pointer";
|
||||
}
|
||||
else {
|
||||
canvas.style.cursor = "default";
|
||||
}
|
||||
});
|
||||
|
||||
helpers.addEvent(canvas, 'click', function(evt){
|
||||
microBar.options.animation = true;
|
||||
microBar.options.onAnimationComplete = function(){
|
||||
this.showTooltip(this.activeElements, true);
|
||||
};
|
||||
var bars = microBar.getBarsAtEvent(evt);
|
||||
helpers.each(bars, function(bar){
|
||||
bar.value = Math.max(random(), 5);
|
||||
});
|
||||
if (bars.length > 0){
|
||||
microBar.update();
|
||||
}
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
function Colour(col, amt) {
|
||||
|
||||
var usePound = false;
|
||||
|
||||
if (col[0] == "#") {
|
||||
col = col.slice(1);
|
||||
usePound = true;
|
||||
}
|
||||
|
||||
var num = parseInt(col,16);
|
||||
|
||||
var r = (num >> 16) + amt;
|
||||
|
||||
if (r > 255) r = 255;
|
||||
else if (r < 0) r = 0;
|
||||
|
||||
var b = ((num >> 8) & 0x00FF) + amt;
|
||||
|
||||
if (b > 255) b = 255;
|
||||
else if (b < 0) b = 0;
|
||||
|
||||
var g = (num & 0x0000FF) + amt;
|
||||
|
||||
if (g > 255) g = 255;
|
||||
else if (g < 0) g = 0;
|
||||
|
||||
return (usePound?"#":"") + (g | (b << 8) | (r << 16)).toString(16);
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
</script>
|
||||
<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-28909194-3', 'auto');
|
||||
ga('send', 'pageview');</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,28 +0,0 @@
|
||||
{
|
||||
"name": "chart.js",
|
||||
"homepage": "http://www.chartjs.org",
|
||||
"description": "Simple HTML5 charts using the canvas element.",
|
||||
"version": "1.0.2",
|
||||
"main": "Chart.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nnnick/Chart.js.git"
|
||||
},
|
||||
"dependences": {},
|
||||
"devDependencies": {
|
||||
"gulp": "3.5.x",
|
||||
"gulp-concat": "~2.1.x",
|
||||
"gulp-connect": "~2.0.5",
|
||||
"gulp-jshint": "~1.5.1",
|
||||
"gulp-replace": "^0.4.0",
|
||||
"gulp-size": "~0.4.0",
|
||||
"gulp-uglify": "~0.2.x",
|
||||
"gulp-util": "~2.2.x",
|
||||
"gulp-html-validator": "^0.0.2",
|
||||
"inquirer": "^0.5.1",
|
||||
"semver": "^3.0.1"
|
||||
},
|
||||
"spm": {
|
||||
"main": "Chart.js"
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bar Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div style="width: 50%">
|
||||
<canvas id="canvas" height="450" width="600"></canvas>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
|
||||
|
||||
var barChartData = {
|
||||
labels : ["January","February","March","April","May","June","July"],
|
||||
datasets : [
|
||||
{
|
||||
fillColor : "rgba(220,220,220,0.5)",
|
||||
strokeColor : "rgba(220,220,220,0.8)",
|
||||
highlightFill: "rgba(220,220,220,0.75)",
|
||||
highlightStroke: "rgba(220,220,220,1)",
|
||||
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
|
||||
},
|
||||
{
|
||||
fillColor : "rgba(151,187,205,0.5)",
|
||||
strokeColor : "rgba(151,187,205,0.8)",
|
||||
highlightFill : "rgba(151,187,205,0.75)",
|
||||
highlightStroke : "rgba(151,187,205,1)",
|
||||
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
window.onload = function(){
|
||||
var ctx = document.getElementById("canvas").getContext("2d");
|
||||
window.myBar = new Chart(ctx).Bar(barChartData, {
|
||||
responsive : true
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,67 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Doughnut Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<style>
|
||||
body{
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
#canvas-holder{
|
||||
width:30%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="canvas-holder">
|
||||
<canvas id="chart-area" width="500" height="500"/>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
var doughnutData = [
|
||||
{
|
||||
value: 300,
|
||||
color:"#F7464A",
|
||||
highlight: "#FF5A5E",
|
||||
label: "Red"
|
||||
},
|
||||
{
|
||||
value: 50,
|
||||
color: "#46BFBD",
|
||||
highlight: "#5AD3D1",
|
||||
label: "Green"
|
||||
},
|
||||
{
|
||||
value: 100,
|
||||
color: "#FDB45C",
|
||||
highlight: "#FFC870",
|
||||
label: "Yellow"
|
||||
},
|
||||
{
|
||||
value: 40,
|
||||
color: "#949FB1",
|
||||
highlight: "#A8B3C5",
|
||||
label: "Grey"
|
||||
},
|
||||
{
|
||||
value: 120,
|
||||
color: "#4D5360",
|
||||
highlight: "#616774",
|
||||
label: "Dark Grey"
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
window.onload = function(){
|
||||
var ctx = document.getElementById("chart-area").getContext("2d");
|
||||
window.myDoughnut = new Chart(ctx).Doughnut(doughnutData, {responsive : true});
|
||||
};
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,129 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Line Chart with Custom Tooltips</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
|
||||
<style>
|
||||
#canvas-holder1 {
|
||||
width: 300px;
|
||||
margin: 20px auto;
|
||||
}
|
||||
#canvas-holder2 {
|
||||
width: 50%;
|
||||
margin: 20px 25%;
|
||||
}
|
||||
#chartjs-tooltip {
|
||||
opacity: 1;
|
||||
position: absolute;
|
||||
background: rgba(0, 0, 0, .7);
|
||||
color: white;
|
||||
padding: 3px;
|
||||
border-radius: 3px;
|
||||
-webkit-transition: all .1s ease;
|
||||
transition: all .1s ease;
|
||||
pointer-events: none;
|
||||
-webkit-transform: translate(-50%, 0);
|
||||
transform: translate(-50%, 0);
|
||||
}
|
||||
.chartjs-tooltip-key{
|
||||
display:inline-block;
|
||||
width:10px;
|
||||
height:10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="canvas-holder1">
|
||||
<canvas id="chart1" width="300" height="30" />
|
||||
</div>
|
||||
<div id="canvas-holder2">
|
||||
<canvas id="chart2" width="450" height="600" />
|
||||
</div>
|
||||
|
||||
<div id="chartjs-tooltip"></div>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
Chart.defaults.global.pointHitDetectionRadius = 1;
|
||||
Chart.defaults.global.customTooltips = function(tooltip) {
|
||||
|
||||
var tooltipEl = $('#chartjs-tooltip');
|
||||
|
||||
if (!tooltip) {
|
||||
tooltipEl.css({
|
||||
opacity: 0
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
tooltipEl.removeClass('above below');
|
||||
tooltipEl.addClass(tooltip.yAlign);
|
||||
|
||||
var innerHtml = '';
|
||||
for (var i = tooltip.labels.length - 1; i >= 0; i--) {
|
||||
innerHtml += [
|
||||
'<div class="chartjs-tooltip-section">',
|
||||
' <span class="chartjs-tooltip-key" style="background-color:' + tooltip.legendColors[i].fill + '"></span>',
|
||||
' <span class="chartjs-tooltip-value">' + tooltip.labels[i] + '</span>',
|
||||
'</div>'
|
||||
].join('');
|
||||
}
|
||||
tooltipEl.html(innerHtml);
|
||||
|
||||
tooltipEl.css({
|
||||
opacity: 1,
|
||||
left: tooltip.chart.canvas.offsetLeft + tooltip.x + 'px',
|
||||
top: tooltip.chart.canvas.offsetTop + tooltip.y + 'px',
|
||||
fontFamily: tooltip.fontFamily,
|
||||
fontSize: tooltip.fontSize,
|
||||
fontStyle: tooltip.fontStyle,
|
||||
});
|
||||
};
|
||||
var randomScalingFactor = function() {
|
||||
return Math.round(Math.random() * 100);
|
||||
};
|
||||
var lineChartData = {
|
||||
labels: ["January", "February", "March", "April", "May", "June", "July"],
|
||||
datasets: [{
|
||||
label: "My First dataset",
|
||||
fillColor: "rgba(220,220,220,0.2)",
|
||||
strokeColor: "rgba(220,220,220,1)",
|
||||
pointColor: "rgba(220,220,220,1)",
|
||||
pointStrokeColor: "#fff",
|
||||
pointHighlightFill: "#fff",
|
||||
pointHighlightStroke: "rgba(220,220,220,1)",
|
||||
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
|
||||
}, {
|
||||
label: "My Second dataset",
|
||||
fillColor: "rgba(151,187,205,0.2)",
|
||||
strokeColor: "rgba(151,187,205,1)",
|
||||
pointColor: "rgba(151,187,205,1)",
|
||||
pointStrokeColor: "#fff",
|
||||
pointHighlightFill: "#fff",
|
||||
pointHighlightStroke: "rgba(151,187,205,1)",
|
||||
data: [randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor(), randomScalingFactor()]
|
||||
}]
|
||||
};
|
||||
|
||||
window.onload = function() {
|
||||
var ctx1 = document.getElementById("chart1").getContext("2d");
|
||||
window.myLine = new Chart(ctx1).Line(lineChartData, {
|
||||
showScale: false,
|
||||
pointDot : true,
|
||||
responsive: true
|
||||
});
|
||||
|
||||
var ctx2 = document.getElementById("chart2").getContext("2d");
|
||||
window.myLine = new Chart(ctx2).Line(lineChartData, {
|
||||
responsive: true
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,54 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Line Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div style="width:30%">
|
||||
<div>
|
||||
<canvas id="canvas" height="450" width="600"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
var randomScalingFactor = function(){ return Math.round(Math.random()*100)};
|
||||
var lineChartData = {
|
||||
labels : ["January","February","March","April","May","June","July"],
|
||||
datasets : [
|
||||
{
|
||||
label: "My First dataset",
|
||||
fillColor : "rgba(220,220,220,0.2)",
|
||||
strokeColor : "rgba(220,220,220,1)",
|
||||
pointColor : "rgba(220,220,220,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
pointHighlightFill : "#fff",
|
||||
pointHighlightStroke : "rgba(220,220,220,1)",
|
||||
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
|
||||
},
|
||||
{
|
||||
label: "My Second dataset",
|
||||
fillColor : "rgba(151,187,205,0.2)",
|
||||
strokeColor : "rgba(151,187,205,1)",
|
||||
pointColor : "rgba(151,187,205,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
pointHighlightFill : "#fff",
|
||||
pointHighlightStroke : "rgba(151,187,205,1)",
|
||||
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
window.onload = function(){
|
||||
var ctx = document.getElementById("canvas").getContext("2d");
|
||||
window.myLine = new Chart(ctx).Line(lineChartData, {
|
||||
responsive: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,156 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Pie Chart with Custom Tooltips</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
|
||||
|
||||
<style>
|
||||
#canvas-holder {
|
||||
width: 100%;
|
||||
margin-top: 50px;
|
||||
text-align: center;
|
||||
}
|
||||
#chartjs-tooltip {
|
||||
opacity: 1;
|
||||
position: absolute;
|
||||
background: rgba(0, 0, 0, .7);
|
||||
color: white;
|
||||
padding: 3px;
|
||||
border-radius: 3px;
|
||||
-webkit-transition: all .1s ease;
|
||||
transition: all .1s ease;
|
||||
pointer-events: none;
|
||||
-webkit-transform: translate(-50%, 0);
|
||||
transform: translate(-50%, 0);
|
||||
}
|
||||
#chartjs-tooltip.below {
|
||||
-webkit-transform: translate(-50%, 0);
|
||||
transform: translate(-50%, 0);
|
||||
}
|
||||
#chartjs-tooltip.below:before {
|
||||
border: solid;
|
||||
border-color: #111 transparent;
|
||||
border-color: rgba(0, 0, 0, .8) transparent;
|
||||
border-width: 0 8px 8px 8px;
|
||||
bottom: 1em;
|
||||
content: "";
|
||||
display: block;
|
||||
left: 50%;
|
||||
position: absolute;
|
||||
z-index: 99;
|
||||
-webkit-transform: translate(-50%, -100%);
|
||||
transform: translate(-50%, -100%);
|
||||
}
|
||||
#chartjs-tooltip.above {
|
||||
-webkit-transform: translate(-50%, -100%);
|
||||
transform: translate(-50%, -100%);
|
||||
}
|
||||
#chartjs-tooltip.above:before {
|
||||
border: solid;
|
||||
border-color: #111 transparent;
|
||||
border-color: rgba(0, 0, 0, .8) transparent;
|
||||
border-width: 8px 8px 0 8px;
|
||||
bottom: 1em;
|
||||
content: "";
|
||||
display: block;
|
||||
left: 50%;
|
||||
top: 100%;
|
||||
position: absolute;
|
||||
z-index: 99;
|
||||
-webkit-transform: translate(-50%, 0);
|
||||
transform: translate(-50%, 0);
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="canvas-holder">
|
||||
<canvas id="chart-area1" width="50" height="50" />
|
||||
</div>
|
||||
<div id="canvas-holder">
|
||||
<canvas id="chart-area2" width="300" height="300" />
|
||||
</div>
|
||||
|
||||
<div id="chartjs-tooltip"></div>
|
||||
|
||||
|
||||
<script>
|
||||
Chart.defaults.global.customTooltips = function(tooltip) {
|
||||
|
||||
// Tooltip Element
|
||||
var tooltipEl = $('#chartjs-tooltip');
|
||||
|
||||
// Hide if no tooltip
|
||||
if (!tooltip) {
|
||||
tooltipEl.css({
|
||||
opacity: 0
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Set caret Position
|
||||
tooltipEl.removeClass('above below');
|
||||
tooltipEl.addClass(tooltip.yAlign);
|
||||
|
||||
// Set Text
|
||||
tooltipEl.html(tooltip.text);
|
||||
|
||||
// Find Y Location on page
|
||||
var top;
|
||||
if (tooltip.yAlign == 'above') {
|
||||
top = tooltip.y - tooltip.caretHeight - tooltip.caretPadding;
|
||||
} else {
|
||||
top = tooltip.y + tooltip.caretHeight + tooltip.caretPadding;
|
||||
}
|
||||
|
||||
// Display, position, and set styles for font
|
||||
tooltipEl.css({
|
||||
opacity: 1,
|
||||
left: tooltip.chart.canvas.offsetLeft + tooltip.x + 'px',
|
||||
top: tooltip.chart.canvas.offsetTop + top + 'px',
|
||||
fontFamily: tooltip.fontFamily,
|
||||
fontSize: tooltip.fontSize,
|
||||
fontStyle: tooltip.fontStyle,
|
||||
});
|
||||
};
|
||||
|
||||
var pieData = [{
|
||||
value: 300,
|
||||
color: "#F7464A",
|
||||
highlight: "#FF5A5E",
|
||||
label: "Red"
|
||||
}, {
|
||||
value: 50,
|
||||
color: "#46BFBD",
|
||||
highlight: "#5AD3D1",
|
||||
label: "Green"
|
||||
}, {
|
||||
value: 100,
|
||||
color: "#FDB45C",
|
||||
highlight: "#FFC870",
|
||||
label: "Yellow"
|
||||
}, {
|
||||
value: 40,
|
||||
color: "#949FB1",
|
||||
highlight: "#A8B3C5",
|
||||
label: "Grey"
|
||||
}, {
|
||||
value: 120,
|
||||
color: "#4D5360",
|
||||
highlight: "#616774",
|
||||
label: "Dark Grey"
|
||||
}];
|
||||
|
||||
window.onload = function() {
|
||||
var ctx1 = document.getElementById("chart-area1").getContext("2d");
|
||||
window.myPie = new Chart(ctx1).Pie(pieData);
|
||||
|
||||
var ctx2 = document.getElementById("chart-area2").getContext("2d");
|
||||
window.myPie = new Chart(ctx2).Pie(pieData);
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -1,58 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Pie Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="canvas-holder">
|
||||
<canvas id="chart-area" width="300" height="300"/>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
var pieData = [
|
||||
{
|
||||
value: 300,
|
||||
color:"#F7464A",
|
||||
highlight: "#FF5A5E",
|
||||
label: "Red"
|
||||
},
|
||||
{
|
||||
value: 50,
|
||||
color: "#46BFBD",
|
||||
highlight: "#5AD3D1",
|
||||
label: "Green"
|
||||
},
|
||||
{
|
||||
value: 100,
|
||||
color: "#FDB45C",
|
||||
highlight: "#FFC870",
|
||||
label: "Yellow"
|
||||
},
|
||||
{
|
||||
value: 40,
|
||||
color: "#949FB1",
|
||||
highlight: "#A8B3C5",
|
||||
label: "Grey"
|
||||
},
|
||||
{
|
||||
value: 120,
|
||||
color: "#4D5360",
|
||||
highlight: "#616774",
|
||||
label: "Dark Grey"
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
window.onload = function(){
|
||||
var ctx = document.getElementById("chart-area").getContext("2d");
|
||||
window.myPie = new Chart(ctx).Pie(pieData);
|
||||
};
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,60 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Polar Area Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="canvas-holder" style="width:30%">
|
||||
<canvas id="chart-area" width="300" height="300"/>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
var polarData = [
|
||||
{
|
||||
value: 300,
|
||||
color:"#F7464A",
|
||||
highlight: "#FF5A5E",
|
||||
label: "Red"
|
||||
},
|
||||
{
|
||||
value: 50,
|
||||
color: "#46BFBD",
|
||||
highlight: "#5AD3D1",
|
||||
label: "Green"
|
||||
},
|
||||
{
|
||||
value: 100,
|
||||
color: "#FDB45C",
|
||||
highlight: "#FFC870",
|
||||
label: "Yellow"
|
||||
},
|
||||
{
|
||||
value: 40,
|
||||
color: "#949FB1",
|
||||
highlight: "#A8B3C5",
|
||||
label: "Grey"
|
||||
},
|
||||
{
|
||||
value: 120,
|
||||
color: "#4D5360",
|
||||
highlight: "#616774",
|
||||
label: "Dark Grey"
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
window.onload = function(){
|
||||
var ctx = document.getElementById("chart-area").getContext("2d");
|
||||
window.myPolarArea = new Chart(ctx).PolarArea(polarData, {
|
||||
responsive:true
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,53 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Radar Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
|
||||
<style>
|
||||
canvas{
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div style="width:30%">
|
||||
<canvas id="canvas" height="450" width="450"></canvas>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
var radarChartData = {
|
||||
labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
|
||||
datasets: [
|
||||
{
|
||||
label: "My First dataset",
|
||||
fillColor: "rgba(220,220,220,0.2)",
|
||||
strokeColor: "rgba(220,220,220,1)",
|
||||
pointColor: "rgba(220,220,220,1)",
|
||||
pointStrokeColor: "#fff",
|
||||
pointHighlightFill: "#fff",
|
||||
pointHighlightStroke: "rgba(220,220,220,1)",
|
||||
data: [65,59,90,81,56,55,40]
|
||||
},
|
||||
{
|
||||
label: "My Second dataset",
|
||||
fillColor: "rgba(151,187,205,0.2)",
|
||||
strokeColor: "rgba(151,187,205,1)",
|
||||
pointColor: "rgba(151,187,205,1)",
|
||||
pointStrokeColor: "#fff",
|
||||
pointHighlightFill: "#fff",
|
||||
pointHighlightStroke: "rgba(151,187,205,1)",
|
||||
data: [28,48,40,19,96,27,100]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
window.onload = function(){
|
||||
window.myRadar = new Chart(document.getElementById("canvas").getContext("2d")).Radar(radarChartData, {
|
||||
responsive: true
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,302 +0,0 @@
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
var root = this,
|
||||
Chart = root.Chart,
|
||||
helpers = Chart.helpers;
|
||||
|
||||
|
||||
var defaultConfig = {
|
||||
//Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
|
||||
scaleBeginAtZero : true,
|
||||
|
||||
//Boolean - Whether grid lines are shown across the chart
|
||||
scaleShowGridLines : true,
|
||||
|
||||
//String - Colour of the grid lines
|
||||
scaleGridLineColor : "rgba(0,0,0,.05)",
|
||||
|
||||
//Number - Width of the grid lines
|
||||
scaleGridLineWidth : 1,
|
||||
|
||||
//Boolean - Whether to show horizontal lines (except X axis)
|
||||
scaleShowHorizontalLines: true,
|
||||
|
||||
//Boolean - Whether to show vertical lines (except Y axis)
|
||||
scaleShowVerticalLines: true,
|
||||
|
||||
//Boolean - If there is a stroke on each bar
|
||||
barShowStroke : true,
|
||||
|
||||
//Number - Pixel width of the bar stroke
|
||||
barStrokeWidth : 2,
|
||||
|
||||
//Number - Spacing between each of the X value sets
|
||||
barValueSpacing : 5,
|
||||
|
||||
//Number - Spacing between data sets within X values
|
||||
barDatasetSpacing : 1,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].fillColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
|
||||
};
|
||||
|
||||
|
||||
Chart.Type.extend({
|
||||
name: "Bar",
|
||||
defaults : defaultConfig,
|
||||
initialize: function(data){
|
||||
|
||||
//Expose options as a scope variable here so we can access it in the ScaleClass
|
||||
var options = this.options;
|
||||
|
||||
this.ScaleClass = Chart.Scale.extend({
|
||||
offsetGridLines : true,
|
||||
calculateBarX : function(datasetCount, datasetIndex, barIndex){
|
||||
//Reusable method for calculating the xPosition of a given bar based on datasetIndex & width of the bar
|
||||
var xWidth = this.calculateBaseWidth(),
|
||||
xAbsolute = this.calculateX(barIndex) - (xWidth/2),
|
||||
barWidth = this.calculateBarWidth(datasetCount);
|
||||
|
||||
return xAbsolute + (barWidth * datasetIndex) + (datasetIndex * options.barDatasetSpacing) + barWidth/2;
|
||||
},
|
||||
calculateBaseWidth : function(){
|
||||
return (this.calculateX(1) - this.calculateX(0)) - (2*options.barValueSpacing);
|
||||
},
|
||||
calculateBarWidth : function(datasetCount){
|
||||
//The padding between datasets is to the right of each bar, providing that there are more than 1 dataset
|
||||
var baseWidth = this.calculateBaseWidth() - ((datasetCount - 1) * options.barDatasetSpacing);
|
||||
|
||||
return (baseWidth / datasetCount);
|
||||
}
|
||||
});
|
||||
|
||||
this.datasets = [];
|
||||
|
||||
//Set up tooltip events on the chart
|
||||
if (this.options.showTooltips){
|
||||
helpers.bindEvents(this, this.options.tooltipEvents, function(evt){
|
||||
var activeBars = (evt.type !== 'mouseout') ? this.getBarsAtEvent(evt) : [];
|
||||
|
||||
this.eachBars(function(bar){
|
||||
bar.restore(['fillColor', 'strokeColor']);
|
||||
});
|
||||
helpers.each(activeBars, function(activeBar){
|
||||
activeBar.fillColor = activeBar.highlightFill;
|
||||
activeBar.strokeColor = activeBar.highlightStroke;
|
||||
});
|
||||
this.showTooltip(activeBars);
|
||||
});
|
||||
}
|
||||
|
||||
//Declare the extension of the default point, to cater for the options passed in to the constructor
|
||||
this.BarClass = Chart.Rectangle.extend({
|
||||
strokeWidth : this.options.barStrokeWidth,
|
||||
showStroke : this.options.barShowStroke,
|
||||
ctx : this.chart.ctx
|
||||
});
|
||||
|
||||
//Iterate through each of the datasets, and build this into a property of the chart
|
||||
helpers.each(data.datasets,function(dataset,datasetIndex){
|
||||
|
||||
var datasetObject = {
|
||||
label : dataset.label || null,
|
||||
fillColor : dataset.fillColor,
|
||||
strokeColor : dataset.strokeColor,
|
||||
bars : []
|
||||
};
|
||||
|
||||
this.datasets.push(datasetObject);
|
||||
|
||||
helpers.each(dataset.data,function(dataPoint,index){
|
||||
//Add a new point for each piece of data, passing any required data to draw.
|
||||
datasetObject.bars.push(new this.BarClass({
|
||||
value : dataPoint,
|
||||
label : data.labels[index],
|
||||
datasetLabel: dataset.label,
|
||||
strokeColor : dataset.strokeColor,
|
||||
fillColor : dataset.fillColor,
|
||||
highlightFill : dataset.highlightFill || dataset.fillColor,
|
||||
highlightStroke : dataset.highlightStroke || dataset.strokeColor
|
||||
}));
|
||||
},this);
|
||||
|
||||
},this);
|
||||
|
||||
this.buildScale(data.labels);
|
||||
|
||||
this.BarClass.prototype.base = this.scale.endPoint;
|
||||
|
||||
this.eachBars(function(bar, index, datasetIndex){
|
||||
helpers.extend(bar, {
|
||||
width : this.scale.calculateBarWidth(this.datasets.length),
|
||||
x: this.scale.calculateBarX(this.datasets.length, datasetIndex, index),
|
||||
y: this.scale.endPoint
|
||||
});
|
||||
bar.save();
|
||||
}, this);
|
||||
|
||||
this.render();
|
||||
},
|
||||
update : function(){
|
||||
this.scale.update();
|
||||
// Reset any highlight colours before updating.
|
||||
helpers.each(this.activeElements, function(activeElement){
|
||||
activeElement.restore(['fillColor', 'strokeColor']);
|
||||
});
|
||||
|
||||
this.eachBars(function(bar){
|
||||
bar.save();
|
||||
});
|
||||
this.render();
|
||||
},
|
||||
eachBars : function(callback){
|
||||
helpers.each(this.datasets,function(dataset, datasetIndex){
|
||||
helpers.each(dataset.bars, callback, this, datasetIndex);
|
||||
},this);
|
||||
},
|
||||
getBarsAtEvent : function(e){
|
||||
var barsArray = [],
|
||||
eventPosition = helpers.getRelativePosition(e),
|
||||
datasetIterator = function(dataset){
|
||||
barsArray.push(dataset.bars[barIndex]);
|
||||
},
|
||||
barIndex;
|
||||
|
||||
for (var datasetIndex = 0; datasetIndex < this.datasets.length; datasetIndex++) {
|
||||
for (barIndex = 0; barIndex < this.datasets[datasetIndex].bars.length; barIndex++) {
|
||||
if (this.datasets[datasetIndex].bars[barIndex].inRange(eventPosition.x,eventPosition.y)){
|
||||
helpers.each(this.datasets, datasetIterator);
|
||||
return barsArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return barsArray;
|
||||
},
|
||||
buildScale : function(labels){
|
||||
var self = this;
|
||||
|
||||
var dataTotal = function(){
|
||||
var values = [];
|
||||
self.eachBars(function(bar){
|
||||
values.push(bar.value);
|
||||
});
|
||||
return values;
|
||||
};
|
||||
|
||||
var scaleOptions = {
|
||||
templateString : this.options.scaleLabel,
|
||||
height : this.chart.height,
|
||||
width : this.chart.width,
|
||||
ctx : this.chart.ctx,
|
||||
textColor : this.options.scaleFontColor,
|
||||
fontSize : this.options.scaleFontSize,
|
||||
fontStyle : this.options.scaleFontStyle,
|
||||
fontFamily : this.options.scaleFontFamily,
|
||||
valuesCount : labels.length,
|
||||
beginAtZero : this.options.scaleBeginAtZero,
|
||||
integersOnly : this.options.scaleIntegersOnly,
|
||||
calculateYRange: function(currentHeight){
|
||||
var updatedRanges = helpers.calculateScaleRange(
|
||||
dataTotal(),
|
||||
currentHeight,
|
||||
this.fontSize,
|
||||
this.beginAtZero,
|
||||
this.integersOnly
|
||||
);
|
||||
helpers.extend(this, updatedRanges);
|
||||
},
|
||||
xLabels : labels,
|
||||
font : helpers.fontString(this.options.scaleFontSize, this.options.scaleFontStyle, this.options.scaleFontFamily),
|
||||
lineWidth : this.options.scaleLineWidth,
|
||||
lineColor : this.options.scaleLineColor,
|
||||
showHorizontalLines : this.options.scaleShowHorizontalLines,
|
||||
showVerticalLines : this.options.scaleShowVerticalLines,
|
||||
gridLineWidth : (this.options.scaleShowGridLines) ? this.options.scaleGridLineWidth : 0,
|
||||
gridLineColor : (this.options.scaleShowGridLines) ? this.options.scaleGridLineColor : "rgba(0,0,0,0)",
|
||||
padding : (this.options.showScale) ? 0 : (this.options.barShowStroke) ? this.options.barStrokeWidth : 0,
|
||||
showLabels : this.options.scaleShowLabels,
|
||||
display : this.options.showScale
|
||||
};
|
||||
|
||||
if (this.options.scaleOverride){
|
||||
helpers.extend(scaleOptions, {
|
||||
calculateYRange: helpers.noop,
|
||||
steps: this.options.scaleSteps,
|
||||
stepValue: this.options.scaleStepWidth,
|
||||
min: this.options.scaleStartValue,
|
||||
max: this.options.scaleStartValue + (this.options.scaleSteps * this.options.scaleStepWidth)
|
||||
});
|
||||
}
|
||||
|
||||
this.scale = new this.ScaleClass(scaleOptions);
|
||||
},
|
||||
addData : function(valuesArray,label){
|
||||
//Map the values array for each of the datasets
|
||||
helpers.each(valuesArray,function(value,datasetIndex){
|
||||
//Add a new point for each piece of data, passing any required data to draw.
|
||||
this.datasets[datasetIndex].bars.push(new this.BarClass({
|
||||
value : value,
|
||||
label : label,
|
||||
x: this.scale.calculateBarX(this.datasets.length, datasetIndex, this.scale.valuesCount+1),
|
||||
y: this.scale.endPoint,
|
||||
width : this.scale.calculateBarWidth(this.datasets.length),
|
||||
base : this.scale.endPoint,
|
||||
strokeColor : this.datasets[datasetIndex].strokeColor,
|
||||
fillColor : this.datasets[datasetIndex].fillColor
|
||||
}));
|
||||
},this);
|
||||
|
||||
this.scale.addXLabel(label);
|
||||
//Then re-render the chart.
|
||||
this.update();
|
||||
},
|
||||
removeData : function(){
|
||||
this.scale.removeXLabel();
|
||||
//Then re-render the chart.
|
||||
helpers.each(this.datasets,function(dataset){
|
||||
dataset.bars.shift();
|
||||
},this);
|
||||
this.update();
|
||||
},
|
||||
reflow : function(){
|
||||
helpers.extend(this.BarClass.prototype,{
|
||||
y: this.scale.endPoint,
|
||||
base : this.scale.endPoint
|
||||
});
|
||||
var newScaleProps = helpers.extend({
|
||||
height : this.chart.height,
|
||||
width : this.chart.width
|
||||
});
|
||||
this.scale.update(newScaleProps);
|
||||
},
|
||||
draw : function(ease){
|
||||
var easingDecimal = ease || 1;
|
||||
this.clear();
|
||||
|
||||
var ctx = this.chart.ctx;
|
||||
|
||||
this.scale.draw(easingDecimal);
|
||||
|
||||
//Draw all the bars for each dataset
|
||||
helpers.each(this.datasets,function(dataset,datasetIndex){
|
||||
helpers.each(dataset.bars,function(bar,index){
|
||||
if (bar.hasValue()){
|
||||
bar.base = this.scale.endPoint;
|
||||
//Transition then draw
|
||||
bar.transition({
|
||||
x : this.scale.calculateBarX(this.datasets.length, datasetIndex, index),
|
||||
y : this.scale.calculateY(bar.value),
|
||||
width : this.scale.calculateBarWidth(this.datasets.length)
|
||||
}, easingDecimal).draw();
|
||||
}
|
||||
},this);
|
||||
|
||||
},this);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}).call(this);
|
||||
-2021
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -1,184 +0,0 @@
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
var root = this,
|
||||
Chart = root.Chart,
|
||||
//Cache a local reference to Chart.helpers
|
||||
helpers = Chart.helpers;
|
||||
|
||||
var defaultConfig = {
|
||||
//Boolean - Whether we should show a stroke on each segment
|
||||
segmentShowStroke : true,
|
||||
|
||||
//String - The colour of each segment stroke
|
||||
segmentStrokeColor : "#fff",
|
||||
|
||||
//Number - The width of each segment stroke
|
||||
segmentStrokeWidth : 2,
|
||||
|
||||
//The percentage of the chart that we cut out of the middle.
|
||||
percentageInnerCutout : 50,
|
||||
|
||||
//Number - Amount of animation steps
|
||||
animationSteps : 100,
|
||||
|
||||
//String - Animation easing effect
|
||||
animationEasing : "easeOutBounce",
|
||||
|
||||
//Boolean - Whether we animate the rotation of the Doughnut
|
||||
animateRotate : true,
|
||||
|
||||
//Boolean - Whether we animate scaling the Doughnut from the centre
|
||||
animateScale : false,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
|
||||
|
||||
};
|
||||
|
||||
|
||||
Chart.Type.extend({
|
||||
//Passing in a name registers this chart in the Chart namespace
|
||||
name: "Doughnut",
|
||||
//Providing a defaults will also register the deafults in the chart namespace
|
||||
defaults : defaultConfig,
|
||||
//Initialize is fired when the chart is initialized - Data is passed in as a parameter
|
||||
//Config is automatically merged by the core of Chart.js, and is available at this.options
|
||||
initialize: function(data){
|
||||
|
||||
//Declare segments as a static property to prevent inheriting across the Chart type prototype
|
||||
this.segments = [];
|
||||
this.outerRadius = (helpers.min([this.chart.width,this.chart.height]) - this.options.segmentStrokeWidth/2)/2;
|
||||
|
||||
this.SegmentArc = Chart.Arc.extend({
|
||||
ctx : this.chart.ctx,
|
||||
x : this.chart.width/2,
|
||||
y : this.chart.height/2
|
||||
});
|
||||
|
||||
//Set up tooltip events on the chart
|
||||
if (this.options.showTooltips){
|
||||
helpers.bindEvents(this, this.options.tooltipEvents, function(evt){
|
||||
var activeSegments = (evt.type !== 'mouseout') ? this.getSegmentsAtEvent(evt) : [];
|
||||
|
||||
helpers.each(this.segments,function(segment){
|
||||
segment.restore(["fillColor"]);
|
||||
});
|
||||
helpers.each(activeSegments,function(activeSegment){
|
||||
activeSegment.fillColor = activeSegment.highlightColor;
|
||||
});
|
||||
this.showTooltip(activeSegments);
|
||||
});
|
||||
}
|
||||
this.calculateTotal(data);
|
||||
|
||||
helpers.each(data,function(datapoint, index){
|
||||
this.addData(datapoint, index, true);
|
||||
},this);
|
||||
|
||||
this.render();
|
||||
},
|
||||
getSegmentsAtEvent : function(e){
|
||||
var segmentsArray = [];
|
||||
|
||||
var location = helpers.getRelativePosition(e);
|
||||
|
||||
helpers.each(this.segments,function(segment){
|
||||
if (segment.inRange(location.x,location.y)) segmentsArray.push(segment);
|
||||
},this);
|
||||
return segmentsArray;
|
||||
},
|
||||
addData : function(segment, atIndex, silent){
|
||||
var index = atIndex || this.segments.length;
|
||||
this.segments.splice(index, 0, new this.SegmentArc({
|
||||
value : segment.value,
|
||||
outerRadius : (this.options.animateScale) ? 0 : this.outerRadius,
|
||||
innerRadius : (this.options.animateScale) ? 0 : (this.outerRadius/100) * this.options.percentageInnerCutout,
|
||||
fillColor : segment.color,
|
||||
highlightColor : segment.highlight || segment.color,
|
||||
showStroke : this.options.segmentShowStroke,
|
||||
strokeWidth : this.options.segmentStrokeWidth,
|
||||
strokeColor : this.options.segmentStrokeColor,
|
||||
startAngle : Math.PI * 1.5,
|
||||
circumference : (this.options.animateRotate) ? 0 : this.calculateCircumference(segment.value),
|
||||
label : segment.label
|
||||
}));
|
||||
if (!silent){
|
||||
this.reflow();
|
||||
this.update();
|
||||
}
|
||||
},
|
||||
calculateCircumference : function(value){
|
||||
return (Math.PI*2)*(Math.abs(value) / this.total);
|
||||
},
|
||||
calculateTotal : function(data){
|
||||
this.total = 0;
|
||||
helpers.each(data,function(segment){
|
||||
this.total += Math.abs(segment.value);
|
||||
},this);
|
||||
},
|
||||
update : function(){
|
||||
this.calculateTotal(this.segments);
|
||||
|
||||
// Reset any highlight colours before updating.
|
||||
helpers.each(this.activeElements, function(activeElement){
|
||||
activeElement.restore(['fillColor']);
|
||||
});
|
||||
|
||||
helpers.each(this.segments,function(segment){
|
||||
segment.save();
|
||||
});
|
||||
this.render();
|
||||
},
|
||||
|
||||
removeData: function(atIndex){
|
||||
var indexToDelete = (helpers.isNumber(atIndex)) ? atIndex : this.segments.length-1;
|
||||
this.segments.splice(indexToDelete, 1);
|
||||
this.reflow();
|
||||
this.update();
|
||||
},
|
||||
|
||||
reflow : function(){
|
||||
helpers.extend(this.SegmentArc.prototype,{
|
||||
x : this.chart.width/2,
|
||||
y : this.chart.height/2
|
||||
});
|
||||
this.outerRadius = (helpers.min([this.chart.width,this.chart.height]) - this.options.segmentStrokeWidth/2)/2;
|
||||
helpers.each(this.segments, function(segment){
|
||||
segment.update({
|
||||
outerRadius : this.outerRadius,
|
||||
innerRadius : (this.outerRadius/100) * this.options.percentageInnerCutout
|
||||
});
|
||||
}, this);
|
||||
},
|
||||
draw : function(easeDecimal){
|
||||
var animDecimal = (easeDecimal) ? easeDecimal : 1;
|
||||
this.clear();
|
||||
helpers.each(this.segments,function(segment,index){
|
||||
segment.transition({
|
||||
circumference : this.calculateCircumference(segment.value),
|
||||
outerRadius : this.outerRadius,
|
||||
innerRadius : (this.outerRadius/100) * this.options.percentageInnerCutout
|
||||
},animDecimal);
|
||||
|
||||
segment.endAngle = segment.startAngle + segment.circumference;
|
||||
|
||||
segment.draw();
|
||||
if (index === 0){
|
||||
segment.startAngle = Math.PI * 1.5;
|
||||
}
|
||||
//Check to see if it's the last segment, if not get the next and update the start angle
|
||||
if (index < this.segments.length-1){
|
||||
this.segments[index+1].startAngle = segment.endAngle;
|
||||
}
|
||||
},this);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
Chart.types.Doughnut.extend({
|
||||
name : "Pie",
|
||||
defaults : helpers.merge(defaultConfig,{percentageInnerCutout : 0})
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
@@ -1,374 +0,0 @@
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
var root = this,
|
||||
Chart = root.Chart,
|
||||
helpers = Chart.helpers;
|
||||
|
||||
var defaultConfig = {
|
||||
|
||||
///Boolean - Whether grid lines are shown across the chart
|
||||
scaleShowGridLines : true,
|
||||
|
||||
//String - Colour of the grid lines
|
||||
scaleGridLineColor : "rgba(0,0,0,.05)",
|
||||
|
||||
//Number - Width of the grid lines
|
||||
scaleGridLineWidth : 1,
|
||||
|
||||
//Boolean - Whether to show horizontal lines (except X axis)
|
||||
scaleShowHorizontalLines: true,
|
||||
|
||||
//Boolean - Whether to show vertical lines (except Y axis)
|
||||
scaleShowVerticalLines: true,
|
||||
|
||||
//Boolean - Whether the line is curved between points
|
||||
bezierCurve : true,
|
||||
|
||||
//Number - Tension of the bezier curve between points
|
||||
bezierCurveTension : 0.4,
|
||||
|
||||
//Boolean - Whether to show a dot for each point
|
||||
pointDot : true,
|
||||
|
||||
//Number - Radius of each point dot in pixels
|
||||
pointDotRadius : 4,
|
||||
|
||||
//Number - Pixel width of point dot stroke
|
||||
pointDotStrokeWidth : 1,
|
||||
|
||||
//Number - amount extra to add to the radius to cater for hit detection outside the drawn point
|
||||
pointHitDetectionRadius : 20,
|
||||
|
||||
//Boolean - Whether to show a stroke for datasets
|
||||
datasetStroke : true,
|
||||
|
||||
//Number - Pixel width of dataset stroke
|
||||
datasetStrokeWidth : 2,
|
||||
|
||||
//Boolean - Whether to fill the dataset with a colour
|
||||
datasetFill : true,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
|
||||
};
|
||||
|
||||
|
||||
Chart.Type.extend({
|
||||
name: "Line",
|
||||
defaults : defaultConfig,
|
||||
initialize: function(data){
|
||||
//Declare the extension of the default point, to cater for the options passed in to the constructor
|
||||
this.PointClass = Chart.Point.extend({
|
||||
strokeWidth : this.options.pointDotStrokeWidth,
|
||||
radius : this.options.pointDotRadius,
|
||||
display: this.options.pointDot,
|
||||
hitDetectionRadius : this.options.pointHitDetectionRadius,
|
||||
ctx : this.chart.ctx,
|
||||
inRange : function(mouseX){
|
||||
return (Math.pow(mouseX-this.x, 2) < Math.pow(this.radius + this.hitDetectionRadius,2));
|
||||
}
|
||||
});
|
||||
|
||||
this.datasets = [];
|
||||
|
||||
//Set up tooltip events on the chart
|
||||
if (this.options.showTooltips){
|
||||
helpers.bindEvents(this, this.options.tooltipEvents, function(evt){
|
||||
var activePoints = (evt.type !== 'mouseout') ? this.getPointsAtEvent(evt) : [];
|
||||
this.eachPoints(function(point){
|
||||
point.restore(['fillColor', 'strokeColor']);
|
||||
});
|
||||
helpers.each(activePoints, function(activePoint){
|
||||
activePoint.fillColor = activePoint.highlightFill;
|
||||
activePoint.strokeColor = activePoint.highlightStroke;
|
||||
});
|
||||
this.showTooltip(activePoints);
|
||||
});
|
||||
}
|
||||
|
||||
//Iterate through each of the datasets, and build this into a property of the chart
|
||||
helpers.each(data.datasets,function(dataset){
|
||||
|
||||
var datasetObject = {
|
||||
label : dataset.label || null,
|
||||
fillColor : dataset.fillColor,
|
||||
strokeColor : dataset.strokeColor,
|
||||
pointColor : dataset.pointColor,
|
||||
pointStrokeColor : dataset.pointStrokeColor,
|
||||
points : []
|
||||
};
|
||||
|
||||
this.datasets.push(datasetObject);
|
||||
|
||||
|
||||
helpers.each(dataset.data,function(dataPoint,index){
|
||||
//Add a new point for each piece of data, passing any required data to draw.
|
||||
datasetObject.points.push(new this.PointClass({
|
||||
value : dataPoint,
|
||||
label : data.labels[index],
|
||||
datasetLabel: dataset.label,
|
||||
strokeColor : dataset.pointStrokeColor,
|
||||
fillColor : dataset.pointColor,
|
||||
highlightFill : dataset.pointHighlightFill || dataset.pointColor,
|
||||
highlightStroke : dataset.pointHighlightStroke || dataset.pointStrokeColor
|
||||
}));
|
||||
},this);
|
||||
|
||||
this.buildScale(data.labels);
|
||||
|
||||
|
||||
this.eachPoints(function(point, index){
|
||||
helpers.extend(point, {
|
||||
x: this.scale.calculateX(index),
|
||||
y: this.scale.endPoint
|
||||
});
|
||||
point.save();
|
||||
}, this);
|
||||
|
||||
},this);
|
||||
|
||||
|
||||
this.render();
|
||||
},
|
||||
update : function(){
|
||||
this.scale.update();
|
||||
// Reset any highlight colours before updating.
|
||||
helpers.each(this.activeElements, function(activeElement){
|
||||
activeElement.restore(['fillColor', 'strokeColor']);
|
||||
});
|
||||
this.eachPoints(function(point){
|
||||
point.save();
|
||||
});
|
||||
this.render();
|
||||
},
|
||||
eachPoints : function(callback){
|
||||
helpers.each(this.datasets,function(dataset){
|
||||
helpers.each(dataset.points,callback,this);
|
||||
},this);
|
||||
},
|
||||
getPointsAtEvent : function(e){
|
||||
var pointsArray = [],
|
||||
eventPosition = helpers.getRelativePosition(e);
|
||||
helpers.each(this.datasets,function(dataset){
|
||||
helpers.each(dataset.points,function(point){
|
||||
if (point.inRange(eventPosition.x,eventPosition.y)) pointsArray.push(point);
|
||||
});
|
||||
},this);
|
||||
return pointsArray;
|
||||
},
|
||||
buildScale : function(labels){
|
||||
var self = this;
|
||||
|
||||
var dataTotal = function(){
|
||||
var values = [];
|
||||
self.eachPoints(function(point){
|
||||
values.push(point.value);
|
||||
});
|
||||
|
||||
return values;
|
||||
};
|
||||
|
||||
var scaleOptions = {
|
||||
templateString : this.options.scaleLabel,
|
||||
height : this.chart.height,
|
||||
width : this.chart.width,
|
||||
ctx : this.chart.ctx,
|
||||
textColor : this.options.scaleFontColor,
|
||||
fontSize : this.options.scaleFontSize,
|
||||
fontStyle : this.options.scaleFontStyle,
|
||||
fontFamily : this.options.scaleFontFamily,
|
||||
valuesCount : labels.length,
|
||||
beginAtZero : this.options.scaleBeginAtZero,
|
||||
integersOnly : this.options.scaleIntegersOnly,
|
||||
calculateYRange : function(currentHeight){
|
||||
var updatedRanges = helpers.calculateScaleRange(
|
||||
dataTotal(),
|
||||
currentHeight,
|
||||
this.fontSize,
|
||||
this.beginAtZero,
|
||||
this.integersOnly
|
||||
);
|
||||
helpers.extend(this, updatedRanges);
|
||||
},
|
||||
xLabels : labels,
|
||||
font : helpers.fontString(this.options.scaleFontSize, this.options.scaleFontStyle, this.options.scaleFontFamily),
|
||||
lineWidth : this.options.scaleLineWidth,
|
||||
lineColor : this.options.scaleLineColor,
|
||||
showHorizontalLines : this.options.scaleShowHorizontalLines,
|
||||
showVerticalLines : this.options.scaleShowVerticalLines,
|
||||
gridLineWidth : (this.options.scaleShowGridLines) ? this.options.scaleGridLineWidth : 0,
|
||||
gridLineColor : (this.options.scaleShowGridLines) ? this.options.scaleGridLineColor : "rgba(0,0,0,0)",
|
||||
padding: (this.options.showScale) ? 0 : this.options.pointDotRadius + this.options.pointDotStrokeWidth,
|
||||
showLabels : this.options.scaleShowLabels,
|
||||
display : this.options.showScale
|
||||
};
|
||||
|
||||
if (this.options.scaleOverride){
|
||||
helpers.extend(scaleOptions, {
|
||||
calculateYRange: helpers.noop,
|
||||
steps: this.options.scaleSteps,
|
||||
stepValue: this.options.scaleStepWidth,
|
||||
min: this.options.scaleStartValue,
|
||||
max: this.options.scaleStartValue + (this.options.scaleSteps * this.options.scaleStepWidth)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
this.scale = new Chart.Scale(scaleOptions);
|
||||
},
|
||||
addData : function(valuesArray,label){
|
||||
//Map the values array for each of the datasets
|
||||
|
||||
helpers.each(valuesArray,function(value,datasetIndex){
|
||||
//Add a new point for each piece of data, passing any required data to draw.
|
||||
this.datasets[datasetIndex].points.push(new this.PointClass({
|
||||
value : value,
|
||||
label : label,
|
||||
x: this.scale.calculateX(this.scale.valuesCount+1),
|
||||
y: this.scale.endPoint,
|
||||
strokeColor : this.datasets[datasetIndex].pointStrokeColor,
|
||||
fillColor : this.datasets[datasetIndex].pointColor
|
||||
}));
|
||||
},this);
|
||||
|
||||
this.scale.addXLabel(label);
|
||||
//Then re-render the chart.
|
||||
this.update();
|
||||
},
|
||||
removeData : function(){
|
||||
this.scale.removeXLabel();
|
||||
//Then re-render the chart.
|
||||
helpers.each(this.datasets,function(dataset){
|
||||
dataset.points.shift();
|
||||
},this);
|
||||
this.update();
|
||||
},
|
||||
reflow : function(){
|
||||
var newScaleProps = helpers.extend({
|
||||
height : this.chart.height,
|
||||
width : this.chart.width
|
||||
});
|
||||
this.scale.update(newScaleProps);
|
||||
},
|
||||
draw : function(ease){
|
||||
var easingDecimal = ease || 1;
|
||||
this.clear();
|
||||
|
||||
var ctx = this.chart.ctx;
|
||||
|
||||
// Some helper methods for getting the next/prev points
|
||||
var hasValue = function(item){
|
||||
return item.value !== null;
|
||||
},
|
||||
nextPoint = function(point, collection, index){
|
||||
return helpers.findNextWhere(collection, hasValue, index) || point;
|
||||
},
|
||||
previousPoint = function(point, collection, index){
|
||||
return helpers.findPreviousWhere(collection, hasValue, index) || point;
|
||||
};
|
||||
|
||||
this.scale.draw(easingDecimal);
|
||||
|
||||
|
||||
helpers.each(this.datasets,function(dataset){
|
||||
var pointsWithValues = helpers.where(dataset.points, hasValue);
|
||||
|
||||
//Transition each point first so that the line and point drawing isn't out of sync
|
||||
//We can use this extra loop to calculate the control points of this dataset also in this loop
|
||||
|
||||
helpers.each(dataset.points, function(point, index){
|
||||
if (point.hasValue()){
|
||||
point.transition({
|
||||
y : this.scale.calculateY(point.value),
|
||||
x : this.scale.calculateX(index)
|
||||
}, easingDecimal);
|
||||
}
|
||||
},this);
|
||||
|
||||
|
||||
// Control points need to be calculated in a seperate loop, because we need to know the current x/y of the point
|
||||
// This would cause issues when there is no animation, because the y of the next point would be 0, so beziers would be skewed
|
||||
if (this.options.bezierCurve){
|
||||
helpers.each(pointsWithValues, function(point, index){
|
||||
var tension = (index > 0 && index < pointsWithValues.length - 1) ? this.options.bezierCurveTension : 0;
|
||||
point.controlPoints = helpers.splineCurve(
|
||||
previousPoint(point, pointsWithValues, index),
|
||||
point,
|
||||
nextPoint(point, pointsWithValues, index),
|
||||
tension
|
||||
);
|
||||
|
||||
// Prevent the bezier going outside of the bounds of the graph
|
||||
|
||||
// Cap puter bezier handles to the upper/lower scale bounds
|
||||
if (point.controlPoints.outer.y > this.scale.endPoint){
|
||||
point.controlPoints.outer.y = this.scale.endPoint;
|
||||
}
|
||||
else if (point.controlPoints.outer.y < this.scale.startPoint){
|
||||
point.controlPoints.outer.y = this.scale.startPoint;
|
||||
}
|
||||
|
||||
// Cap inner bezier handles to the upper/lower scale bounds
|
||||
if (point.controlPoints.inner.y > this.scale.endPoint){
|
||||
point.controlPoints.inner.y = this.scale.endPoint;
|
||||
}
|
||||
else if (point.controlPoints.inner.y < this.scale.startPoint){
|
||||
point.controlPoints.inner.y = this.scale.startPoint;
|
||||
}
|
||||
},this);
|
||||
}
|
||||
|
||||
|
||||
//Draw the line between all the points
|
||||
ctx.lineWidth = this.options.datasetStrokeWidth;
|
||||
ctx.strokeStyle = dataset.strokeColor;
|
||||
ctx.beginPath();
|
||||
|
||||
helpers.each(pointsWithValues, function(point, index){
|
||||
if (index === 0){
|
||||
ctx.moveTo(point.x, point.y);
|
||||
}
|
||||
else{
|
||||
if(this.options.bezierCurve){
|
||||
var previous = previousPoint(point, pointsWithValues, index);
|
||||
|
||||
ctx.bezierCurveTo(
|
||||
previous.controlPoints.outer.x,
|
||||
previous.controlPoints.outer.y,
|
||||
point.controlPoints.inner.x,
|
||||
point.controlPoints.inner.y,
|
||||
point.x,
|
||||
point.y
|
||||
);
|
||||
}
|
||||
else{
|
||||
ctx.lineTo(point.x,point.y);
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
ctx.stroke();
|
||||
|
||||
if (this.options.datasetFill && pointsWithValues.length > 0){
|
||||
//Round off the line by going to the base of the chart, back to the start, then fill.
|
||||
ctx.lineTo(pointsWithValues[pointsWithValues.length - 1].x, this.scale.endPoint);
|
||||
ctx.lineTo(pointsWithValues[0].x, this.scale.endPoint);
|
||||
ctx.fillStyle = dataset.fillColor;
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
//Now draw the points over the line
|
||||
//A little inefficient double looping, but better than the line
|
||||
//lagging behind the point positions
|
||||
helpers.each(pointsWithValues,function(point){
|
||||
point.draw();
|
||||
});
|
||||
},this);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}).call(this);
|
||||
@@ -1,250 +0,0 @@
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
var root = this,
|
||||
Chart = root.Chart,
|
||||
//Cache a local reference to Chart.helpers
|
||||
helpers = Chart.helpers;
|
||||
|
||||
var defaultConfig = {
|
||||
//Boolean - Show a backdrop to the scale label
|
||||
scaleShowLabelBackdrop : true,
|
||||
|
||||
//String - The colour of the label backdrop
|
||||
scaleBackdropColor : "rgba(255,255,255,0.75)",
|
||||
|
||||
// Boolean - Whether the scale should begin at zero
|
||||
scaleBeginAtZero : true,
|
||||
|
||||
//Number - The backdrop padding above & below the label in pixels
|
||||
scaleBackdropPaddingY : 2,
|
||||
|
||||
//Number - The backdrop padding to the side of the label in pixels
|
||||
scaleBackdropPaddingX : 2,
|
||||
|
||||
//Boolean - Show line for each value in the scale
|
||||
scaleShowLine : true,
|
||||
|
||||
//Boolean - Stroke a line around each segment in the chart
|
||||
segmentShowStroke : true,
|
||||
|
||||
//String - The colour of the stroke on each segement.
|
||||
segmentStrokeColor : "#fff",
|
||||
|
||||
//Number - The width of the stroke value in pixels
|
||||
segmentStrokeWidth : 2,
|
||||
|
||||
//Number - Amount of animation steps
|
||||
animationSteps : 100,
|
||||
|
||||
//String - Animation easing effect.
|
||||
animationEasing : "easeOutBounce",
|
||||
|
||||
//Boolean - Whether to animate the rotation of the chart
|
||||
animateRotate : true,
|
||||
|
||||
//Boolean - Whether to animate scaling the chart from the centre
|
||||
animateScale : false,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>"
|
||||
};
|
||||
|
||||
|
||||
Chart.Type.extend({
|
||||
//Passing in a name registers this chart in the Chart namespace
|
||||
name: "PolarArea",
|
||||
//Providing a defaults will also register the deafults in the chart namespace
|
||||
defaults : defaultConfig,
|
||||
//Initialize is fired when the chart is initialized - Data is passed in as a parameter
|
||||
//Config is automatically merged by the core of Chart.js, and is available at this.options
|
||||
initialize: function(data){
|
||||
this.segments = [];
|
||||
//Declare segment class as a chart instance specific class, so it can share props for this instance
|
||||
this.SegmentArc = Chart.Arc.extend({
|
||||
showStroke : this.options.segmentShowStroke,
|
||||
strokeWidth : this.options.segmentStrokeWidth,
|
||||
strokeColor : this.options.segmentStrokeColor,
|
||||
ctx : this.chart.ctx,
|
||||
innerRadius : 0,
|
||||
x : this.chart.width/2,
|
||||
y : this.chart.height/2
|
||||
});
|
||||
this.scale = new Chart.RadialScale({
|
||||
display: this.options.showScale,
|
||||
fontStyle: this.options.scaleFontStyle,
|
||||
fontSize: this.options.scaleFontSize,
|
||||
fontFamily: this.options.scaleFontFamily,
|
||||
fontColor: this.options.scaleFontColor,
|
||||
showLabels: this.options.scaleShowLabels,
|
||||
showLabelBackdrop: this.options.scaleShowLabelBackdrop,
|
||||
backdropColor: this.options.scaleBackdropColor,
|
||||
backdropPaddingY : this.options.scaleBackdropPaddingY,
|
||||
backdropPaddingX: this.options.scaleBackdropPaddingX,
|
||||
lineWidth: (this.options.scaleShowLine) ? this.options.scaleLineWidth : 0,
|
||||
lineColor: this.options.scaleLineColor,
|
||||
lineArc: true,
|
||||
width: this.chart.width,
|
||||
height: this.chart.height,
|
||||
xCenter: this.chart.width/2,
|
||||
yCenter: this.chart.height/2,
|
||||
ctx : this.chart.ctx,
|
||||
templateString: this.options.scaleLabel,
|
||||
valuesCount: data.length
|
||||
});
|
||||
|
||||
this.updateScaleRange(data);
|
||||
|
||||
this.scale.update();
|
||||
|
||||
helpers.each(data,function(segment,index){
|
||||
this.addData(segment,index,true);
|
||||
},this);
|
||||
|
||||
//Set up tooltip events on the chart
|
||||
if (this.options.showTooltips){
|
||||
helpers.bindEvents(this, this.options.tooltipEvents, function(evt){
|
||||
var activeSegments = (evt.type !== 'mouseout') ? this.getSegmentsAtEvent(evt) : [];
|
||||
helpers.each(this.segments,function(segment){
|
||||
segment.restore(["fillColor"]);
|
||||
});
|
||||
helpers.each(activeSegments,function(activeSegment){
|
||||
activeSegment.fillColor = activeSegment.highlightColor;
|
||||
});
|
||||
this.showTooltip(activeSegments);
|
||||
});
|
||||
}
|
||||
|
||||
this.render();
|
||||
},
|
||||
getSegmentsAtEvent : function(e){
|
||||
var segmentsArray = [];
|
||||
|
||||
var location = helpers.getRelativePosition(e);
|
||||
|
||||
helpers.each(this.segments,function(segment){
|
||||
if (segment.inRange(location.x,location.y)) segmentsArray.push(segment);
|
||||
},this);
|
||||
return segmentsArray;
|
||||
},
|
||||
addData : function(segment, atIndex, silent){
|
||||
var index = atIndex || this.segments.length;
|
||||
|
||||
this.segments.splice(index, 0, new this.SegmentArc({
|
||||
fillColor: segment.color,
|
||||
highlightColor: segment.highlight || segment.color,
|
||||
label: segment.label,
|
||||
value: segment.value,
|
||||
outerRadius: (this.options.animateScale) ? 0 : this.scale.calculateCenterOffset(segment.value),
|
||||
circumference: (this.options.animateRotate) ? 0 : this.scale.getCircumference(),
|
||||
startAngle: Math.PI * 1.5
|
||||
}));
|
||||
if (!silent){
|
||||
this.reflow();
|
||||
this.update();
|
||||
}
|
||||
},
|
||||
removeData: function(atIndex){
|
||||
var indexToDelete = (helpers.isNumber(atIndex)) ? atIndex : this.segments.length-1;
|
||||
this.segments.splice(indexToDelete, 1);
|
||||
this.reflow();
|
||||
this.update();
|
||||
},
|
||||
calculateTotal: function(data){
|
||||
this.total = 0;
|
||||
helpers.each(data,function(segment){
|
||||
this.total += segment.value;
|
||||
},this);
|
||||
this.scale.valuesCount = this.segments.length;
|
||||
},
|
||||
updateScaleRange: function(datapoints){
|
||||
var valuesArray = [];
|
||||
helpers.each(datapoints,function(segment){
|
||||
valuesArray.push(segment.value);
|
||||
});
|
||||
|
||||
var scaleSizes = (this.options.scaleOverride) ?
|
||||
{
|
||||
steps: this.options.scaleSteps,
|
||||
stepValue: this.options.scaleStepWidth,
|
||||
min: this.options.scaleStartValue,
|
||||
max: this.options.scaleStartValue + (this.options.scaleSteps * this.options.scaleStepWidth)
|
||||
} :
|
||||
helpers.calculateScaleRange(
|
||||
valuesArray,
|
||||
helpers.min([this.chart.width, this.chart.height])/2,
|
||||
this.options.scaleFontSize,
|
||||
this.options.scaleBeginAtZero,
|
||||
this.options.scaleIntegersOnly
|
||||
);
|
||||
|
||||
helpers.extend(
|
||||
this.scale,
|
||||
scaleSizes,
|
||||
{
|
||||
size: helpers.min([this.chart.width, this.chart.height]),
|
||||
xCenter: this.chart.width/2,
|
||||
yCenter: this.chart.height/2
|
||||
}
|
||||
);
|
||||
|
||||
},
|
||||
update : function(){
|
||||
this.calculateTotal(this.segments);
|
||||
|
||||
helpers.each(this.segments,function(segment){
|
||||
segment.save();
|
||||
});
|
||||
|
||||
this.reflow();
|
||||
this.render();
|
||||
},
|
||||
reflow : function(){
|
||||
helpers.extend(this.SegmentArc.prototype,{
|
||||
x : this.chart.width/2,
|
||||
y : this.chart.height/2
|
||||
});
|
||||
this.updateScaleRange(this.segments);
|
||||
this.scale.update();
|
||||
|
||||
helpers.extend(this.scale,{
|
||||
xCenter: this.chart.width/2,
|
||||
yCenter: this.chart.height/2
|
||||
});
|
||||
|
||||
helpers.each(this.segments, function(segment){
|
||||
segment.update({
|
||||
outerRadius : this.scale.calculateCenterOffset(segment.value)
|
||||
});
|
||||
}, this);
|
||||
|
||||
},
|
||||
draw : function(ease){
|
||||
var easingDecimal = ease || 1;
|
||||
//Clear & draw the canvas
|
||||
this.clear();
|
||||
helpers.each(this.segments,function(segment, index){
|
||||
segment.transition({
|
||||
circumference : this.scale.getCircumference(),
|
||||
outerRadius : this.scale.calculateCenterOffset(segment.value)
|
||||
},easingDecimal);
|
||||
|
||||
segment.endAngle = segment.startAngle + segment.circumference;
|
||||
|
||||
// If we've removed the first segment we need to set the first one to
|
||||
// start at the top.
|
||||
if (index === 0){
|
||||
segment.startAngle = Math.PI * 1.5;
|
||||
}
|
||||
|
||||
//Check to see if it's the last segment, if not get the next and update the start angle
|
||||
if (index < this.segments.length - 1){
|
||||
this.segments[index+1].startAngle = segment.endAngle;
|
||||
}
|
||||
segment.draw();
|
||||
}, this);
|
||||
this.scale.draw();
|
||||
}
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
@@ -1,343 +0,0 @@
|
||||
(function(){
|
||||
"use strict";
|
||||
|
||||
var root = this,
|
||||
Chart = root.Chart,
|
||||
helpers = Chart.helpers;
|
||||
|
||||
|
||||
|
||||
Chart.Type.extend({
|
||||
name: "Radar",
|
||||
defaults:{
|
||||
//Boolean - Whether to show lines for each scale point
|
||||
scaleShowLine : true,
|
||||
|
||||
//Boolean - Whether we show the angle lines out of the radar
|
||||
angleShowLineOut : true,
|
||||
|
||||
//Boolean - Whether to show labels on the scale
|
||||
scaleShowLabels : false,
|
||||
|
||||
// Boolean - Whether the scale should begin at zero
|
||||
scaleBeginAtZero : true,
|
||||
|
||||
//String - Colour of the angle line
|
||||
angleLineColor : "rgba(0,0,0,.1)",
|
||||
|
||||
//Number - Pixel width of the angle line
|
||||
angleLineWidth : 1,
|
||||
|
||||
//String - Point label font declaration
|
||||
pointLabelFontFamily : "'Arial'",
|
||||
|
||||
//String - Point label font weight
|
||||
pointLabelFontStyle : "normal",
|
||||
|
||||
//Number - Point label font size in pixels
|
||||
pointLabelFontSize : 10,
|
||||
|
||||
//String - Point label font colour
|
||||
pointLabelFontColor : "#666",
|
||||
|
||||
//Boolean - Whether to show a dot for each point
|
||||
pointDot : true,
|
||||
|
||||
//Number - Radius of each point dot in pixels
|
||||
pointDotRadius : 3,
|
||||
|
||||
//Number - Pixel width of point dot stroke
|
||||
pointDotStrokeWidth : 1,
|
||||
|
||||
//Number - amount extra to add to the radius to cater for hit detection outside the drawn point
|
||||
pointHitDetectionRadius : 20,
|
||||
|
||||
//Boolean - Whether to show a stroke for datasets
|
||||
datasetStroke : true,
|
||||
|
||||
//Number - Pixel width of dataset stroke
|
||||
datasetStrokeWidth : 2,
|
||||
|
||||
//Boolean - Whether to fill the dataset with a colour
|
||||
datasetFill : true,
|
||||
|
||||
//String - A legend template
|
||||
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
|
||||
},
|
||||
|
||||
initialize: function(data){
|
||||
this.PointClass = Chart.Point.extend({
|
||||
strokeWidth : this.options.pointDotStrokeWidth,
|
||||
radius : this.options.pointDotRadius,
|
||||
display: this.options.pointDot,
|
||||
hitDetectionRadius : this.options.pointHitDetectionRadius,
|
||||
ctx : this.chart.ctx
|
||||
});
|
||||
|
||||
this.datasets = [];
|
||||
|
||||
this.buildScale(data);
|
||||
|
||||
//Set up tooltip events on the chart
|
||||
if (this.options.showTooltips){
|
||||
helpers.bindEvents(this, this.options.tooltipEvents, function(evt){
|
||||
var activePointsCollection = (evt.type !== 'mouseout') ? this.getPointsAtEvent(evt) : [];
|
||||
|
||||
this.eachPoints(function(point){
|
||||
point.restore(['fillColor', 'strokeColor']);
|
||||
});
|
||||
helpers.each(activePointsCollection, function(activePoint){
|
||||
activePoint.fillColor = activePoint.highlightFill;
|
||||
activePoint.strokeColor = activePoint.highlightStroke;
|
||||
});
|
||||
|
||||
this.showTooltip(activePointsCollection);
|
||||
});
|
||||
}
|
||||
|
||||
//Iterate through each of the datasets, and build this into a property of the chart
|
||||
helpers.each(data.datasets,function(dataset){
|
||||
|
||||
var datasetObject = {
|
||||
label: dataset.label || null,
|
||||
fillColor : dataset.fillColor,
|
||||
strokeColor : dataset.strokeColor,
|
||||
pointColor : dataset.pointColor,
|
||||
pointStrokeColor : dataset.pointStrokeColor,
|
||||
points : []
|
||||
};
|
||||
|
||||
this.datasets.push(datasetObject);
|
||||
|
||||
helpers.each(dataset.data,function(dataPoint,index){
|
||||
//Add a new point for each piece of data, passing any required data to draw.
|
||||
var pointPosition;
|
||||
if (!this.scale.animation){
|
||||
pointPosition = this.scale.getPointPosition(index, this.scale.calculateCenterOffset(dataPoint));
|
||||
}
|
||||
datasetObject.points.push(new this.PointClass({
|
||||
value : dataPoint,
|
||||
label : data.labels[index],
|
||||
datasetLabel: dataset.label,
|
||||
x: (this.options.animation) ? this.scale.xCenter : pointPosition.x,
|
||||
y: (this.options.animation) ? this.scale.yCenter : pointPosition.y,
|
||||
strokeColor : dataset.pointStrokeColor,
|
||||
fillColor : dataset.pointColor,
|
||||
highlightFill : dataset.pointHighlightFill || dataset.pointColor,
|
||||
highlightStroke : dataset.pointHighlightStroke || dataset.pointStrokeColor
|
||||
}));
|
||||
},this);
|
||||
|
||||
},this);
|
||||
|
||||
this.render();
|
||||
},
|
||||
eachPoints : function(callback){
|
||||
helpers.each(this.datasets,function(dataset){
|
||||
helpers.each(dataset.points,callback,this);
|
||||
},this);
|
||||
},
|
||||
|
||||
getPointsAtEvent : function(evt){
|
||||
var mousePosition = helpers.getRelativePosition(evt),
|
||||
fromCenter = helpers.getAngleFromPoint({
|
||||
x: this.scale.xCenter,
|
||||
y: this.scale.yCenter
|
||||
}, mousePosition);
|
||||
|
||||
var anglePerIndex = (Math.PI * 2) /this.scale.valuesCount,
|
||||
pointIndex = Math.round((fromCenter.angle - Math.PI * 1.5) / anglePerIndex),
|
||||
activePointsCollection = [];
|
||||
|
||||
// If we're at the top, make the pointIndex 0 to get the first of the array.
|
||||
if (pointIndex >= this.scale.valuesCount || pointIndex < 0){
|
||||
pointIndex = 0;
|
||||
}
|
||||
|
||||
if (fromCenter.distance <= this.scale.drawingArea){
|
||||
helpers.each(this.datasets, function(dataset){
|
||||
activePointsCollection.push(dataset.points[pointIndex]);
|
||||
});
|
||||
}
|
||||
|
||||
return activePointsCollection;
|
||||
},
|
||||
|
||||
buildScale : function(data){
|
||||
this.scale = new Chart.RadialScale({
|
||||
display: this.options.showScale,
|
||||
fontStyle: this.options.scaleFontStyle,
|
||||
fontSize: this.options.scaleFontSize,
|
||||
fontFamily: this.options.scaleFontFamily,
|
||||
fontColor: this.options.scaleFontColor,
|
||||
showLabels: this.options.scaleShowLabels,
|
||||
showLabelBackdrop: this.options.scaleShowLabelBackdrop,
|
||||
backdropColor: this.options.scaleBackdropColor,
|
||||
backdropPaddingY : this.options.scaleBackdropPaddingY,
|
||||
backdropPaddingX: this.options.scaleBackdropPaddingX,
|
||||
lineWidth: (this.options.scaleShowLine) ? this.options.scaleLineWidth : 0,
|
||||
lineColor: this.options.scaleLineColor,
|
||||
angleLineColor : this.options.angleLineColor,
|
||||
angleLineWidth : (this.options.angleShowLineOut) ? this.options.angleLineWidth : 0,
|
||||
// Point labels at the edge of each line
|
||||
pointLabelFontColor : this.options.pointLabelFontColor,
|
||||
pointLabelFontSize : this.options.pointLabelFontSize,
|
||||
pointLabelFontFamily : this.options.pointLabelFontFamily,
|
||||
pointLabelFontStyle : this.options.pointLabelFontStyle,
|
||||
height : this.chart.height,
|
||||
width: this.chart.width,
|
||||
xCenter: this.chart.width/2,
|
||||
yCenter: this.chart.height/2,
|
||||
ctx : this.chart.ctx,
|
||||
templateString: this.options.scaleLabel,
|
||||
labels: data.labels,
|
||||
valuesCount: data.datasets[0].data.length
|
||||
});
|
||||
|
||||
this.scale.setScaleSize();
|
||||
this.updateScaleRange(data.datasets);
|
||||
this.scale.buildYLabels();
|
||||
},
|
||||
updateScaleRange: function(datasets){
|
||||
var valuesArray = (function(){
|
||||
var totalDataArray = [];
|
||||
helpers.each(datasets,function(dataset){
|
||||
if (dataset.data){
|
||||
totalDataArray = totalDataArray.concat(dataset.data);
|
||||
}
|
||||
else {
|
||||
helpers.each(dataset.points, function(point){
|
||||
totalDataArray.push(point.value);
|
||||
});
|
||||
}
|
||||
});
|
||||
return totalDataArray;
|
||||
})();
|
||||
|
||||
|
||||
var scaleSizes = (this.options.scaleOverride) ?
|
||||
{
|
||||
steps: this.options.scaleSteps,
|
||||
stepValue: this.options.scaleStepWidth,
|
||||
min: this.options.scaleStartValue,
|
||||
max: this.options.scaleStartValue + (this.options.scaleSteps * this.options.scaleStepWidth)
|
||||
} :
|
||||
helpers.calculateScaleRange(
|
||||
valuesArray,
|
||||
helpers.min([this.chart.width, this.chart.height])/2,
|
||||
this.options.scaleFontSize,
|
||||
this.options.scaleBeginAtZero,
|
||||
this.options.scaleIntegersOnly
|
||||
);
|
||||
|
||||
helpers.extend(
|
||||
this.scale,
|
||||
scaleSizes
|
||||
);
|
||||
|
||||
},
|
||||
addData : function(valuesArray,label){
|
||||
//Map the values array for each of the datasets
|
||||
this.scale.valuesCount++;
|
||||
helpers.each(valuesArray,function(value,datasetIndex){
|
||||
var pointPosition = this.scale.getPointPosition(this.scale.valuesCount, this.scale.calculateCenterOffset(value));
|
||||
this.datasets[datasetIndex].points.push(new this.PointClass({
|
||||
value : value,
|
||||
label : label,
|
||||
x: pointPosition.x,
|
||||
y: pointPosition.y,
|
||||
strokeColor : this.datasets[datasetIndex].pointStrokeColor,
|
||||
fillColor : this.datasets[datasetIndex].pointColor
|
||||
}));
|
||||
},this);
|
||||
|
||||
this.scale.labels.push(label);
|
||||
|
||||
this.reflow();
|
||||
|
||||
this.update();
|
||||
},
|
||||
removeData : function(){
|
||||
this.scale.valuesCount--;
|
||||
this.scale.labels.shift();
|
||||
helpers.each(this.datasets,function(dataset){
|
||||
dataset.points.shift();
|
||||
},this);
|
||||
this.reflow();
|
||||
this.update();
|
||||
},
|
||||
update : function(){
|
||||
this.eachPoints(function(point){
|
||||
point.save();
|
||||
});
|
||||
this.reflow();
|
||||
this.render();
|
||||
},
|
||||
reflow: function(){
|
||||
helpers.extend(this.scale, {
|
||||
width : this.chart.width,
|
||||
height: this.chart.height,
|
||||
size : helpers.min([this.chart.width, this.chart.height]),
|
||||
xCenter: this.chart.width/2,
|
||||
yCenter: this.chart.height/2
|
||||
});
|
||||
this.updateScaleRange(this.datasets);
|
||||
this.scale.setScaleSize();
|
||||
this.scale.buildYLabels();
|
||||
},
|
||||
draw : function(ease){
|
||||
var easeDecimal = ease || 1,
|
||||
ctx = this.chart.ctx;
|
||||
this.clear();
|
||||
this.scale.draw();
|
||||
|
||||
helpers.each(this.datasets,function(dataset){
|
||||
|
||||
//Transition each point first so that the line and point drawing isn't out of sync
|
||||
helpers.each(dataset.points,function(point,index){
|
||||
if (point.hasValue()){
|
||||
point.transition(this.scale.getPointPosition(index, this.scale.calculateCenterOffset(point.value)), easeDecimal);
|
||||
}
|
||||
},this);
|
||||
|
||||
|
||||
|
||||
//Draw the line between all the points
|
||||
ctx.lineWidth = this.options.datasetStrokeWidth;
|
||||
ctx.strokeStyle = dataset.strokeColor;
|
||||
ctx.beginPath();
|
||||
helpers.each(dataset.points,function(point,index){
|
||||
if (index === 0){
|
||||
ctx.moveTo(point.x,point.y);
|
||||
}
|
||||
else{
|
||||
ctx.lineTo(point.x,point.y);
|
||||
}
|
||||
},this);
|
||||
ctx.closePath();
|
||||
ctx.stroke();
|
||||
|
||||
ctx.fillStyle = dataset.fillColor;
|
||||
ctx.fill();
|
||||
|
||||
//Now draw the points over the line
|
||||
//A little inefficient double looping, but better than the line
|
||||
//lagging behind the point positions
|
||||
helpers.each(dataset.points,function(point){
|
||||
if (point.hasValue()){
|
||||
point.draw();
|
||||
}
|
||||
});
|
||||
|
||||
},this);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}).call(this);
|
||||
Referência em uma Nova Issue
Bloquear um usuário