mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
commit
f13f99b7d7
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,2 +1,7 @@
|
||||
|
||||
.DS_Store
|
||||
|
||||
node_modules/*
|
||||
custom/*
|
||||
|
||||
docs/index.md
|
||||
|
||||
4608
Chart.js
vendored
Executable file → Normal file
4608
Chart.js
vendored
Executable file → Normal file
File diff suppressed because it is too large
Load Diff
49
Chart.min.js
vendored
49
Chart.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,8 +1,7 @@
|
||||
{
|
||||
"name": "Chart.js",
|
||||
"version": "0.2.0",
|
||||
"version": "1.0.0-beta",
|
||||
"description": "Simple HTML5 Charts using the canvas element",
|
||||
"keywords": ["charts"],
|
||||
"homepage": "https://github.com/nnnick/Chart.js",
|
||||
"author": "nnnick",
|
||||
"main": ["Chart.min.js"],
|
||||
197
docs/00-Getting-Started.md
Normal file
197
docs/00-Getting-Started.md
Normal file
@ -0,0 +1,197 @@
|
||||
---
|
||||
title: Getting started
|
||||
anchor: getting-started
|
||||
---
|
||||
|
||||
###Include Chart.js
|
||||
|
||||
First we need to include the Chart.js library on the page. The library occupies a global variable of `Chart`.
|
||||
|
||||
```html
|
||||
<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.
|
||||
|
||||
```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
|
||||
// The function returns what was previously Chart, allowing you to reassign.
|
||||
var Chartjs = Chart.noConflict();
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
You can also grab Chart.js using bower:
|
||||
|
||||
```bash
|
||||
bower install chartjs --save
|
||||
```
|
||||
|
||||
###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.
|
||||
|
||||
```html
|
||||
<canvas id="myChart" width="400" height="400"></canvas>
|
||||
```
|
||||
|
||||
```javascript
|
||||
// Get the context of the canvas element we want to select
|
||||
var ctx = document.getElementById("myChart").getContext("2d");
|
||||
var myNewChart = new Chart(ctx).PolarArea(data);
|
||||
```
|
||||
|
||||
We can also get the context of our canvas with jQuery. To do this, we need to get the DOM node out of the jQuery collection, and call the `getContext("2d")` method on that.
|
||||
|
||||
```javascript
|
||||
// Get context with jQuery - using jQuery's .get() method.
|
||||
var ctx = $("#myChart").get(0).getContext("2d");
|
||||
// This will get the first returned node in the jQuery collection.
|
||||
var myNewChart = new Chart(ctx);
|
||||
```
|
||||
|
||||
After we've instantiated the Chart class on the canvas we want to draw on, Chart.js will handle the scaling for retina displays.
|
||||
|
||||
With the Chart class set up, we can go on to create one of the charts Chart.js has available. In the example below, we would be drawing a Polar area chart.
|
||||
|
||||
```javascript
|
||||
new Chart(ctx).PolarArea(data, options);
|
||||
```
|
||||
|
||||
We call a method of the name of the chart we want to create. We pass in the data for that chart type, and the options for that chart as parameters. Chart.js will merge the global defaults with chart type specific defaults, then merge any options passed in as a second argument after data.
|
||||
|
||||
###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.
|
||||
|
||||
```javascript
|
||||
Chart.defaults.global = {
|
||||
// Boolean - Whether to animate the chart
|
||||
animation: true,
|
||||
|
||||
// Number - Number of animation steps
|
||||
animationSteps: 60,
|
||||
|
||||
// String - Animation easing effect
|
||||
animationEasing: "easeOutQuart",
|
||||
|
||||
// Boolean - If we should show the scale at all
|
||||
showScale: true,
|
||||
|
||||
// Boolean - If we want to override with a hard coded scale
|
||||
scaleOverride: false,
|
||||
|
||||
// ** Required if scaleOverride is true **
|
||||
// Number - The number of steps in a hard coded scale
|
||||
scaleSteps: null,
|
||||
// Number - The value jump in the hard coded scale
|
||||
scaleStepWidth: null,
|
||||
// Number - The scale starting value
|
||||
scaleStartValue: null,
|
||||
|
||||
// String - Colour of the scale line
|
||||
scaleLineColor: "rgba(0,0,0,.1)",
|
||||
|
||||
// Number - Pixel width of the scale line
|
||||
scaleLineWidth: 1,
|
||||
|
||||
// Boolean - Whether to show labels on the scale
|
||||
scaleShowLabels: true,
|
||||
|
||||
// Interpolated JS string - can access value
|
||||
scaleLabel: "<%=value%>",
|
||||
|
||||
// Boolean - Whether the scale should stick to integers, not floats even if drawing space is there
|
||||
scaleIntegersOnly: true,
|
||||
|
||||
// Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
|
||||
scaleBeginAtZero: false,
|
||||
|
||||
// String - Scale label font declaration for the scale label
|
||||
scaleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
|
||||
|
||||
// Number - Scale label font size in pixels
|
||||
scaleFontSize: 12,
|
||||
|
||||
// String - Scale label font weight style
|
||||
scaleFontStyle: "normal",
|
||||
|
||||
// String - Scale label font colour
|
||||
scaleFontColor: "#666",
|
||||
|
||||
// Boolean - whether or not the chart should be responsive and resize when the browser does.
|
||||
responsive: false,
|
||||
|
||||
// Boolean - Determines whether to draw tooltips on the canvas or not
|
||||
showTooltips: true,
|
||||
|
||||
// Array - Array of string names to attach tooltip events
|
||||
tooltipEvents: ["mousemove", "touchstart", "touchmove"],
|
||||
|
||||
// String - Tooltip background colour
|
||||
tooltipFillColor: "rgba(0,0,0,0.8)",
|
||||
|
||||
// String - Tooltip label font declaration for the scale label
|
||||
tooltipFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
|
||||
|
||||
// Number - Tooltip label font size in pixels
|
||||
tooltipFontSize: 14,
|
||||
|
||||
// String - Tooltip font weight style
|
||||
tooltipFontStyle: "normal",
|
||||
|
||||
// String - Tooltip label font colour
|
||||
tooltipFontColor: "#fff",
|
||||
|
||||
// String - Tooltip title font declaration for the scale label
|
||||
tooltipTitleFontFamily: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",
|
||||
|
||||
// Number - Tooltip title font size in pixels
|
||||
tooltipTitleFontSize: 14,
|
||||
|
||||
// String - Tooltip title font weight style
|
||||
tooltipTitleFontStyle: "bold",
|
||||
|
||||
// String - Tooltip title font colour
|
||||
tooltipTitleFontColor: "#fff",
|
||||
|
||||
// Number - pixel width of padding around tooltip text
|
||||
tooltipYPadding: 6,
|
||||
|
||||
// Number - pixel width of padding around tooltip text
|
||||
tooltipXPadding: 6,
|
||||
|
||||
// Number - Size of the caret on the tooltip
|
||||
tooltipCaretSize: 8,
|
||||
|
||||
// Number - Pixel radius of the tooltip border
|
||||
tooltipCornerRadius: 6,
|
||||
|
||||
// Number - Pixel offset from point x to tooltip edge
|
||||
tooltipXOffset: 10,
|
||||
{% raw %}
|
||||
// String - Template string for single tooltips
|
||||
tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value %>",
|
||||
{% endraw %}
|
||||
// String - Template string for single tooltips
|
||||
multiTooltipTemplate: "<%= value %>",
|
||||
|
||||
// Function - Will fire on animation progression.
|
||||
onAnimationProgress: function(){},
|
||||
|
||||
// Function - Will fire on animation completion.
|
||||
onAnimationComplete: function(){}
|
||||
}
|
||||
```
|
||||
|
||||
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`.
|
||||
160
docs/01-Line-Chart.md
Normal file
160
docs/01-Line-Chart.md
Normal file
@ -0,0 +1,160 @@
|
||||
---
|
||||
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).Line(data, options);
|
||||
```
|
||||
###Data structure
|
||||
|
||||
```javascript
|
||||
var data = {
|
||||
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: [65, 59, 80, 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, 86, 27, 90]
|
||||
}
|
||||
]
|
||||
};
|
||||
```
|
||||
|
||||
The line chart requires an array of labels for each of the data points. This is shown on the X axis.
|
||||
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.
|
||||
|
||||
```javascript
|
||||
{
|
||||
|
||||
///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 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,
|
||||
{% 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].lineColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
{% endraw %}
|
||||
};
|
||||
```
|
||||
|
||||
You can override these for your `Chart` instance by passing a second argument into the `Line` method as an object with the keys you want to override.
|
||||
|
||||
For example, we could have a line chart without bezier curves between points by doing the following:
|
||||
|
||||
```javascript
|
||||
new Chart(ctx).Line(data, {
|
||||
bezierCurve: 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 `bezierCurve` set to false.
|
||||
```
|
||||
|
||||
We can also change these defaults values for each Line type that is created, this object is available at `Chart.defaults.Line`.
|
||||
|
||||
|
||||
### Prototype methods
|
||||
|
||||
#### .getPointsAtEvent( event )
|
||||
|
||||
Calling `getPointsAtEvent(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.getPointsAtEvent(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.
|
||||
|
||||
#### .update( )
|
||||
|
||||
Calling `update()` on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those in one animated render loop.
|
||||
|
||||
```javascript
|
||||
myLineChart.datasets[0].points[2].value = 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.
|
||||
```
|
||||
|
||||
#### .addData( valuesArray, label )
|
||||
|
||||
Calling `addData(valuesArray, label)` on your Chart instance passing an array of values for each dataset, along with a label for those points.
|
||||
|
||||
```javascript
|
||||
// The values array passed into addData should be one for each dataset in the chart
|
||||
myLineChart.addData([40, 60], "August");
|
||||
// This new data will now animate at the end of the chart.
|
||||
```
|
||||
|
||||
#### .removeData( )
|
||||
|
||||
Calling `removeData()` on your Chart instance will remove the first value for all datasets on the chart.
|
||||
|
||||
```javascript
|
||||
myLineChart.removeData();
|
||||
// The chart will remove the first point and animate other points into place
|
||||
```
|
||||
143
docs/02-Bar-Chart.md
Normal file
143
docs/02-Bar-Chart.md
Normal file
@ -0,0 +1,143 @@
|
||||
---
|
||||
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).Bar(data, options);
|
||||
```
|
||||
|
||||
### Data structure
|
||||
|
||||
```javascript
|
||||
var data = {
|
||||
labels: ["January", "February", "March", "April", "May", "June", "July"],
|
||||
datasets: [
|
||||
{
|
||||
label: "My First dataset",
|
||||
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: [65, 59, 80, 81, 56, 55, 40]
|
||||
},
|
||||
{
|
||||
label: "My Second dataset",
|
||||
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: [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.
|
||||
|
||||
```javascript
|
||||
{
|
||||
//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 - 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,
|
||||
{% 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].lineColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
{% endraw %}
|
||||
}
|
||||
```
|
||||
|
||||
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).Bar(data, {
|
||||
barShowStroke: false
|
||||
});
|
||||
// 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 `barShowStroke` set to false.
|
||||
```
|
||||
|
||||
We can also change these defaults values for each Bar type that is created, this object is available at `Chart.defaults.Bar`.
|
||||
|
||||
### Prototype methods
|
||||
|
||||
#### .getBarsAtEvent( event )
|
||||
|
||||
Calling `getBarsAtEvent(event)` on your Chart instance passing an argument of an event, or jQuery event, will return the bar elements that are at that the same position of that event.
|
||||
|
||||
```javascript
|
||||
canvas.onclick = function(evt){
|
||||
var activeBars = myBarChart.getBarsAtEvent(evt);
|
||||
// => activeBars is an array of bars 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.
|
||||
|
||||
#### .update( )
|
||||
|
||||
Calling `update()` on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those in one animated render loop.
|
||||
|
||||
```javascript
|
||||
myBarChart.datasets[0].bars[2].value = 50;
|
||||
// Would update the first dataset's value of 'March' to be 50
|
||||
myBarChart.update();
|
||||
// Calling update now animates the position of March from 90 to 50.
|
||||
```
|
||||
|
||||
#### .addData( valuesArray, label )
|
||||
|
||||
Calling `addData(valuesArray, label)` on your Chart instance passing an array of values for each dataset, along with a label for those bars.
|
||||
|
||||
```javascript
|
||||
// The values array passed into addData should be one for each dataset in the chart
|
||||
myBarChart.addData([40, 60], "August");
|
||||
// The new data will now animate at the end of the chart.
|
||||
```
|
||||
|
||||
#### .removeData( )
|
||||
|
||||
Calling `removeData()` on your Chart instance will remove the first value for all datasets on the chart.
|
||||
|
||||
```javascript
|
||||
myBarChart.removeData();
|
||||
// The chart will now animate and remove the first bar
|
||||
```
|
||||
177
docs/03-Radar-Chart.md
Normal file
177
docs/03-Radar-Chart.md
Normal file
@ -0,0 +1,177 @@
|
||||
---
|
||||
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).Radar(data, options);
|
||||
```
|
||||
|
||||
###Data structure
|
||||
```javascript
|
||||
var data = {
|
||||
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]
|
||||
}
|
||||
]
|
||||
};
|
||||
```
|
||||
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.
|
||||
|
||||
|
||||
```javascript
|
||||
{
|
||||
//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,
|
||||
{% 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].lineColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
|
||||
{% endraw %}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
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).Radar(data, {
|
||||
pointDot: false
|
||||
});
|
||||
// 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 `pointDot` set to false.
|
||||
```
|
||||
|
||||
We can also change these defaults values for each Radar type that is created, this object is available at `Chart.defaults.Radar`.
|
||||
|
||||
|
||||
### Prototype methods
|
||||
|
||||
#### .getPointsAtEvent( event )
|
||||
|
||||
Calling `getPointsAtEvent(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 = myRadarChart.getPointsAtEvent(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.
|
||||
|
||||
#### .update( )
|
||||
|
||||
Calling `update()` on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those in one animated render loop.
|
||||
|
||||
```javascript
|
||||
myRadarChart.datasets[0].points[2].value = 50;
|
||||
// Would update the first dataset's value of 'Sleeping' to be 50
|
||||
myRadarChart.update();
|
||||
// Calling update now animates the position of Sleeping from 90 to 50.
|
||||
```
|
||||
|
||||
#### .addData( valuesArray, label )
|
||||
|
||||
Calling `addData(valuesArray, label)` on your Chart instance passing an array of values for each dataset, along with a label for those points.
|
||||
|
||||
```javascript
|
||||
// The values array passed into addData should be one for each dataset in the chart
|
||||
myRadarChart.addData([40, 60], "Dancing");
|
||||
// The new data will now animate at the end of the chart.
|
||||
```
|
||||
|
||||
#### .removeData( )
|
||||
|
||||
Calling `removeData()` on your Chart instance will remove the first value for all datasets on the chart.
|
||||
|
||||
```javascript
|
||||
myRadarChart.removeData();
|
||||
// Other points will now animate to their correct positions.
|
||||
```
|
||||
172
docs/04-Polar-Area-Chart.md
Normal file
172
docs/04-Polar-Area-Chart.md
Normal file
@ -0,0 +1,172 @@
|
||||
---
|
||||
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).PolarArea(data, options);
|
||||
```
|
||||
|
||||
### Data structure
|
||||
|
||||
```javascript
|
||||
var data = [
|
||||
{
|
||||
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"
|
||||
}
|
||||
|
||||
];
|
||||
```
|
||||
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.
|
||||
|
||||
```javascript
|
||||
{
|
||||
//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,
|
||||
{% 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>"
|
||||
{% endraw %}
|
||||
}
|
||||
```
|
||||
|
||||
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).PolarArea(data, {
|
||||
segmentStrokeColor: "#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 `segmentStrokeColor` 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`.
|
||||
|
||||
### Prototype methods
|
||||
|
||||
#### .getSegmentsAtEvent( event )
|
||||
|
||||
Calling `getSegmentsAtEvent(event)` on your Chart instance passing an argument of an event, or jQuery event, will return the segment elements that are at that the same position of that event.
|
||||
|
||||
```javascript
|
||||
canvas.onclick = function(evt){
|
||||
var activePoints = myPolarAreaChart.getSegmentsAtEvent(evt);
|
||||
// => activePoints is an array of segments 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.
|
||||
|
||||
#### .update( )
|
||||
|
||||
Calling `update()` on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those in one animated render loop.
|
||||
|
||||
```javascript
|
||||
myPolarAreaChart.segments[1].value = 10;
|
||||
// Would update the first dataset's value of 'Green' to be 10
|
||||
myPolarAreaChart.update();
|
||||
// Calling update now animates the position of Green from 50 to 10.
|
||||
```
|
||||
|
||||
#### .addData( segmentData, index )
|
||||
|
||||
Calling `addData(segmentData, index)` on your Chart instance passing an object in the same format as in the constructor. There is an option second argument of 'index', this determines at what index the new segment should be inserted into the chart.
|
||||
|
||||
```javascript
|
||||
// An object in the same format as the original data source
|
||||
myPolarAreaChart.addData({
|
||||
value: 130,
|
||||
color: "#B48EAD",
|
||||
highlight: "#C69CBE",
|
||||
label: "Purple"
|
||||
});
|
||||
// The new segment will now animate in.
|
||||
```
|
||||
|
||||
#### .removeData( index )
|
||||
|
||||
Calling `removeData(index)` on your Chart instance will remove segment at that particular index. If none is provided, it will default to the last segment.
|
||||
|
||||
```javascript
|
||||
myPolarAreaChart.removeData();
|
||||
// Other segments will update to fill the empty space left.
|
||||
```
|
||||
158
docs/05-Pie-Doughnut-Chart.md
Normal file
158
docs/05-Pie-Doughnut-Chart.md
Normal file
@ -0,0 +1,158 @@
|
||||
---
|
||||
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 a the proportional value of each piece of data.
|
||||
|
||||
They are excellent at showing the relational proportions between data.
|
||||
|
||||
Pie and doughnut charts in 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]).Pie(data,options);
|
||||
|
||||
// And for a doughnut chart
|
||||
var myDoughnutChart = new Chart(ctx[1]).Doughnut(data,options);
|
||||
```
|
||||
|
||||
### Data structure
|
||||
|
||||
```javascript
|
||||
var data = [
|
||||
{
|
||||
value: 300,
|
||||
color:"#F7464A",
|
||||
highlight: "#FF5A5E",
|
||||
label: "Red"
|
||||
},
|
||||
{
|
||||
value: 50,
|
||||
color: "#46BFBD",
|
||||
highlight: "#5AD3D1",
|
||||
label: "Green"
|
||||
},
|
||||
{
|
||||
value: 100,
|
||||
color: "#FDB45C",
|
||||
highlight: "#FFC870",
|
||||
label: "Yellow"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
### 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.
|
||||
|
||||
```javascript
|
||||
{
|
||||
//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,
|
||||
|
||||
//Number - The percentage of the chart that we cut out of the middle
|
||||
percentageInnerCutout : 50, // This is 0 for Pie charts
|
||||
|
||||
//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,
|
||||
{% 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>"
|
||||
{% endraw %}
|
||||
}
|
||||
```
|
||||
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).Doughnut(data, {
|
||||
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 defaults 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.
|
||||
|
||||
### Prototype methods
|
||||
|
||||
#### .getSegmentsAtEvent( event )
|
||||
|
||||
Calling `getSegmentsAtEvent(event)` on your Chart instance passing an argument of an event, or jQuery event, will return the segment elements that are at that the same position of that event.
|
||||
|
||||
```javascript
|
||||
canvas.onclick = function(evt){
|
||||
var activePoints = myDoughnutChart.getSegmentsAtEvent(evt);
|
||||
// => activePoints is an array of segments 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.
|
||||
|
||||
#### .update( )
|
||||
|
||||
Calling `update()` on your Chart instance will re-render the chart with any updated values, allowing you to edit the value of multiple existing points, then render those in one animated render loop.
|
||||
|
||||
```javascript
|
||||
myDoughnutChart.segments[1].value = 10;
|
||||
// Would update the first dataset's value of 'Green' to be 10
|
||||
myDoughnutChart.update();
|
||||
// Calling update now animates the circumference of the segment 'Green' from 50 to 10.
|
||||
// and transitions other segment widths
|
||||
```
|
||||
|
||||
#### .addData( segmentData, index )
|
||||
|
||||
Calling `addData(segmentData, index)` on your Chart instance passing an object in the same format as in the constructor. There is an option second argument of 'index', this determines at what index the new segment should be inserted into the chart.
|
||||
|
||||
```javascript
|
||||
// An object in the same format as the original data source
|
||||
myDoughnutChart.addData({
|
||||
value: 130,
|
||||
color: "#B48EAD",
|
||||
highlight: "#C69CBE",
|
||||
label: "Purple"
|
||||
});
|
||||
// The new segment will now animate in.
|
||||
```
|
||||
|
||||
#### .removeData( index )
|
||||
|
||||
Calling `removeData(index)` on your Chart instance will remove segment at that particular index. If none is provided, it will default to the last segment.
|
||||
|
||||
```javascript
|
||||
myDoughnutChart.removeData();
|
||||
// Other segments will update to fill the empty space left.
|
||||
```
|
||||
144
docs/06-Advanced.md
Normal file
144
docs/06-Advanced.md
Normal file
@ -0,0 +1,144 @@
|
||||
---
|
||||
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).Line(data);
|
||||
```
|
||||
|
||||
#### .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
|
||||
```
|
||||
|
||||
#### .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 browser 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
|
||||
```
|
||||
|
||||
#### .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.
|
||||
|
||||
```javascript
|
||||
// Destroys a specific chart instance
|
||||
myLineChart.destroy();
|
||||
```
|
||||
|
||||
#### .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 template for this legend is at `legendTemplate` in the chart options.
|
||||
|
||||
```javascript
|
||||
myLineChart.generateLegend();
|
||||
// => returns HTML string of a legend for this chart
|
||||
```
|
||||
|
||||
### Writing new chart types
|
||||
|
||||
Chart.js 1.0 has been rewritten to provide a platform for developers to create their own custom chart types, and be able to share and utilise them through the Chart.js API.
|
||||
|
||||
The format is relatively simple, there are a set of utility helper methods under `Chart.helpers`, including things such as looping over collections, requesting animation frames, and easing equations.
|
||||
|
||||
On top of this, there are also some simple base classes of Chart elements, these all extend from `Chart.Element`, and include things such as points, bars and scales.
|
||||
|
||||
```javascript
|
||||
Chart.Type.extend({
|
||||
// Passing in a name registers this chart in the Chart namespace
|
||||
name: "Scatter",
|
||||
// Providing a defaults will also register the deafults in the chart namespace
|
||||
defaults : {
|
||||
options: "Here",
|
||||
available: "at this.options"
|
||||
},
|
||||
// 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.chart.ctx // The drawing context for this chart
|
||||
this.chart.canvas // the canvas node for this chart
|
||||
}
|
||||
});
|
||||
|
||||
// Now we can create a new instance of our chart, using the Chart.js API
|
||||
new Chart(ctx).Scatter(data);
|
||||
// initialize is now run
|
||||
```
|
||||
|
||||
### Extending existing chart types
|
||||
|
||||
We can also extend existing chart types, and expose them to the API in the same way. Let's say for example, we might want to run some more code when we initialize every Line chart.
|
||||
|
||||
```javascript
|
||||
// Notice now we're extending the particular Line chart type, rather than the base class.
|
||||
Chart.types.Line.extend({
|
||||
// Passing in a name registers this chart in the Chart namespace in the same way
|
||||
name: "LineAlt",
|
||||
initialize: function(data){
|
||||
console.log('My Line chart extension');
|
||||
Chart.types.Line.prototype.apply(this, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
// Creates a line chart in the same way
|
||||
new Chart(ctx).LineAlt(data);
|
||||
// but this logs 'My Line chart extension' in the console.
|
||||
```
|
||||
|
||||
### Creating custom builds
|
||||
|
||||
Chart.js uses <a href="http://gulpjs.com/" target="_blank">gulp</a> to build the library into a single javascript file. We can use this same build script with custom parameters in order to build a custom version.
|
||||
|
||||
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, 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.
|
||||
|
||||
Here we will create a version of Chart.js with only Line, Radar and Bar charts included:
|
||||
|
||||
```bash
|
||||
gulp build --types=Line,Radar,Bar
|
||||
```
|
||||
|
||||
This will output to the `/custom` directory, and write two files, Chart.js, and Chart.min.js with only those chart types included.
|
||||
42
docs/07-Notes.md
Normal file
42
docs/07-Notes.md
Normal file
@ -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>.
|
||||
1443
docs/Chart.js
vendored
1443
docs/Chart.js
vendored
File diff suppressed because it is too large
Load Diff
766
docs/index.html
766
docs/index.html
@ -1,766 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Chart.js Documentation</title>
|
||||
<link href="styles.css" rel="stylesheet">
|
||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
|
||||
<script src="prettify.js"></script>
|
||||
<script src="Chart.js"></script>
|
||||
<script type="text/javascript" src="//use.typekit.net/puc1imu.js"></script>
|
||||
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="redBorder"></div>
|
||||
<div class="greenBorder"></div>
|
||||
<div class="yellowBorder"></div>
|
||||
<div id="wrapper">
|
||||
<nav>
|
||||
<dl>
|
||||
</dl>
|
||||
</nav>
|
||||
|
||||
<div id="contentWrapper">
|
||||
<h1 id="mainHeader">Chart.js Documentation</h1>
|
||||
<h2 id="introText">Everything you need to know to create great looking charts using Chart.js</h2>
|
||||
<article id="gettingStarted">
|
||||
<h1>Getting started</h1>
|
||||
<h2>Include Chart.js</h2>
|
||||
<p>First we need to include the Chart.js library on the page. The library occupies a global variable of <code>Chart</code>.</p>
|
||||
<pre data-type="html"><code><script src="Chart.js"></script></code></pre>
|
||||
<h2>Creating a chart</h2>
|
||||
<p>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.</p>
|
||||
<pre data-type="html"><code><canvas id="myChart" width="400" height="400"></canvas></code></pre>
|
||||
<pre data-type="javascript"><code>//Get the context of the canvas element we want to select
|
||||
var ctx = document.getElementById("myChart").getContext("2d");
|
||||
var myNewChart = new Chart(ctx).PolarArea(data);</code></pre>
|
||||
<p>We can also get the context of our canvas with jQuery. To do this, we need to get the DOM node out of the jQuery collection, and call the <code>getContext("2d")</code> method on that.</p>
|
||||
<pre data-type="javascript"><code>//Get context with jQuery - using jQuery's .get() method.
|
||||
var ctx = $("#myChart").get(0).getContext("2d");
|
||||
//This will get the first returned node in the jQuery collection.
|
||||
var myNewChart = new Chart(ctx);</code></pre>
|
||||
<p>After we've instantiated the Chart class on the canvas we want to draw on, Chart.js will handle the scaling for retina displays.</p>
|
||||
<p>With the Chart class set up, we can go on to create one of the charts Chart.js has available. In the example below, we would be drawing a Polar area chart.</p>
|
||||
<pre data-type="javascript"><code>new Chart(ctx).PolarArea(data,options);</code></pre>
|
||||
<p>We call a method of the name of the chart we want to create. We pass in the data for that chart type, and the options for that chart as parameters. Chart.js will merge the options you pass in with the default options for that chart type.</p>
|
||||
</article>
|
||||
|
||||
<article id="lineChart">
|
||||
<h1>Line chart</h1>
|
||||
<h2>Introduction</h2>
|
||||
<p>A line chart is a way of plotting data points on a line.</p>
|
||||
<p>Often, it is used to show trend data, and the comparison of two data sets.</p>
|
||||
<h2>Example usage</h2>
|
||||
<canvas id="line" data-type="Line" width="600" height="400"></canvas>
|
||||
<pre data-type="javascript"><code>new Chart(ctx).Line(data,options);</code></pre>
|
||||
<h2>Data structure</h2>
|
||||
<pre data-type="javascript"><code data-for="line">var data = {
|
||||
labels : ["January","February","March","April","May","June","July"],
|
||||
datasets : [
|
||||
{
|
||||
fillColor : "rgba(220,220,220,0.5)",
|
||||
strokeColor : "rgba(220,220,220,1)",
|
||||
pointColor : "rgba(220,220,220,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [65,59,90,81,56,55,40]
|
||||
},
|
||||
{
|
||||
fillColor : "rgba(151,187,205,0.5)",
|
||||
strokeColor : "rgba(151,187,205,1)",
|
||||
pointColor : "rgba(151,187,205,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [28,48,40,19,96,27,100]
|
||||
}
|
||||
]
|
||||
}</code></pre>
|
||||
<p>The line chart requires an array of labels for each of the data points. This is show on the X axis.</p>
|
||||
<p>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.</p>
|
||||
|
||||
<h2>Chart options</h2>
|
||||
<pre data-type="javascript"><code>Line.defaults = {
|
||||
|
||||
//Boolean - If we show the scale above the chart data
|
||||
scaleOverlay : false,
|
||||
|
||||
//Boolean - If we want to override with a hard coded scale
|
||||
scaleOverride : false,
|
||||
|
||||
//** Required if scaleOverride is true **
|
||||
//Number - The number of steps in a hard coded scale
|
||||
scaleSteps : null,
|
||||
//Number - The value jump in the hard coded scale
|
||||
scaleStepWidth : null,
|
||||
//Number - The scale starting value
|
||||
scaleStartValue : null,
|
||||
|
||||
//String - Colour of the scale line
|
||||
scaleLineColor : "rgba(0,0,0,.1)",
|
||||
|
||||
//Number - Pixel width of the scale line
|
||||
scaleLineWidth : 1,
|
||||
|
||||
//Boolean - Whether to show labels on the scale
|
||||
scaleShowLabels : true,
|
||||
|
||||
//Interpolated JS string - can access value
|
||||
scaleLabel : "<%=value%>",
|
||||
|
||||
//String - Scale label font declaration for the scale label
|
||||
scaleFontFamily : "'Arial'",
|
||||
|
||||
//Number - Scale label font size in pixels
|
||||
scaleFontSize : 12,
|
||||
|
||||
//String - Scale label font weight style
|
||||
scaleFontStyle : "normal",
|
||||
|
||||
//String - Scale label font colour
|
||||
scaleFontColor : "#666",
|
||||
|
||||
///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 the line is curved between points
|
||||
bezierCurve : true,
|
||||
|
||||
//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,
|
||||
|
||||
//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,
|
||||
|
||||
//Boolean - Whether to animate the chart
|
||||
animation : true,
|
||||
|
||||
//Number - Number of animation steps
|
||||
animationSteps : 60,
|
||||
|
||||
//String - Animation easing effect
|
||||
animationEasing : "easeOutQuart",
|
||||
|
||||
//Function - Fires when the animation is complete
|
||||
onAnimationComplete : null
|
||||
|
||||
}</code></pre>
|
||||
</article>
|
||||
|
||||
<article id="barChart">
|
||||
<h1>Bar chart</h1>
|
||||
<h2>Introduction</h2>
|
||||
<p>A bar chart is a way of showing data as bars.</p>
|
||||
<p>It is sometimes used to show trend data, and the comparison of multiple data sets side by side.</p>
|
||||
<h2>Example usage</h2>
|
||||
<canvas id="bar" data-type="Bar" width="600" height="400"></canvas>
|
||||
<pre data-type="javascript"><code>new Chart(ctx).Bar(data,options);</code></pre>
|
||||
<h2>Data structure</h2>
|
||||
<pre data-type="javascript"><code data-for="bar">var data = {
|
||||
labels : ["January","February","March","April","May","June","July"],
|
||||
datasets : [
|
||||
{
|
||||
fillColor : "rgba(220,220,220,0.5)",
|
||||
strokeColor : "rgba(220,220,220,1)",
|
||||
data : [65,59,90,81,56,55,40]
|
||||
},
|
||||
{
|
||||
fillColor : "rgba(151,187,205,0.5)",
|
||||
strokeColor : "rgba(151,187,205,1)",
|
||||
data : [28,48,40,19,96,27,100]
|
||||
}
|
||||
]
|
||||
}</code></pre>
|
||||
<p>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.</p>
|
||||
<p>We have an array of labels too for display. In the example, we are showing the same data as the previous line chart example.</p>
|
||||
|
||||
<h2>Chart options</h2>
|
||||
<pre data-type="javascript"><code>Bar.defaults = {
|
||||
|
||||
//Boolean - If we show the scale above the chart data
|
||||
scaleOverlay : false,
|
||||
|
||||
//Boolean - If we want to override with a hard coded scale
|
||||
scaleOverride : false,
|
||||
|
||||
//** Required if scaleOverride is true **
|
||||
//Number - The number of steps in a hard coded scale
|
||||
scaleSteps : null,
|
||||
//Number - The value jump in the hard coded scale
|
||||
scaleStepWidth : null,
|
||||
//Number - The scale starting value
|
||||
scaleStartValue : null,
|
||||
|
||||
//String - Colour of the scale line
|
||||
scaleLineColor : "rgba(0,0,0,.1)",
|
||||
|
||||
//Number - Pixel width of the scale line
|
||||
scaleLineWidth : 1,
|
||||
|
||||
//Boolean - Whether to show labels on the scale
|
||||
scaleShowLabels : true,
|
||||
|
||||
//Interpolated JS string - can access value
|
||||
scaleLabel : "<%=value%>",
|
||||
|
||||
//String - Scale label font declaration for the scale label
|
||||
scaleFontFamily : "'Arial'",
|
||||
|
||||
//Number - Scale label font size in pixels
|
||||
scaleFontSize : 12,
|
||||
|
||||
//String - Scale label font weight style
|
||||
scaleFontStyle : "normal",
|
||||
|
||||
//String - Scale label font colour
|
||||
scaleFontColor : "#666",
|
||||
|
||||
///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 - 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,
|
||||
|
||||
//Boolean - Whether to animate the chart
|
||||
animation : true,
|
||||
|
||||
//Number - Number of animation steps
|
||||
animationSteps : 60,
|
||||
|
||||
//String - Animation easing effect
|
||||
animationEasing : "easeOutQuart",
|
||||
|
||||
//Function - Fires when the animation is complete
|
||||
onAnimationComplete : null
|
||||
|
||||
}</code></pre>
|
||||
</article>
|
||||
|
||||
<article id="radarChart">
|
||||
<h1>Radar chart</h1>
|
||||
<h2>Introduction</h2>
|
||||
<p>A radar chart is a way of showing multiple data points and the variation between them.</p>
|
||||
<p>They are often useful for comparing the points of two or more different data sets</p>
|
||||
<h2>Example usage</h2>
|
||||
<canvas id="radar" data-type="Radar" width="400" height="400"></canvas>
|
||||
<pre data-type="javascript"><code>new Chart(ctx).Radar(data,options);</code></pre>
|
||||
<h2>Data structure</h2>
|
||||
<pre data-type="javascript"><code data-for="radar">var data = {
|
||||
labels : ["Eating","Drinking","Sleeping","Designing","Coding","Partying","Running"],
|
||||
datasets : [
|
||||
{
|
||||
fillColor : "rgba(220,220,220,0.5)",
|
||||
strokeColor : "rgba(220,220,220,1)",
|
||||
pointColor : "rgba(220,220,220,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [65,59,90,81,56,55,40]
|
||||
},
|
||||
{
|
||||
fillColor : "rgba(151,187,205,0.5)",
|
||||
strokeColor : "rgba(151,187,205,1)",
|
||||
pointColor : "rgba(151,187,205,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [28,48,40,19,96,27,100]
|
||||
}
|
||||
]
|
||||
}</code></pre>
|
||||
<p>For a radar chart, usually you will want to show a label on each point of the chart, so we include an array of strings that we show around each point in the chart. If you do not want this, you can either not include the array of labels, or choose to hide them in the chart options.</p>
|
||||
<p>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.</p>
|
||||
|
||||
<h2>Chart options</h2>
|
||||
<pre data-type="javascript"><code>Radar.defaults = {
|
||||
|
||||
//Boolean - If we show the scale above the chart data
|
||||
scaleOverlay : false,
|
||||
|
||||
//Boolean - If we want to override with a hard coded scale
|
||||
scaleOverride : false,
|
||||
|
||||
//** Required if scaleOverride is true **
|
||||
//Number - The number of steps in a hard coded scale
|
||||
scaleSteps : null,
|
||||
//Number - The value jump in the hard coded scale
|
||||
scaleStepWidth : null,
|
||||
//Number - The centre starting value
|
||||
scaleStartValue : null,
|
||||
|
||||
//Boolean - Whether to show lines for each scale point
|
||||
scaleShowLine : true,
|
||||
|
||||
//String - Colour of the scale line
|
||||
scaleLineColor : "rgba(0,0,0,.1)",
|
||||
|
||||
//Number - Pixel width of the scale line
|
||||
scaleLineWidth : 1,
|
||||
|
||||
//Boolean - Whether to show labels on the scale
|
||||
scaleShowLabels : false,
|
||||
|
||||
//Interpolated JS string - can access value
|
||||
scaleLabel : "<%=value%>",
|
||||
|
||||
//String - Scale label font declaration for the scale label
|
||||
scaleFontFamily : "'Arial'",
|
||||
|
||||
//Number - Scale label font size in pixels
|
||||
scaleFontSize : 12,
|
||||
|
||||
//String - Scale label font weight style
|
||||
scaleFontStyle : "normal",
|
||||
|
||||
//String - Scale label font colour
|
||||
scaleFontColor : "#666",
|
||||
|
||||
//Boolean - Show a backdrop to the scale label
|
||||
scaleShowLabelBackdrop : true,
|
||||
|
||||
//String - The colour of the label backdrop
|
||||
scaleBackdropColor : "rgba(255,255,255,0.75)",
|
||||
|
||||
//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 - Whether we show the angle lines out of the radar
|
||||
angleShowLineOut : 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 : 12,
|
||||
|
||||
//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,
|
||||
|
||||
//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,
|
||||
|
||||
//Boolean - Whether to animate the chart
|
||||
animation : true,
|
||||
|
||||
//Number - Number of animation steps
|
||||
animationSteps : 60,
|
||||
|
||||
//String - Animation easing effect
|
||||
animationEasing : "easeOutQuart",
|
||||
|
||||
//Function - Fires when the animation is complete
|
||||
onAnimationComplete : null
|
||||
|
||||
}</code></pre>
|
||||
</article>
|
||||
|
||||
<article id="polarAreaChart">
|
||||
<h1>Polar area chart</h1>
|
||||
<h2>Introduction</h2>
|
||||
<p>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.</p>
|
||||
<p>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.</p>
|
||||
<h2>Example usage</h2>
|
||||
<canvas id="polarArea" data-type="PolarArea" width="300" height="300"></canvas>
|
||||
<pre data-type="javascript"><code>new Chart(ctx).PolarArea(data,options);</code></pre>
|
||||
<h2>Data structure</h2>
|
||||
<pre data-type="javascript"><code data-for="polarArea">var data = [
|
||||
{
|
||||
value : 30,
|
||||
color: "#D97041"
|
||||
},
|
||||
{
|
||||
value : 90,
|
||||
color: "#C7604C"
|
||||
},
|
||||
{
|
||||
value : 24,
|
||||
color: "#21323D"
|
||||
},
|
||||
{
|
||||
value : 58,
|
||||
color: "#9D9B7F"
|
||||
},
|
||||
{
|
||||
value : 82,
|
||||
color: "#7D4F6D"
|
||||
},
|
||||
{
|
||||
value : 8,
|
||||
color: "#584A5E"
|
||||
}
|
||||
]</code></pre>
|
||||
<p>As you can see, for the chart data you pass in an array of objects, with a value and a colour. The <code>value</code> attribute should be a number, while the <code>color</code> attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL.</p>
|
||||
<h2>Chart options</h2>
|
||||
<p>These are the default chart options. By passing in an object with any of these attributes, Chart.js will merge these objects and the graph accordingly. Explanations of each option are commented in the code below.</p>
|
||||
<pre data-type="javascript"><code>PolarArea.defaults = {
|
||||
|
||||
//Boolean - Whether we show the scale above or below the chart segments
|
||||
scaleOverlay : true,
|
||||
|
||||
//Boolean - If we want to override with a hard coded scale
|
||||
scaleOverride : false,
|
||||
|
||||
//** Required if scaleOverride is true **
|
||||
//Number - The number of steps in a hard coded scale
|
||||
scaleSteps : null,
|
||||
//Number - The value jump in the hard coded scale
|
||||
scaleStepWidth : null,
|
||||
//Number - The centre starting value
|
||||
scaleStartValue : null,
|
||||
|
||||
//Boolean - Show line for each value in the scale
|
||||
scaleShowLine : true,
|
||||
|
||||
//String - The colour of the scale line
|
||||
scaleLineColor : "rgba(0,0,0,.1)",
|
||||
|
||||
//Number - The width of the line - in pixels
|
||||
scaleLineWidth : 1,
|
||||
|
||||
//Boolean - whether we should show text labels
|
||||
scaleShowLabels : true,
|
||||
|
||||
//Interpolated JS string - can access value
|
||||
scaleLabel : "<%=value%>",
|
||||
|
||||
//String - Scale label font declaration for the scale label
|
||||
scaleFontFamily : "'Arial'",
|
||||
|
||||
//Number - Scale label font size in pixels
|
||||
scaleFontSize : 12,
|
||||
|
||||
//String - Scale label font weight style
|
||||
scaleFontStyle : "normal",
|
||||
|
||||
//String - Scale label font colour
|
||||
scaleFontColor : "#666",
|
||||
|
||||
//Boolean - Show a backdrop to the scale label
|
||||
scaleShowLabelBackdrop : true,
|
||||
|
||||
//String - The colour of the label backdrop
|
||||
scaleBackdropColor : "rgba(255,255,255,0.75)",
|
||||
|
||||
//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 - 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,
|
||||
|
||||
//Boolean - Whether to animate the chart or not
|
||||
animation : true,
|
||||
|
||||
//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,
|
||||
|
||||
//Function - This will fire when the animation of the chart is complete.
|
||||
onAnimationComplete : null
|
||||
}</code></pre>
|
||||
</article>
|
||||
<article id="pieChart">
|
||||
<h1>Pie chart</h1>
|
||||
<h2>Introduction</h2>
|
||||
<p>Pie charts are probably the most commonly used chart there are. They are divided into segments, the arc of each segment shows a the proportional value of each piece of data.</p>
|
||||
<p>They are excellent at showing the relational proportions between data.</p>
|
||||
<h2>Example usage</h2>
|
||||
<canvas id="pie" data-type="Pie" width="400" height="400"></canvas>
|
||||
<pre data-type="javascript"><code>new Chart(ctx).Pie(data,options);</code></pre>
|
||||
<h2>Data structure</h2>
|
||||
<pre data-type="javascript"><code data-for="pie">var data = [
|
||||
{
|
||||
value: 30,
|
||||
color:"#F38630"
|
||||
},
|
||||
{
|
||||
value : 50,
|
||||
color : "#E0E4CC"
|
||||
},
|
||||
{
|
||||
value : 100,
|
||||
color : "#69D2E7"
|
||||
}
|
||||
]</code></pre>
|
||||
<p>For a pie chart, you must pass in an array of objects with a <code>value</code> and a <code>color</code> property. The <code>value</code> attribute should be a number, Chart.js will total all of the numbers and calculate the relative proportion of each. The <code>color</code> attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL.</p>
|
||||
<h2>Chart options</h2>
|
||||
<p>These are the default options for the Pie chart. Pass in an object with any of these attributes to override them.
|
||||
<pre data-type="javascript"><code>Pie.defaults = {
|
||||
//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,
|
||||
|
||||
//Boolean - Whether we should animate the chart
|
||||
animation : true,
|
||||
|
||||
//Number - Amount of animation steps
|
||||
animationSteps : 100,
|
||||
|
||||
//String - Animation easing effect
|
||||
animationEasing : "easeOutBounce",
|
||||
|
||||
//Boolean - Whether we animate the rotation of the Pie
|
||||
animateRotate : true,
|
||||
|
||||
//Boolean - Whether we animate scaling the Pie from the centre
|
||||
animateScale : false,
|
||||
|
||||
//Function - Will fire on animation completion.
|
||||
onAnimationComplete : null
|
||||
}</code></pre>
|
||||
</article>
|
||||
<article id="doughnutChart">
|
||||
<h1>Doughnut chart</h1>
|
||||
<h2>Introduction</h2>
|
||||
<p>Doughnut charts are similar to pie charts, however they have the centre cut out, and are therefore shaped more like a doughnut than a pie!</p>
|
||||
<p>They are aso excellent at showing the relational proportions between data.</p>
|
||||
<h2>Example usage</h2>
|
||||
<canvas id="doughnut" data-type="Doughnut" width="400" height="400"></canvas>
|
||||
<pre data-type="javascript"><code>new Chart(ctx).Doughnut(data,options);</code></pre>
|
||||
<h2>Data structure</h2>
|
||||
<pre data-type="javascript"><code data-for="doughnut">var data = [
|
||||
{
|
||||
value: 30,
|
||||
color:"#F7464A"
|
||||
},
|
||||
{
|
||||
value : 50,
|
||||
color : "#E2EAE9"
|
||||
},
|
||||
{
|
||||
value : 100,
|
||||
color : "#D4CCC5"
|
||||
},
|
||||
{
|
||||
value : 40,
|
||||
color : "#949FB1"
|
||||
},
|
||||
{
|
||||
value : 120,
|
||||
color : "#4D5360"
|
||||
}
|
||||
|
||||
]</code></pre>
|
||||
<p>For a doughnut chart, you must pass in an array of objects with a <code>value</code> and a <code>color</code> property. The <code>value</code> attribute should be a number, Chart.js will total all of the numbers and calculate the relative proportion of each. The <code>color</code> attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL.</p>
|
||||
<h2>Chart options</h2>
|
||||
<p>These are the default options for the doughnut chart. Pass in an object with any of these attributes to override them.
|
||||
<pre data-type="javascript"><code>Doughnut.defaults = {
|
||||
//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,
|
||||
|
||||
//Boolean - Whether we should animate the chart
|
||||
animation : true,
|
||||
|
||||
//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,
|
||||
|
||||
//Function - Will fire on animation completion.
|
||||
onAnimationComplete : null
|
||||
}</code></pre>
|
||||
</article>
|
||||
<article id="generalIssues">
|
||||
<h1>General issues</h1>
|
||||
<h2>Chart interactivity</h2>
|
||||
<p>If you are looking to add interaction as a layer to charts, Chart.js is <strong>not the library for you</strong>. A better option would be using SVG, as this will let you attach event listeners to any of the elements in the chart, as these are all DOM nodes.</p>
|
||||
<p>Chart.js uses the canvas element, which is a single DOM node, similar in characteristics to a static image. This does mean that it has a wider scope for compatibility, and less memory implications than SVG based charting solutions. The canvas element also allows for saving the contents as a base 64 string, allowing saving the chart as an image. </p>
|
||||
<p>In SVG, all of the lines, data points and everything you see is a DOM node. As a result of this, complex charts with a lot of intricacies, or many charts on the page will often see dips in performance when scrolling or generating the chart, especially when there are multiple on the page. SVG also has relatively poor mobile support, with Android not supporting SVG at all before version 3.0, and iOS before 5.0. (<a href="http://caniuse.com/svg-html5" target="_blank">caniuse.com/svg-html5</a>).</p>
|
||||
<h2>Browser support</h2>
|
||||
<p>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>).</p>
|
||||
<p>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:</p>
|
||||
<pre data-type="html"><code><head>
|
||||
<!--[if lte IE 8]>
|
||||
<script src="excanvas.js"></script>
|
||||
<![endif]-->
|
||||
</head></code></pre>
|
||||
<p>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.</p>
|
||||
<p>Some important points to note in my experience using ExplorerCanvas as a fallback.</p>
|
||||
<ul>
|
||||
<li>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.</li>
|
||||
<li>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/" targer="_blank">Modernizr</a> to do this.</li>
|
||||
<li>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.</li>
|
||||
|
||||
</ul>
|
||||
<h2>Bugs & issues</h2>
|
||||
<p>Please report these on the Github page - at <a href="https://github.com/nnnick/Chart.js" target="_blank">github.com/nnnick/Chart.js</a>.</p>
|
||||
<p>New contributions to the library are welcome.</p>
|
||||
<h2>License</h2>
|
||||
<p>Chart.js is open source and available under the <a href="http://opensource.org/licenses/MIT" target="_blank">MIT license</a>.</p>
|
||||
</article>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
|
||||
var $nav = $("nav dl");
|
||||
|
||||
$("article").each(function(){
|
||||
var $el = $(this);
|
||||
var $h1 = $el.find("h1");
|
||||
var sectionTitle = $h1.html();
|
||||
var articleId = $el.attr("id");
|
||||
var $dt = $("<dt><a href=\"#"+articleId +"\">"+sectionTitle+"</a></dt>");
|
||||
|
||||
$dt.find("a").on("click",function(e){
|
||||
e.preventDefault();
|
||||
$('html,body').animate({scrollTop: $h1.offset().top},400);
|
||||
});
|
||||
|
||||
$nav.append($dt);
|
||||
|
||||
var $subtitles = $el.find("h2");
|
||||
|
||||
$subtitles.each(function(){
|
||||
var $h2 = $(this);
|
||||
var title = $h2.text();
|
||||
var newID = articleId + "-" +camelCase(title);
|
||||
$h2.attr("id",newID);
|
||||
var $dd = $("<dd><a href=\"#" +newID + "\">" + title + "</a></dd>");
|
||||
|
||||
$dd.find("a").on("click",function(e){
|
||||
e.preventDefault();
|
||||
$('html,body').animate({scrollTop: $h2.offset().top},400);
|
||||
})
|
||||
$nav.append($dd);
|
||||
|
||||
});
|
||||
|
||||
var $articles = $el.find("article");
|
||||
|
||||
});
|
||||
|
||||
$("canvas").each(function(){
|
||||
var $canvas = $(this);
|
||||
var ctx = this.getContext("2d");
|
||||
|
||||
|
||||
|
||||
eval($("code[data-for='" + $canvas.attr("id") + "']").text());
|
||||
|
||||
|
||||
var evalString = "new Chart(ctx)." + $canvas.data("type") + "(data);";
|
||||
|
||||
eval(evalString);
|
||||
|
||||
});
|
||||
prettyPrint();
|
||||
|
||||
function camelCase(str){
|
||||
var splitString = str.split(" ");
|
||||
|
||||
var returnedCamel = splitString[0].toLowerCase();
|
||||
|
||||
for (var i=1; i<splitString.length; i++){
|
||||
returnedCamel += splitString[i].charAt(0).toUpperCase() + splitString[i].substring(1).toLowerCase();
|
||||
}
|
||||
|
||||
return returnedCamel;
|
||||
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', 'UA-28909194-3']);
|
||||
_gaq.push(['_trackPageview']);
|
||||
|
||||
(function() {
|
||||
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
|
||||
</script>
|
||||
</html>
|
||||
@ -1,38 +0,0 @@
|
||||
/* Pretty printing styles. Used with prettify.js. */
|
||||
/* Vim sunburst theme by David Leibovic */
|
||||
|
||||
pre .str, code .str { color: #65B042; } /* string - green */
|
||||
pre .kwd, code .kwd { color: #E28964; } /* keyword - dark pink */
|
||||
pre .com, code .com { color: #AEAEAE; font-style: italic; } /* comment - gray */
|
||||
pre .typ, code .typ { color: #89bdff; } /* type - light blue */
|
||||
pre .lit, code .lit { color: #3387CC; } /* literal - blue */
|
||||
pre .pun, code .pun { color: #fff; } /* punctuation - white */
|
||||
pre .pln, code .pln { color: #fff; } /* plaintext - white */
|
||||
pre .tag, code .tag { color: #89bdff; } /* html/xml tag - light blue */
|
||||
pre .atn, code .atn { color: #bdb76b; } /* html/xml attribute name - khaki */
|
||||
pre .atv, code .atv { color: #65B042; } /* html/xml attribute value - green */
|
||||
pre .dec, code .dec { color: #3387CC; } /* decimal - blue */
|
||||
|
||||
pre.prettyprint, code.prettyprint {
|
||||
background-color: #000;
|
||||
-moz-border-radius: 8px;
|
||||
-webkit-border-radius: 8px;
|
||||
-o-border-radius: 8px;
|
||||
-ms-border-radius: 8px;
|
||||
-khtml-border-radius: 8px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
pre.prettyprint {
|
||||
width: 95%;
|
||||
margin: 1em auto;
|
||||
padding: 1em;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
|
||||
/* Specify class=linenums on a pre to get line numbering */
|
||||
ol.linenums { margin-top: 0; margin-bottom: 0; color: #AEAEAE; } /* IE indents via margin-left */
|
||||
li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8 { list-style-type: none }
|
||||
/* Alternate shading for lines */
|
||||
li.L1,li.L3,li.L5,li.L7,li.L9 { }
|
||||
@ -1,28 +0,0 @@
|
||||
var q=null;window.PR_SHOULD_USE_CONTINUATION=!0;
|
||||
(function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a=
|
||||
[],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c<i;++c){var j=f[c];if(/\\[bdsw]/i.test(j))a.push(j);else{var j=m(j),d;c+2<i&&"-"===f[c+1]?(d=m(f[c+2]),c+=2):d=j;b.push([j,d]);d<65||j>122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;c<b.length;++c)i=b[c],i[0]<=j[1]+1?j[1]=Math.max(j[1],i[1]):f.push(j=i);b=["["];o&&b.push("^");b.push.apply(b,a);for(c=0;c<
|
||||
f.length;++c)i=f[c],b.push(e(i[0])),i[1]>i[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c<b;++c){var j=f[c];j==="("?++i:"\\"===j.charAt(0)&&(j=+j.substring(1))&&j<=i&&(d[j]=-1)}for(c=1;c<d.length;++c)-1===d[c]&&(d[c]=++t);for(i=c=0;c<b;++c)j=f[c],j==="("?(++i,d[i]===void 0&&(f[c]="(?:")):"\\"===j.charAt(0)&&
|
||||
(j=+j.substring(1))&&j<=i&&(f[c]="\\"+d[i]);for(i=c=0;c<b;++c)"^"===f[c]&&"^"!==f[c+1]&&(f[c]="");if(a.ignoreCase&&s)for(c=0;c<b;++c)j=f[c],a=j.charAt(0),j.length>=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p<d;++p){var g=a[p];if(g.ignoreCase)l=!0;else if(/[a-z]/i.test(g.source.replace(/\\u[\da-f]{4}|\\x[\da-f]{2}|\\[^UXux]/gi,""))){s=!0;l=!1;break}}for(var r=
|
||||
{b:8,t:9,n:10,v:11,f:12,r:13},n=[],p=0,d=a.length;p<d;++p){g=a[p];if(g.global||g.multiline)throw Error(""+g);n.push("(?:"+y(g)+")")}return RegExp(n.join("|"),l?"gi":"g")}function M(a){function m(a){switch(a.nodeType){case 1:if(e.test(a.className))break;for(var g=a.firstChild;g;g=g.nextSibling)m(g);g=a.nodeName;if("BR"===g||"LI"===g)h[s]="\n",t[s<<1]=y++,t[s++<<1|1]=a;break;case 3:case 4:g=a.nodeValue,g.length&&(g=p?g.replace(/\r\n?/g,"\n"):g.replace(/[\t\n\r ]+/g," "),h[s]=g,t[s<<1]=y,y+=g.length,
|
||||
t[s++<<1|1]=a)}}var e=/(?:^|\s)nocode(?:\s|$)/,h=[],y=0,t=[],s=0,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=document.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);m(a);return{a:h.join("").replace(/\n$/,""),c:t}}function B(a,m,e,h){m&&(a={a:m,d:a},e(a),h.push.apply(h,a.e))}function x(a,m){function e(a){for(var l=a.d,p=[l,"pln"],d=0,g=a.a.match(y)||[],r={},n=0,z=g.length;n<z;++n){var f=g[n],b=r[f],o=void 0,c;if(typeof b===
|
||||
"string")c=!1;else{var i=h[f.charAt(0)];if(i)o=f.match(i[1]),b=i[0];else{for(c=0;c<t;++c)if(i=m[c],o=f.match(i[1])){b=i[0];break}o||(b="pln")}if((c=b.length>=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m),
|
||||
l=[],p={},d=0,g=e.length;d<g;++d){var r=e[d],n=r[3];if(n)for(var k=n.length;--k>=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/,
|
||||
q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/,
|
||||
q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g,
|
||||
"");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a),
|
||||
a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e}
|
||||
for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g<d.length;++g)e(d[g]);m===(m|0)&&d[0].setAttribute("value",
|
||||
m);var r=s.createElement("OL");r.className="linenums";for(var n=Math.max(0,m-1|0)||0,g=0,z=d.length;g<z;++g)l=d[g],l.className="L"+(g+n)%10,l.firstChild||l.appendChild(s.createTextNode("\xa0")),r.appendChild(l);a.appendChild(r)}function k(a,m){for(var e=m.length;--e>=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*</.test(m)?"default-markup":"default-code";return A[a]}function E(a){var m=
|
||||
a.g;try{var e=M(a.h),h=e.a;a.a=h;a.c=e.c;a.d=0;C(m,h)(a);var k=/\bMSIE\b/.test(navigator.userAgent),m=/\n/g,t=a.a,s=t.length,e=0,l=a.c,p=l.length,h=0,d=a.e,g=d.length,a=0;d[g]=s;var r,n;for(n=r=0;n<g;)d[n]!==d[n+2]?(d[r++]=d[n++],d[r++]=d[n++]):n+=2;g=r;for(n=r=0;n<g;){for(var z=d[n],f=d[n+1],b=n+2;b+2<=g&&d[b+1]===f;)b+=2;d[r++]=z;d[r++]=f;n=b}for(d.length=r;h<p;){var o=l[h+2]||s,c=d[a+2]||s,b=Math.min(o,c),i=l[h+1],j;if(i.nodeType!==1&&(j=t.substring(e,b))){k&&(j=j.replace(m,"\r"));i.nodeValue=
|
||||
j;var u=i.ownerDocument,v=u.createElement("SPAN");v.className=d[a+1];var x=i.parentNode;x.replaceChild(v,i);v.appendChild(i);e<o&&(l[h+1]=i=u.createTextNode(t.substring(b,o)),x.insertBefore(i,v.nextSibling))}e=b;e>=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"],
|
||||
"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"],
|
||||
H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"],
|
||||
J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+
|
||||
I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^<?]+/],["dec",/^<!\w[^>]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^<xmp\b[^>]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^<script\b[^>]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^<style\b[^>]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),
|
||||
["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css",
|
||||
/^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}),
|
||||
["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes",
|
||||
hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p<h.length&&l.now()<e;p++){var n=h[p],k=n.className;var k=k.match(g),f,b;if(b=
|
||||
!k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}p<h.length?setTimeout(m,
|
||||
250):a&&a()}for(var e=[document.getElementsByTagName("pre"),document.getElementsByTagName("code"),document.getElementsByTagName("xmp")],h=[],k=0;k<e.length;++k)for(var t=0,s=e[k].length;t<s;++t)h.push(e[k][t]);var e=q,l=Date;l.now||(l={now:function(){return+new Date}});var p=0,d,g=/\blang(?:uage)?-([\w.]+)(?!\S)/;m()};window.PR={createSimpleLexer:x,registerLangHandler:k,sourceDecorator:u,PR_ATTRIB_NAME:"atn",PR_ATTRIB_VALUE:"atv",PR_COMMENT:"com",PR_DECLARATION:"dec",PR_KEYWORD:"kwd",PR_LITERAL:"lit",
|
||||
PR_NOCODE:"nocode",PR_PLAIN:"pln",PR_PUNCTUATION:"pun",PR_SOURCE:"src",PR_STRING:"str",PR_TAG:"tag",PR_TYPE:"typ"}})();
|
||||
@ -1,33 +0,0 @@
|
||||
/* Pretty printing styles. Used with prettify.js. */
|
||||
/* Vim sunburst theme by David Leibovic */
|
||||
|
||||
pre .str{ color: #65B042; } /* string - green */
|
||||
pre .kwd{ color: #E28964; } /* keyword - dark pink */
|
||||
pre .com{ color: #AEAEAE; font-style: italic; } /* comment - gray */
|
||||
pre .typ{ color: #89bdff; } /* type - light blue */
|
||||
pre .lit{ color: #3387CC; } /* literal - blue */
|
||||
pre .pun{ color: #fff; } /* punctuation - white */
|
||||
pre .pln{ color: #fff; } /* plaintext - white */
|
||||
pre .tag{ color: #89bdff; } /* html/xml tag - light blue */
|
||||
pre .atn{ color: #bdb76b; } /* html/xml attribute name - khaki */
|
||||
pre .atv{ color: #65B042; } /* html/xml attribute value - green */
|
||||
pre .dec{ color: #3387CC; } /* decimal - blue */
|
||||
|
||||
/* Specify class=linenums on a pre to get line numbering */
|
||||
ol.linenums { margin-top: 0; margin-bottom: 0; color: #AEAEAE; } /* IE indents via margin-left */
|
||||
li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8 { list-style-type: none }
|
||||
/* Alternate shading for lines */
|
||||
li.L1,li.L3,li.L5,li.L7,li.L9 { }
|
||||
|
||||
@media print {
|
||||
pre .str{ color: #060; }
|
||||
pre .kwd{ color: #006; font-weight: bold; }
|
||||
pre .com{ color: #600; font-style: italic; }
|
||||
pre .typ{ color: #404; font-weight: bold; }
|
||||
pre .lit{ color: #044; }
|
||||
pre .pun{ color: #440; }
|
||||
pre .pln{ color: #000; }
|
||||
pre .tag{ color: #006; font-weight: bold; }
|
||||
pre .atn{ color: #404; }
|
||||
pre .atv{ color: #060; }
|
||||
}
|
||||
263
docs/styles.css
263
docs/styles.css
@ -1,263 +0,0 @@
|
||||
/* Pretty printing styles. Used with prettify.js. */
|
||||
/* Vim sunburst theme by David Leibovic */
|
||||
pre .str {
|
||||
color: #65B042;
|
||||
}
|
||||
/* string - green */
|
||||
pre .kwd {
|
||||
color: #E28964;
|
||||
}
|
||||
/* keyword - dark pink */
|
||||
pre .com {
|
||||
color: #AEAEAE;
|
||||
font-style: italic;
|
||||
}
|
||||
/* comment - gray */
|
||||
pre .typ {
|
||||
color: #89bdff;
|
||||
}
|
||||
/* type - light blue */
|
||||
pre .lit {
|
||||
color: #3387CC;
|
||||
}
|
||||
/* literal - blue */
|
||||
pre .pun {
|
||||
color: #fff;
|
||||
}
|
||||
/* punctuation - white */
|
||||
pre .pln {
|
||||
color: #fff;
|
||||
}
|
||||
/* plaintext - white */
|
||||
pre .tag {
|
||||
color: #89bdff;
|
||||
}
|
||||
/* html/xml tag - light blue */
|
||||
pre .atn {
|
||||
color: #bdb76b;
|
||||
}
|
||||
/* html/xml attribute name - khaki */
|
||||
pre .atv {
|
||||
color: #65B042;
|
||||
}
|
||||
/* html/xml attribute value - green */
|
||||
pre .dec {
|
||||
color: #3387CC;
|
||||
}
|
||||
/* decimal - blue */
|
||||
/* Specify class=linenums on a pre to get line numbering */
|
||||
ol.linenums {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
color: #AEAEAE;
|
||||
}
|
||||
/* IE indents via margin-left */
|
||||
li.L0,
|
||||
li.L1,
|
||||
li.L2,
|
||||
li.L3,
|
||||
li.L5,
|
||||
li.L6,
|
||||
li.L7,
|
||||
li.L8 {
|
||||
list-style-type: none;
|
||||
}
|
||||
/* Alternate shading for lines */
|
||||
@media print {
|
||||
pre .str {
|
||||
color: #060;
|
||||
}
|
||||
pre .kwd {
|
||||
color: #006;
|
||||
font-weight: bold;
|
||||
}
|
||||
pre .com {
|
||||
color: #600;
|
||||
font-style: italic;
|
||||
}
|
||||
pre .typ {
|
||||
color: #404;
|
||||
font-weight: bold;
|
||||
}
|
||||
pre .lit {
|
||||
color: #044;
|
||||
}
|
||||
pre .pun {
|
||||
color: #440;
|
||||
}
|
||||
pre .pln {
|
||||
color: #000;
|
||||
}
|
||||
pre .tag {
|
||||
color: #006;
|
||||
font-weight: bold;
|
||||
}
|
||||
pre .atn {
|
||||
color: #404;
|
||||
}
|
||||
pre .atv {
|
||||
color: #060;
|
||||
}
|
||||
}
|
||||
* {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
-webkit-box-sizing: border-box;
|
||||
color: inherit;
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
body {
|
||||
color: #282b36;
|
||||
min-width: 768px;
|
||||
}
|
||||
.redBorder,
|
||||
.greenBorder,
|
||||
.yellowBorder {
|
||||
border-top: 8px solid #282b36;
|
||||
width: 33.33%;
|
||||
float: left;
|
||||
height: 16px;
|
||||
position: relative;
|
||||
z-index: 50;
|
||||
}
|
||||
.redBorder {
|
||||
background-color: #f33e6f;
|
||||
}
|
||||
.greenBorder {
|
||||
background-color: #46bfbd;
|
||||
}
|
||||
.yellowBorder {
|
||||
background-color: #fdb45c;
|
||||
}
|
||||
h1 {
|
||||
font-family: "proxima-nova";
|
||||
font-weight: 600;
|
||||
font-size: 32px;
|
||||
}
|
||||
h2 {
|
||||
font-family: "proxima-nova";
|
||||
font-weight: 600;
|
||||
font-size: 22px;
|
||||
line-height: 40px;
|
||||
}
|
||||
#mainHeader {
|
||||
font-size: 55px;
|
||||
}
|
||||
#introText {
|
||||
font-weight: 400;
|
||||
margin-top: 20px;
|
||||
font-size: 26px;
|
||||
line-height: 40px;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
#wrapper {
|
||||
margin: 0 auto;
|
||||
position: relative;
|
||||
min-width: 768px;
|
||||
}
|
||||
#wrapper nav {
|
||||
width: 20%;
|
||||
padding-right: 20px;
|
||||
position: fixed;
|
||||
height: 100%;
|
||||
overflow-y: scroll;
|
||||
top: 0;
|
||||
z-index: 0;
|
||||
padding: 40px 20px;
|
||||
font-family: "proxima-nova";
|
||||
background-color: #ebebeb;
|
||||
}
|
||||
#wrapper nav dl {
|
||||
color: #767c8d;
|
||||
}
|
||||
#wrapper nav dl dt {
|
||||
list-style: none;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
#wrapper nav dl dt a {
|
||||
display: block;
|
||||
padding: 2px 0;
|
||||
border-bottom: 1px solid rgba(118, 124, 141, 0.2);
|
||||
text-decoration: none;
|
||||
}
|
||||
#wrapper nav dl dd {
|
||||
margin-bottom: 5px;
|
||||
padding-left: 5px;
|
||||
}
|
||||
#wrapper nav dl dd:before {
|
||||
content: "- ";
|
||||
}
|
||||
#wrapper nav dl dd a {
|
||||
text-decoration: none;
|
||||
font-size: 12px;
|
||||
border-bottom: 1px solid transparent;
|
||||
}
|
||||
#wrapper nav dl a {
|
||||
-webkit-transition: all 200ms ease-in-out;
|
||||
-moz-transition: all 200ms ease-in-out;
|
||||
-o-transition: all 200ms ease-in-out;
|
||||
-ms-transition: all 200ms ease-in-out;
|
||||
transition: all 200ms ease-in-out;
|
||||
}
|
||||
#wrapper nav dl a:hover {
|
||||
color: #2d91ea;
|
||||
border-bottom-color: #2d91ea;
|
||||
}
|
||||
#wrapper #contentWrapper {
|
||||
width: 80%;
|
||||
max-width: 1080px;
|
||||
margin-left: 20%;
|
||||
padding: 0px 40px;
|
||||
padding-top: 72px;
|
||||
}
|
||||
article {
|
||||
border-top: 1px solid #ebebeb;
|
||||
padding: 40px 0;
|
||||
}
|
||||
article h2 {
|
||||
margin-top: 20px;
|
||||
}
|
||||
p,
|
||||
ul li {
|
||||
font-family: "proxima-nova";
|
||||
line-height: 20px;
|
||||
font-size: 16px;
|
||||
margin-top: 10px;
|
||||
color: #767c8d;
|
||||
}
|
||||
p a,
|
||||
ul li a {
|
||||
text-decoration: none;
|
||||
border-bottom: 1px solid #2d91ea;
|
||||
color: #2d91ea;
|
||||
}
|
||||
canvas {
|
||||
margin-top: 20px;
|
||||
}
|
||||
pre {
|
||||
background-color: #292b36;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
position: relative;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
margin: 40px 0 20px 0;
|
||||
}
|
||||
pre code {
|
||||
display: block;
|
||||
}
|
||||
pre:before {
|
||||
content: attr(data-type);
|
||||
position: absolute;
|
||||
font-size: 12px;
|
||||
top: -30px;
|
||||
left: 0;
|
||||
font-family: "proxima-nova";
|
||||
font-weight: 400;
|
||||
display: inline-block;
|
||||
padding: 2px 5px;
|
||||
border-radius: 5px;
|
||||
background-color: #ebebeb;
|
||||
}
|
||||
185
docs/styles.less
185
docs/styles.less
@ -1,185 +0,0 @@
|
||||
@import "prettify";
|
||||
|
||||
@codeBackground : #292B36;
|
||||
|
||||
@primaryFont : "proxima-nova";
|
||||
|
||||
@textColour : #282B36;
|
||||
@secondaryTextColour : #767c8d;
|
||||
|
||||
@borderPaleColour : #EBEBEB;
|
||||
@pageBorderColour : @textColour;
|
||||
|
||||
@red : #F33E6F;
|
||||
@green : #46BFBD;
|
||||
@yellow : #FDB45C;
|
||||
@blue : #2D91EA;
|
||||
|
||||
*{
|
||||
padding:0;
|
||||
margin:0;
|
||||
box-sizing:border-box;
|
||||
-moz-box-sizing:border-box;
|
||||
-webkit-box-sizing:border-box;
|
||||
color:inherit;
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
body{
|
||||
color: @textColour;
|
||||
min-width: 768px;
|
||||
}
|
||||
|
||||
.redBorder,.greenBorder,.yellowBorder{
|
||||
border-top: 8px solid @pageBorderColour;
|
||||
width: 33.33%;
|
||||
float: left;
|
||||
height: 16px;
|
||||
position: relative;
|
||||
z-index:50;
|
||||
}
|
||||
.redBorder{
|
||||
background-color: @red;
|
||||
}
|
||||
.greenBorder{
|
||||
background-color: @green;
|
||||
}
|
||||
.yellowBorder{
|
||||
background-color: @yellow;
|
||||
}
|
||||
|
||||
h1{
|
||||
font-family: @primaryFont;
|
||||
font-weight: 600;
|
||||
font-size: 32px;
|
||||
}
|
||||
h2{
|
||||
font-family: @primaryFont;
|
||||
font-weight: 600;
|
||||
font-size: 22px;
|
||||
line-height: 40px;
|
||||
}
|
||||
#mainHeader{
|
||||
font-size: 55px;
|
||||
}
|
||||
#introText{
|
||||
font-weight: 400;
|
||||
margin-top: 20px;
|
||||
font-size: 26px;
|
||||
line-height: 40px;
|
||||
margin-bottom: 40px;
|
||||
}
|
||||
#wrapper{
|
||||
margin: 0 auto;
|
||||
position: relative;
|
||||
min-width: 768px;
|
||||
nav{
|
||||
width: 20%;
|
||||
padding-right: 20px;
|
||||
position: fixed;
|
||||
height: 100%;
|
||||
overflow-y: scroll;
|
||||
top: 0;
|
||||
z-index: 0;
|
||||
padding: 40px 20px;
|
||||
font-family: @primaryFont;
|
||||
background-color: @borderPaleColour;
|
||||
|
||||
dl{
|
||||
color: @secondaryTextColour;
|
||||
dt{
|
||||
list-style: none;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 5px;
|
||||
a{
|
||||
display: block;
|
||||
padding: 2px 0;
|
||||
border-bottom: 1px solid fade(@secondaryTextColour,20%);
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
dd{
|
||||
margin-bottom: 5px;
|
||||
padding-left: 5px;
|
||||
&:before{
|
||||
content: "- ";
|
||||
|
||||
}
|
||||
a{
|
||||
text-decoration:none;
|
||||
font-size: 12px;
|
||||
border-bottom: 1px solid transparent;
|
||||
}
|
||||
}
|
||||
a{
|
||||
-webkit-transition: all 200ms ease-in-out;
|
||||
-moz-transition: all 200ms ease-in-out;
|
||||
-o-transition: all 200ms ease-in-out;
|
||||
-ms-transition: all 200ms ease-in-out;
|
||||
transition: all 200ms ease-in-out;
|
||||
&:hover{
|
||||
color: @blue;
|
||||
border-bottom-color:@blue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#contentWrapper{
|
||||
width: 80%;
|
||||
max-width: 1080px;
|
||||
margin-left: 20%;
|
||||
padding: 0px 40px;
|
||||
padding-top: 72px;
|
||||
}
|
||||
}
|
||||
article{
|
||||
border-top: 1px solid @borderPaleColour;
|
||||
padding: 40px 0;
|
||||
h2{
|
||||
margin-top: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
p,ul li{
|
||||
font-family: @primaryFont;
|
||||
line-height: 20px;
|
||||
font-size: 16px;
|
||||
margin-top: 10px;
|
||||
color: @secondaryTextColour;
|
||||
a{
|
||||
text-decoration: none;
|
||||
border-bottom: 1px solid @blue;
|
||||
color: @blue;
|
||||
}
|
||||
}
|
||||
|
||||
canvas{
|
||||
margin-top: 20px;
|
||||
}
|
||||
pre{
|
||||
background-color: @codeBackground;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
position: relative;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
margin: 40px 0 20px 0;
|
||||
code{
|
||||
display: block;
|
||||
}
|
||||
&:before{
|
||||
content: attr(data-type);
|
||||
position: absolute;
|
||||
font-size: 12px;
|
||||
top: -30px;
|
||||
left: 0;
|
||||
font-family: @primaryFont;
|
||||
font-weight: 400;
|
||||
display: inline-block;
|
||||
padding: 2px 5px;
|
||||
border-radius: 5px;
|
||||
background-color: @borderPaleColour;
|
||||
}
|
||||
}
|
||||
p{
|
||||
}
|
||||
87
gulpfile.js
Normal file
87
gulpfile.js
Normal file
@ -0,0 +1,87 @@
|
||||
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'),
|
||||
exec = require('child_process').exec;
|
||||
|
||||
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(gulp.dest(outputDir))
|
||||
.pipe(uglify({preserveComments:'some'}))
|
||||
.pipe(concat('Chart.min.js'))
|
||||
.pipe(gulp.dest(outputDir));
|
||||
|
||||
function FileName(moduleName){
|
||||
return srcDir+'Chart.'+moduleName+'.js';
|
||||
};
|
||||
});
|
||||
|
||||
gulp.task('jshint', function(){
|
||||
return gulp.src(srcDir + '*.js')
|
||||
.pipe(jshint())
|
||||
.pipe(jshint.reporter('default'));
|
||||
});
|
||||
|
||||
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']);
|
||||
|
||||
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']);
|
||||
21
package.json
Normal file
21
package.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Chart.js",
|
||||
"homepage": "http://www.chartjs.org",
|
||||
"description": "Simple HTML5 charts using the canvas element.",
|
||||
"private": true,
|
||||
"version": "1.0.0-beta",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nnnick/Chart.js.git"
|
||||
},
|
||||
"dependences": {},
|
||||
"devDependencies": {
|
||||
"gulp": "3.5.x",
|
||||
"gulp-concat": "~2.1.x",
|
||||
"gulp-uglify": "~0.2.x",
|
||||
"gulp-util": "~2.2.x",
|
||||
"gulp-jshint": "~1.5.1",
|
||||
"gulp-size": "~0.4.0",
|
||||
"gulp-connect": "~2.0.5"
|
||||
}
|
||||
}
|
||||
57
readme.md
57
readme.md
@ -1,52 +1,25 @@
|
||||
Chart.js
|
||||
=======
|
||||
# Chart.js
|
||||
|
||||
*Simple HTML5 Charts using the canvas element* [chartjs.org](http://www.chartjs.org)
|
||||
|
||||
Quick FYI
|
||||
-------
|
||||
I'm currently working on a big refactor of the library into a more object oriented structure.
|
||||
## Documentation
|
||||
|
||||
It'll have an extendable class structure for adding community developed chart types. By opening up components into Chart.js into extendable classes, it'll allow for much easier community driven library extensions rather than tacking on new features as required. The refactor will also feature a generisized version of the interaction layer introduced by Regaddi in his tooltips branch - https://github.com/nnnick/Chart.js/pull/51. On top of this, it'll include utility methods on each chart object, for updating, clearing and redrawing charts etc.
|
||||
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.
|
||||
|
||||
I haven't quite got the bandwidth right now to be juggling both issues/requests in master while redesigning all of the core code in Chart.js. By focusing on the refactor, it'll get done WAY quicker.
|
||||
## License
|
||||
|
||||
Extensibility will absolutely be at the core of the refactor, allowing for the development of complex extension modules, but also keeping a lightweight set of core code.
|
||||
Chart.js is available under the [MIT license](http://opensource.org/licenses/MIT).
|
||||
|
||||
Hang tight - it'll be worth it.
|
||||
## Bugs & issues
|
||||
|
||||
PS. If you're interested in reviewing some code or trying out writing extensions, shoot me an email.
|
||||
|
||||
###Update - 8th September
|
||||
Just a quick update on the refactor.
|
||||
|
||||
Just wanted to let you guys know it's making really good progress, and it'll be well worth the wait.
|
||||
|
||||
The new version is being broken up into Chart type modules, with each of the current 6 chart types using documented and extendable classes and helper methods from the Chart.js core. This means the community will be able to build new chart types using existing components, or extend existing types to do something a bit different.
|
||||
|
||||
By splitting the different charts into modules will mean the ability to use AMD if appropriate, but I'll also be writing a simple web interface for concatenating chart types into a minified production ready custom build.
|
||||
|
||||
The syntax for creating charts **will not change**, so the upgrade should be a drop in replacement, but give you the ability to have a whole new level of interactivity and animated data updates.
|
||||
|
||||
Right now I've wrote 80% of the core, and refactored the Doughnut and Pie charts, and I'm a good way through the Line and Bar charts. I hope to have the new version ready to release with some new docs late September/early October.
|
||||
|
||||
I know PR and issues are racking up in the repo, and I'll do my best to sort them ASAP, but I think this update is really important for creating flexibility and extensibility to cater for these new features in an elegant way, rather than introducing scope creep into an architecture that wasn't designed to deliver this extra functionality.
|
||||
|
||||
Big thanks for all the support - it's been totally overwhelming.
|
||||
|
||||
###Another Quick Update - 16th October
|
||||
First of all - my apologies, early October has drifted away from me and we're moving towards late October. This last month has been really unexpectedly busy, and I've had a lot of stuff going on, so I haven't quite managed to find as much time to work on Chart.js as I'd hoped.
|
||||
|
||||
In terms of an updated ETA, I'm really aiming for a pre-November release, and I'll be having some late nights and a few days off to try my best to make this happen.
|
||||
|
||||
Again, really appreciate the support and cheers for your patience for the new version.
|
||||
When reporting bugs or issues, if you could include a link to a simple [jsbin](http://jsbin.com) or similar demonstrating the issue, that'd be really helpful.
|
||||
|
||||
|
||||
Documentation
|
||||
-------
|
||||
You can find documentation at [chartjs.org/docs](http://www.chartjs.org/docs).
|
||||
## Contributing
|
||||
New contributions to the library are welcome, just a couple of guidelines:
|
||||
|
||||
License
|
||||
-------
|
||||
Chart.js was taken down on the 19th March. It is now back online for good and IS available under MIT license.
|
||||
|
||||
Chart.js is available under the [MIT license] (http://opensource.org/licenses/MIT).
|
||||
- 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.
|
||||
@ -3,37 +3,43 @@
|
||||
<head>
|
||||
<title>Bar Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
|
||||
<style>
|
||||
canvas{
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas" height="450" width="600"></canvas>
|
||||
<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,1)",
|
||||
data : [65,59,90,81,56,55,40]
|
||||
},
|
||||
{
|
||||
fillColor : "rgba(151,187,205,0.5)",
|
||||
strokeColor : "rgba(151,187,205,1)",
|
||||
data : [28,48,40,19,96,27,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
|
||||
});
|
||||
}
|
||||
|
||||
var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Bar(barChartData);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -3,44 +3,65 @@
|
||||
<head>
|
||||
<title>Doughnut Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
|
||||
<style>
|
||||
canvas{
|
||||
body{
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
#canvas-holder{
|
||||
width:30%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas" height="450" width="450"></canvas>
|
||||
<div id="canvas-holder">
|
||||
<canvas id="chart-area" width="500" height="500"/>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
var doughnutData = [
|
||||
{
|
||||
value: 30,
|
||||
color:"#F7464A"
|
||||
value: 300,
|
||||
color:"#F7464A",
|
||||
highlight: "#FF5A5E",
|
||||
label: "Red"
|
||||
},
|
||||
{
|
||||
value : 50,
|
||||
color : "#46BFBD"
|
||||
value: 50,
|
||||
color: "#46BFBD",
|
||||
highlight: "#5AD3D1",
|
||||
label: "Green"
|
||||
},
|
||||
{
|
||||
value : 100,
|
||||
color : "#FDB45C"
|
||||
value: 100,
|
||||
color: "#FDB45C",
|
||||
highlight: "#FFC870",
|
||||
label: "Yellow"
|
||||
},
|
||||
{
|
||||
value : 40,
|
||||
color : "#949FB1"
|
||||
value: 40,
|
||||
color: "#949FB1",
|
||||
highlight: "#A8B3C5",
|
||||
label: "Grey"
|
||||
},
|
||||
{
|
||||
value : 120,
|
||||
color : "#4D5360"
|
||||
value: 120,
|
||||
color: "#4D5360",
|
||||
highlight: "#616774",
|
||||
label: "Dark Grey"
|
||||
}
|
||||
|
||||
|
||||
];
|
||||
|
||||
var myDoughnut = new Chart(document.getElementById("canvas").getContext("2d")).Doughnut(doughnutData);
|
||||
|
||||
window.onload = function(){
|
||||
var ctx = document.getElementById("chart-area").getContext("2d");
|
||||
window.myDoughnut = new Chart(ctx).Doughnut(doughnutData, {responsive : true});
|
||||
};
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -3,41 +3,52 @@
|
||||
<head>
|
||||
<title>Line Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
|
||||
<style>
|
||||
canvas{
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas" height="450" width="600"></canvas>
|
||||
<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 : [
|
||||
{
|
||||
fillColor : "rgba(220,220,220,0.5)",
|
||||
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",
|
||||
data : [65,59,90,81,56,55,40]
|
||||
pointHighlightFill : "#fff",
|
||||
pointHighlightStroke : "rgba(220,220,220,1)",
|
||||
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
|
||||
},
|
||||
{
|
||||
fillColor : "rgba(151,187,205,0.5)",
|
||||
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",
|
||||
data : [28,48,40,19,96,27,100]
|
||||
pointHighlightFill : "#fff",
|
||||
pointHighlightStroke : "rgba(151,187,205,1)",
|
||||
data : [randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor(),randomScalingFactor()]
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
}
|
||||
|
||||
var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Line(lineChartData);
|
||||
|
||||
window.onload = function(){
|
||||
var ctx = document.getElementById("canvas").getContext("2d");
|
||||
window.myLine = new Chart(ctx).Line(lineChartData, {
|
||||
responsive: true
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,38 +1,58 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Radar Chart</title>
|
||||
<title>Pie Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
|
||||
<style>
|
||||
canvas{
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas" height="450" width="450"></canvas>
|
||||
<div id="canvas-holder">
|
||||
<canvas id="chart-area" width="300" height="300"/>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
var pieData = [
|
||||
{
|
||||
value: 30,
|
||||
color:"#F38630"
|
||||
value: 300,
|
||||
color:"#F7464A",
|
||||
highlight: "#FF5A5E",
|
||||
label: "Red"
|
||||
},
|
||||
{
|
||||
value : 50,
|
||||
color : "#E0E4CC"
|
||||
value: 50,
|
||||
color: "#46BFBD",
|
||||
highlight: "#5AD3D1",
|
||||
label: "Green"
|
||||
},
|
||||
{
|
||||
value : 100,
|
||||
color : "#69D2E7"
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
];
|
||||
|
||||
var myPie = new Chart(document.getElementById("canvas").getContext("2d")).Pie(pieData);
|
||||
|
||||
window.onload = function(){
|
||||
var ctx = document.getElementById("chart-area").getContext("2d");
|
||||
window.myPie = new Chart(ctx).Pie(pieData);
|
||||
};
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
60
samples/polar-area.html
Normal file
60
samples/polar-area.html
Normal file
@ -0,0 +1,60 @@
|
||||
<!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,44 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Polar Area Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
|
||||
<style>
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas" height="400" width="400"></canvas>
|
||||
|
||||
|
||||
<script>
|
||||
var chartData = [
|
||||
{
|
||||
value : Math.random(),
|
||||
color: "#D97041"
|
||||
},
|
||||
{
|
||||
value : Math.random(),
|
||||
color: "#C7604C"
|
||||
},
|
||||
{
|
||||
value : Math.random(),
|
||||
color: "#21323D"
|
||||
},
|
||||
{
|
||||
value : Math.random(),
|
||||
color: "#9D9B7F"
|
||||
},
|
||||
{
|
||||
value : Math.random(),
|
||||
color: "#7D4F6D"
|
||||
},
|
||||
{
|
||||
value : Math.random(),
|
||||
color: "#584A5E"
|
||||
}
|
||||
];
|
||||
var myPolarArea = new Chart(document.getElementById("canvas").getContext("2d")).PolarArea(chartData);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@ -10,34 +10,44 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas" height="450" width="450"></canvas>
|
||||
<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]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var radarChartData = {
|
||||
labels : ["Eating","Drinking","Sleeping","Designing","Coding","Partying","Running"],
|
||||
datasets : [
|
||||
{
|
||||
fillColor : "rgba(220,220,220,0.5)",
|
||||
strokeColor : "rgba(220,220,220,1)",
|
||||
pointColor : "rgba(220,220,220,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [65,59,90,81,56,55,40]
|
||||
},
|
||||
{
|
||||
fillColor : "rgba(151,187,205,0.5)",
|
||||
strokeColor : "rgba(151,187,205,1)",
|
||||
pointColor : "rgba(151,187,205,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [28,48,40,19,96,27,100]
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
window.onload = function(){
|
||||
window.myRadar = new Chart(document.getElementById("canvas").getContext("2d")).Radar(radarChartData, {
|
||||
responsive: true
|
||||
});
|
||||
}
|
||||
|
||||
var myRadar = new Chart(document.getElementById("canvas").getContext("2d")).Radar(radarChartData,{scaleShowLabels : false, pointLabelFontSize : 10});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -1,155 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Doughnut Chart</title>
|
||||
<script src="../Chart.js"></script>
|
||||
<meta name = "viewport" content = "initial-scale = 1, user-scalable = no">
|
||||
<style>
|
||||
canvas{
|
||||
float: left;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div style="width:600px;height:600px;">
|
||||
<canvas id="doughnut" height="300" width="200"></canvas>
|
||||
<canvas id="line" height="300" width="200"></canvas>
|
||||
<canvas id="polarArea" height="300" width="200"></canvas>
|
||||
<canvas id="bar" height="300" width="200"></canvas>
|
||||
<canvas id="pie" height="300" width="200"></canvas>
|
||||
<canvas id="radar" height="300" width="200"></canvas>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
var doughnutData = [
|
||||
{
|
||||
value: 30,
|
||||
color:"#F7464A"
|
||||
},
|
||||
{
|
||||
value : 50,
|
||||
color : "#46BFBD"
|
||||
},
|
||||
{
|
||||
value : 100,
|
||||
color : "#FDB45C"
|
||||
},
|
||||
{
|
||||
value : 40,
|
||||
color : "#949FB1"
|
||||
},
|
||||
{
|
||||
value : 120,
|
||||
color : "#4D5360"
|
||||
}
|
||||
|
||||
];
|
||||
var lineChartData = {
|
||||
labels : ["","","","","","",""],
|
||||
datasets : [
|
||||
{
|
||||
fillColor : "rgba(220,220,220,0.5)",
|
||||
strokeColor : "rgba(220,220,220,1)",
|
||||
pointColor : "rgba(220,220,220,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [65,59,90,81,56,55,40]
|
||||
},
|
||||
{
|
||||
fillColor : "rgba(151,187,205,0.5)",
|
||||
strokeColor : "rgba(151,187,205,1)",
|
||||
pointColor : "rgba(151,187,205,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [28,48,40,19,96,27,100]
|
||||
}
|
||||
]
|
||||
|
||||
};
|
||||
var pieData = [
|
||||
{
|
||||
value: 30,
|
||||
color:"#F38630"
|
||||
},
|
||||
{
|
||||
value : 50,
|
||||
color : "#E0E4CC"
|
||||
},
|
||||
{
|
||||
value : 100,
|
||||
color : "#69D2E7"
|
||||
}
|
||||
|
||||
];
|
||||
var barChartData = {
|
||||
labels : ["January","February","March","April","May","June","July"],
|
||||
datasets : [
|
||||
{
|
||||
fillColor : "rgba(220,220,220,0.5)",
|
||||
strokeColor : "rgba(220,220,220,1)",
|
||||
data : [65,59,90,81,56,55,40]
|
||||
},
|
||||
{
|
||||
fillColor : "rgba(151,187,205,0.5)",
|
||||
strokeColor : "rgba(151,187,205,1)",
|
||||
data : [28,48,40,19,96,27,100]
|
||||
}
|
||||
]
|
||||
|
||||
};
|
||||
var chartData = [
|
||||
{
|
||||
value : Math.random(),
|
||||
color: "#D97041"
|
||||
},
|
||||
{
|
||||
value : Math.random(),
|
||||
color: "#C7604C"
|
||||
},
|
||||
{
|
||||
value : Math.random(),
|
||||
color: "#21323D"
|
||||
},
|
||||
{
|
||||
value : Math.random(),
|
||||
color: "#9D9B7F"
|
||||
},
|
||||
{
|
||||
value : Math.random(),
|
||||
color: "#7D4F6D"
|
||||
},
|
||||
{
|
||||
value : Math.random(),
|
||||
color: "#584A5E"
|
||||
}
|
||||
];
|
||||
var radarChartData = {
|
||||
labels : ["","","","","","",""],
|
||||
datasets : [
|
||||
{
|
||||
fillColor : "rgba(220,220,220,0.5)",
|
||||
strokeColor : "rgba(220,220,220,1)",
|
||||
pointColor : "rgba(220,220,220,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [65,59,90,81,56,55,40]
|
||||
},
|
||||
{
|
||||
fillColor : "rgba(151,187,205,0.5)",
|
||||
strokeColor : "rgba(151,187,205,1)",
|
||||
pointColor : "rgba(151,187,205,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [28,48,40,19,96,27,100]
|
||||
}
|
||||
]
|
||||
|
||||
};
|
||||
new Chart(document.getElementById("doughnut").getContext("2d")).Doughnut(doughnutData);
|
||||
new Chart(document.getElementById("line").getContext("2d")).Line(lineChartData);
|
||||
new Chart(document.getElementById("radar").getContext("2d")).Radar(radarChartData);
|
||||
new Chart(document.getElementById("polarArea").getContext("2d")).PolarArea(chartData);
|
||||
new Chart(document.getElementById("bar").getContext("2d")).Bar(barChartData);
|
||||
new Chart(document.getElementById("pie").getContext("2d")).Pie(pieData);
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 78 KiB |
1443
site/assets/Chart.js
vendored
1443
site/assets/Chart.js
vendored
File diff suppressed because it is too large
Load Diff
320
site/assets/effects.js
vendored
320
site/assets/effects.js
vendored
@ -1,320 +0,0 @@
|
||||
$(window).load(function() {
|
||||
var lineChartData = {
|
||||
labels : ["January","February","March","April","May","June","July"],
|
||||
datasets : [
|
||||
{
|
||||
fillColor : "rgba(220,220,220,0.5)",
|
||||
strokeColor : "rgba(220,220,220,1)",
|
||||
pointColor : "rgba(220,220,220,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [65,59,90,81,56,55,40]
|
||||
},
|
||||
{
|
||||
fillColor : "rgba(151,187,205,0.5)",
|
||||
strokeColor : "rgba(151,187,205,1)",
|
||||
pointColor : "rgba(151,187,205,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [28,48,40,19,96,27,100]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var barChartData = {
|
||||
labels : ["January","February","March","April","May","June","July"],
|
||||
datasets : [
|
||||
{
|
||||
fillColor : "rgba(220,220,220,0.5)",
|
||||
strokeColor : "rgba(220,220,220,1)",
|
||||
data : [65,59,90,81,56,55,40]
|
||||
},
|
||||
{
|
||||
fillColor : "rgba(151,187,205,0.5)",
|
||||
strokeColor : "rgba(151,187,205,1)",
|
||||
data : [28,48,40,19,96,27,100]
|
||||
}
|
||||
]
|
||||
|
||||
};
|
||||
|
||||
var radarChartData = {
|
||||
labels : ["A","B","C","D","E","F","G"],
|
||||
datasets : [
|
||||
{
|
||||
fillColor : "rgba(220,220,220,0.5)",
|
||||
strokeColor : "rgba(220,220,220,1)",
|
||||
pointColor : "rgba(220,220,220,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [65,59,90,81,56,55,40]
|
||||
},
|
||||
{
|
||||
fillColor : "rgba(151,187,205,0.5)",
|
||||
strokeColor : "rgba(151,187,205,1)",
|
||||
pointColor : "rgba(151,187,205,1)",
|
||||
pointStrokeColor : "#fff",
|
||||
data : [28,48,40,19,96,27,100]
|
||||
}
|
||||
]
|
||||
|
||||
};
|
||||
var pieChartData = [
|
||||
{
|
||||
value: 30,
|
||||
color:"#F38630"
|
||||
},
|
||||
{
|
||||
value : 50,
|
||||
color : "#E0E4CC"
|
||||
},
|
||||
{
|
||||
value : 100,
|
||||
color : "#69D2E7"
|
||||
}
|
||||
|
||||
];
|
||||
var polarAreaChartData = [
|
||||
{
|
||||
value : 62,
|
||||
color: "#D97041"
|
||||
},
|
||||
{
|
||||
value : 70,
|
||||
color: "#C7604C"
|
||||
},
|
||||
{
|
||||
value : 41,
|
||||
color: "#21323D"
|
||||
},
|
||||
{
|
||||
value : 24,
|
||||
color: "#9D9B7F"
|
||||
},
|
||||
{
|
||||
value : 55,
|
||||
color: "#7D4F6D"
|
||||
},
|
||||
{
|
||||
value : 18,
|
||||
color: "#584A5E"
|
||||
}
|
||||
];
|
||||
var doughnutChartData = [
|
||||
{
|
||||
value: 30,
|
||||
color:"#F7464A"
|
||||
},
|
||||
{
|
||||
value : 50,
|
||||
color : "#46BFBD"
|
||||
},
|
||||
{
|
||||
value : 100,
|
||||
color : "#FDB45C"
|
||||
},
|
||||
{
|
||||
value : 40,
|
||||
color : "#949FB1"
|
||||
},
|
||||
{
|
||||
value : 120,
|
||||
color : "#4D5360"
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
var globalGraphSettings = {animation : Modernizr.canvas};
|
||||
|
||||
setIntroChart();
|
||||
|
||||
function setIntroChart(){
|
||||
var ctx = document.getElementById("introChart").getContext("2d");
|
||||
|
||||
new Chart(ctx).Line(lineChartData,{animation: Modernizr.canvas, scaleShowLabels : false, scaleFontColor : "#767C8D"});
|
||||
};
|
||||
|
||||
function showLineChart(){
|
||||
var ctx = document.getElementById("lineChartCanvas").getContext("2d");
|
||||
new Chart(ctx).Line(lineChartData,globalGraphSettings);
|
||||
};
|
||||
function showBarChart(){
|
||||
var ctx = document.getElementById("barChartCanvas").getContext("2d");
|
||||
new Chart(ctx).Bar(barChartData,globalGraphSettings);
|
||||
};
|
||||
function showRadarChart(){
|
||||
var ctx = document.getElementById("radarChartCanvas").getContext("2d");
|
||||
new Chart(ctx).Radar(radarChartData,globalGraphSettings);
|
||||
}
|
||||
function showPolarAreaChart(){
|
||||
var ctx = document.getElementById("polarAreaChartCanvas").getContext("2d");
|
||||
new Chart(ctx).PolarArea(polarAreaChartData,globalGraphSettings);
|
||||
}
|
||||
function showPieChart(){
|
||||
var ctx = document.getElementById("pieChartCanvas").getContext("2d");
|
||||
new Chart(ctx).Pie(pieChartData,globalGraphSettings);
|
||||
};
|
||||
function showDoughnutChart(){
|
||||
var ctx = document.getElementById("doughnutChartCanvas").getContext("2d");
|
||||
new Chart(ctx).Doughnut(doughnutChartData,globalGraphSettings);
|
||||
};
|
||||
|
||||
var graphInitDelay = 300;
|
||||
|
||||
//Set up each of the inview events here.
|
||||
$("#lineChart").on("inview",function(){
|
||||
var $this = $(this);
|
||||
$this.removeClass("hidden").off("inview");
|
||||
setTimeout(showLineChart,graphInitDelay);
|
||||
});
|
||||
$("#barChart").on("inview",function(){
|
||||
var $this = $(this);
|
||||
$this.removeClass("hidden").off("inview");
|
||||
setTimeout(showBarChart,graphInitDelay);
|
||||
});
|
||||
|
||||
$("#radarChart").on("inview",function(){
|
||||
var $this = $(this);
|
||||
$this.removeClass("hidden").off("inview");
|
||||
setTimeout(showRadarChart,graphInitDelay);
|
||||
});
|
||||
$("#pieChart").on("inview",function(){
|
||||
var $this = $(this);
|
||||
$this.removeClass("hidden").off("inview");
|
||||
setTimeout(showPieChart,graphInitDelay);
|
||||
});
|
||||
$("#polarAreaChart").on("inview",function(){
|
||||
var $this = $(this);
|
||||
$this.removeClass("hidden").off("inview");
|
||||
setTimeout(showPolarAreaChart,graphInitDelay);
|
||||
});
|
||||
$("#doughnutChart").on("inview",function(){
|
||||
var $this = $(this);
|
||||
$this.removeClass("hidden").off("inview");
|
||||
setTimeout(showDoughnutChart,graphInitDelay);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* author Christopher Blum
|
||||
* - based on the idea of Remy Sharp, http://remysharp.com/2009/01/26/element-in-view-event-plugin/
|
||||
* - forked from http://github.com/zuk/jquery.inview/
|
||||
*/
|
||||
(function ($) {
|
||||
var inviewObjects = {}, viewportSize, viewportOffset,
|
||||
d = document, w = window, documentElement = d.documentElement, expando = $.expando;
|
||||
|
||||
$.event.special.inview = {
|
||||
add: function(data) {
|
||||
inviewObjects[data.guid + "-" + this[expando]] = { data: data, $element: $(this) };
|
||||
},
|
||||
|
||||
remove: function(data) {
|
||||
try { delete inviewObjects[data.guid + "-" + this[expando]]; } catch(e) {}
|
||||
}
|
||||
};
|
||||
|
||||
function getViewportSize() {
|
||||
var mode, domObject, size = { height: w.innerHeight, width: w.innerWidth };
|
||||
|
||||
// if this is correct then return it. iPad has compat Mode, so will
|
||||
// go into check clientHeight/clientWidth (which has the wrong value).
|
||||
if (!size.height) {
|
||||
mode = d.compatMode;
|
||||
if (mode || !$.support.boxModel) { // IE, Gecko
|
||||
domObject = mode === 'CSS1Compat' ?
|
||||
documentElement : // Standards
|
||||
d.body; // Quirks
|
||||
size = {
|
||||
height: domObject.clientHeight,
|
||||
width: domObject.clientWidth
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
function getViewportOffset() {
|
||||
return {
|
||||
top: w.pageYOffset || documentElement.scrollTop || d.body.scrollTop,
|
||||
left: w.pageXOffset || documentElement.scrollLeft || d.body.scrollLeft
|
||||
};
|
||||
}
|
||||
|
||||
function checkInView() {
|
||||
var $elements = $(), elementsLength, i = 0;
|
||||
|
||||
$.each(inviewObjects, function(i, inviewObject) {
|
||||
var selector = inviewObject.data.selector,
|
||||
$element = inviewObject.$element;
|
||||
$elements = $elements.add(selector ? $element.find(selector) : $element);
|
||||
});
|
||||
|
||||
elementsLength = $elements.length;
|
||||
if (elementsLength) {
|
||||
viewportSize = viewportSize || getViewportSize();
|
||||
viewportOffset = viewportOffset || getViewportOffset();
|
||||
|
||||
for (; i<elementsLength; i++) {
|
||||
// Ignore elements that are not in the DOM tree
|
||||
if (!$.contains(documentElement, $elements[i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var $element = $($elements[i]),
|
||||
elementSize = { height: $element.height(), width: $element.width() },
|
||||
elementOffset = $element.offset(),
|
||||
inView = $element.data('inview'),
|
||||
visiblePartX,
|
||||
visiblePartY,
|
||||
visiblePartsMerged;
|
||||
|
||||
// Don't ask me why because I haven't figured out yet:
|
||||
// viewportOffset and viewportSize are sometimes suddenly null in Firefox 5.
|
||||
// Even though it sounds weird:
|
||||
// It seems that the execution of this function is interferred by the onresize/onscroll event
|
||||
// where viewportOffset and viewportSize are unset
|
||||
if (!viewportOffset || !viewportSize) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (elementOffset.top + elementSize.height > viewportOffset.top &&
|
||||
elementOffset.top < viewportOffset.top + viewportSize.height &&
|
||||
elementOffset.left + elementSize.width > viewportOffset.left &&
|
||||
elementOffset.left < viewportOffset.left + viewportSize.width) {
|
||||
visiblePartX = (viewportOffset.left > elementOffset.left ?
|
||||
'right' : (viewportOffset.left + viewportSize.width) < (elementOffset.left + elementSize.width) ?
|
||||
'left' : 'both');
|
||||
visiblePartY = (viewportOffset.top > elementOffset.top ?
|
||||
'bottom' : (viewportOffset.top + viewportSize.height) < (elementOffset.top + elementSize.height) ?
|
||||
'top' : 'both');
|
||||
visiblePartsMerged = visiblePartX + "-" + visiblePartY;
|
||||
if (!inView || inView !== visiblePartsMerged) {
|
||||
$element.data('inview', visiblePartsMerged).trigger('inview', [true, visiblePartX, visiblePartY]);
|
||||
}
|
||||
} else if (inView) {
|
||||
$element.data('inview', false).trigger('inview', [false]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$(w).bind("scroll resize", function() {
|
||||
viewportSize = viewportOffset = null;
|
||||
});
|
||||
|
||||
// IE < 9 scrolls to focused elements without firing the "scroll" event
|
||||
if (!documentElement.addEventListener && documentElement.attachEvent) {
|
||||
documentElement.attachEvent("onfocusin", function() {
|
||||
viewportOffset = null;
|
||||
});
|
||||
}
|
||||
|
||||
// Use setInterval in order to also make sure this captures elements within
|
||||
// "overflow:scroll" elements or elements that appeared in the dom tree due to
|
||||
// dom manipulation and reflow
|
||||
// old: $(window).scroll(checkInView);
|
||||
//
|
||||
// By the way, iOS (iPad, iPhone, ...) seems to not execute, or at least delays
|
||||
// intervals while the user scrolls. Therefore the inview event might fire a bit late there
|
||||
setInterval(checkInView, 250);
|
||||
})(jQuery);
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 82 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 47 KiB |
141
site/index.html
141
site/index.html
File diff suppressed because one or more lines are too long
205
site/styles.css
205
site/styles.css
@ -1,205 +0,0 @@
|
||||
* {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
color: inherit;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
body {
|
||||
color: #282b36;
|
||||
border-top: 8px solid #282b36;
|
||||
}
|
||||
canvas {
|
||||
font-family: "proxima-nova", sans-serif sans-serif;
|
||||
}
|
||||
.redBorder,
|
||||
.greenBorder,
|
||||
.yellowBorder {
|
||||
width: 33.33%;
|
||||
float: left;
|
||||
height: 8px;
|
||||
}
|
||||
.redBorder {
|
||||
background-color: #f33e6f;
|
||||
}
|
||||
.greenBorder {
|
||||
background-color: #46bfbd;
|
||||
}
|
||||
.yellowBorder {
|
||||
background-color: #fdb45c;
|
||||
}
|
||||
h1 {
|
||||
font-family: "proxima-nova", sans-serif;
|
||||
font-weight: 600;
|
||||
font-size: 55px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
h2 {
|
||||
font-family: "proxima-nova", sans-serif;
|
||||
font-weight: 400;
|
||||
margin-top: 20px;
|
||||
font-size: 26px;
|
||||
line-height: 40px;
|
||||
}
|
||||
h3 {
|
||||
font-family: "proxima-nova", sans-serif;
|
||||
font-weight: 600;
|
||||
text-align: center;
|
||||
margin: 20px 0;
|
||||
}
|
||||
h3 a {
|
||||
color: #2d91ea;
|
||||
text-decoration: none;
|
||||
border-bottom: 1px solid #2d91ea;
|
||||
}
|
||||
p {
|
||||
font-family: "proxima-nova", sans-serif;
|
||||
line-height: 24px;
|
||||
font-size: 18px;
|
||||
color: #767c8d;
|
||||
}
|
||||
.btn {
|
||||
display: inline-block;
|
||||
padding: 20px;
|
||||
font-family: "proxima-nova", sans-serif;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
border-radius: 5px;
|
||||
text-align: center;
|
||||
font-size: 18px;
|
||||
-webkit-transition-property: background-color box-shadow;
|
||||
-webkit-transition-duration: 200ms;
|
||||
-webkit-transition-timing-function: ease-in-out;
|
||||
-moz-transition-property: background-color box-shadow;
|
||||
-moz-transition-duration: 200ms;
|
||||
-moz-transition-timing-function: ease-in-out;
|
||||
-ms-transition-property: background-color box-shadow;
|
||||
-ms-transition-duration: 200ms;
|
||||
-ms-transition-timing-function: ease-in-out;
|
||||
-o-transition-property: background-color box-shadow;
|
||||
-o-transition-duration: 200ms;
|
||||
-o-transition-timing-function: ease-in-out;
|
||||
transition-property: background-color box-shadow;
|
||||
transition-duration: 200ms;
|
||||
transition-timing-function: ease-in-out;
|
||||
}
|
||||
.btn:active {
|
||||
box-shadow: inset 1px 1px 4px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
.btn.red {
|
||||
background-color: #f33e6f;
|
||||
}
|
||||
.btn.red:hover {
|
||||
background-color: #f2265d;
|
||||
}
|
||||
.btn.blue {
|
||||
background-color: #2d91ea;
|
||||
}
|
||||
.btn.blue:hover {
|
||||
background-color: #1785e6;
|
||||
}
|
||||
header {
|
||||
width: 978px;
|
||||
margin: 20px auto;
|
||||
display: block;
|
||||
position: relative;
|
||||
}
|
||||
header hgroup {
|
||||
width: 50%;
|
||||
padding: 20px 0;
|
||||
}
|
||||
header #introChart {
|
||||
position: absolute;
|
||||
top: 60px;
|
||||
right: 0;
|
||||
}
|
||||
header .btn {
|
||||
margin-right: 10px;
|
||||
width: 180px;
|
||||
}
|
||||
footer {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
background-color: #ebebeb;
|
||||
}
|
||||
footer p {
|
||||
color: #767c8d;
|
||||
font-family: "proxima-nova", sans-serif;
|
||||
font-size: 16px;
|
||||
padding: 20px 0;
|
||||
}
|
||||
section {
|
||||
width: 978px;
|
||||
margin: 40px auto;
|
||||
}
|
||||
section:before {
|
||||
content: '';
|
||||
width: 600px;
|
||||
margin: 0 auto;
|
||||
border-top: 1px solid #ebebeb;
|
||||
height: 20px;
|
||||
display: block;
|
||||
}
|
||||
section:after {
|
||||
content: "";
|
||||
display: table;
|
||||
clear: both;
|
||||
}
|
||||
*section {
|
||||
zoom: 1;
|
||||
}
|
||||
#features article {
|
||||
width: 33.33%;
|
||||
float: left;
|
||||
}
|
||||
#features article p {
|
||||
display: block;
|
||||
width: 90%;
|
||||
margin: 0 auto;
|
||||
text-align: center;
|
||||
}
|
||||
#features article img {
|
||||
width: 250px;
|
||||
height: 250px;
|
||||
margin: 0 auto;
|
||||
display: block;
|
||||
}
|
||||
#examples article {
|
||||
-webkit-transition: opacity 200ms ease-in-out;
|
||||
-ms-transition: opacity 200ms ease-in-out;
|
||||
-moz-transition: opacity 200ms ease-in-out;
|
||||
-o-transition: opacity 200ms ease-in-out;
|
||||
transition: opacity 200ms ease-in-out;
|
||||
position: relative;
|
||||
margin-top: 20px;
|
||||
clear: both;
|
||||
}
|
||||
#examples article:after {
|
||||
content: '';
|
||||
width: 600px;
|
||||
padding-top: 40px;
|
||||
margin: 40px auto;
|
||||
border-bottom: 1px solid #ebebeb;
|
||||
height: 20px;
|
||||
display: block;
|
||||
clear: both;
|
||||
}
|
||||
#examples article p {
|
||||
margin-top: 10px;
|
||||
}
|
||||
#examples article .half {
|
||||
width: 50%;
|
||||
float: left;
|
||||
}
|
||||
#examples article .canvasWrapper {
|
||||
float: left;
|
||||
width: 449px;
|
||||
padding: 0 20px;
|
||||
}
|
||||
#examples h3 {
|
||||
clear: both;
|
||||
}
|
||||
#examples .hidden {
|
||||
opacity: 0;
|
||||
}
|
||||
295
src/Chart.Bar.js
Normal file
295
src/Chart.Bar.js
Normal file
@ -0,0 +1,295 @@
|
||||
(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 - 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){
|
||||
if (helpers.isNumber(dataPoint)){
|
||||
//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],
|
||||
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,
|
||||
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){
|
||||
if (helpers.isNumber(value)){
|
||||
//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){
|
||||
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);
|
||||
1883
src/Chart.Core.js
Executable file
1883
src/Chart.Core.js
Executable file
File diff suppressed because it is too large
Load Diff
184
src/Chart.Doughnut.js
Normal file
184
src/Chart.Doughnut.js
Normal file
@ -0,0 +1,184 @@
|
||||
(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)*(value / this.total);
|
||||
},
|
||||
calculateTotal : function(data){
|
||||
this.total = 0;
|
||||
helpers.each(data,function(segment){
|
||||
this.total += 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);
|
||||
343
src/Chart.Line.js
Normal file
343
src/Chart.Line.js
Normal file
@ -0,0 +1,343 @@
|
||||
(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 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,
|
||||
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){
|
||||
//Best way to do this? or in draw sequence...?
|
||||
if (helpers.isNumber(dataPoint)){
|
||||
//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],
|
||||
// x: this.scale.calculateX(index),
|
||||
// y: this.scale.endPoint,
|
||||
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,
|
||||
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){
|
||||
if (helpers.isNumber(value)){
|
||||
//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;
|
||||
|
||||
this.scale.draw(easingDecimal);
|
||||
|
||||
|
||||
helpers.each(this.datasets,function(dataset){
|
||||
|
||||
//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){
|
||||
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(dataset.points,function(point,index){
|
||||
//If we're at the start or end, we don't have a previous/next point
|
||||
//By setting the tension to 0 here, the curve will transition to straight at the end
|
||||
if (index === 0){
|
||||
point.controlPoints = helpers.splineCurve(point,point,dataset.points[index+1],0);
|
||||
}
|
||||
else if (index >= dataset.points.length-1){
|
||||
point.controlPoints = helpers.splineCurve(dataset.points[index-1],point,point,0);
|
||||
}
|
||||
else{
|
||||
point.controlPoints = helpers.splineCurve(dataset.points[index-1],point,dataset.points[index+1],this.options.bezierCurveTension);
|
||||
}
|
||||
},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){
|
||||
if(this.options.bezierCurve){
|
||||
ctx.bezierCurveTo(
|
||||
dataset.points[index-1].controlPoints.outer.x,
|
||||
dataset.points[index-1].controlPoints.outer.y,
|
||||
point.controlPoints.inner.x,
|
||||
point.controlPoints.inner.y,
|
||||
point.x,
|
||||
point.y
|
||||
);
|
||||
}
|
||||
else{
|
||||
ctx.lineTo(point.x,point.y);
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
ctx.moveTo(point.x,point.y);
|
||||
}
|
||||
},this);
|
||||
ctx.stroke();
|
||||
|
||||
|
||||
if (this.options.datasetFill){
|
||||
//Round off the line by going to the base of the chart, back to the start, then fill.
|
||||
ctx.lineTo(dataset.points[dataset.points.length-1].x, this.scale.endPoint);
|
||||
ctx.lineTo(this.scale.calculateX(0), 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(dataset.points,function(point){
|
||||
point.draw();
|
||||
});
|
||||
|
||||
},this);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}).call(this);
|
||||
248
src/Chart.PolarArea.js
Normal file
248
src/Chart.PolarArea.js
Normal file
@ -0,0 +1,248 @@
|
||||
(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.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);
|
||||
341
src/Chart.Radar.js
Normal file
341
src/Chart.Radar.js
Normal file
@ -0,0 +1,341 @@
|
||||
(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,
|
||||
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){
|
||||
//Best way to do this? or in draw sequence...?
|
||||
if (helpers.isNumber(dataPoint)){
|
||||
//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],
|
||||
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){
|
||||
if (helpers.isNumber(value)){
|
||||
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.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){
|
||||
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){
|
||||
point.draw();
|
||||
});
|
||||
|
||||
},this);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}).call(this);
|
||||
Loading…
x
Reference in New Issue
Block a user