livechart
livechart copied to clipboard
Scalable canvas chart for live data display
livechart
Canvas chart for display dynamic data with animatiion.
Features
-
Lightweight, < 12k when minified and gziped.
-
Scalable, the canvas element could adjust itself when the container resized
-
Easy configuation, using style and configurable.js for style and other option configuation.
-
Retina support
Installation
Install with component(1):
$ component install chemzqm/livechart
Or include file livechart.js and livechart.css on your web page and use global value livechart.
Example Usage
function random(i) {
var res = [];
while(i--) res.push(Math.random());
return res;
}
var PieChart = require('livechart').PieChart;
var parent = document.getElementById("piechart");
var chart = new PieChart(parent);
chart.set('labels', ['Free', 'Wired', 'Active', 'Inactive']);
setInterval(function(){
var values = random(4);
chart.add(values);
}, 1000);
API
Options
Options are configured by the set method, this method works like below:
chart.set({
min: 0,
max: 100
})
Or
chart.set('min', 0);
chart.set('max', 100);
colorsoptional color Array for each series.labelsoptinal label Array , lables are displayed on the left top corner (exceptBarchart).minoptinal min Number , chould be changed dynamicly when there's value lower.maxoptinal max Number , chould be changed dynamicly when there's value higher.countmax count Number, only used forLineChart,AreaChartandHistogram.formatformat Function should return formatted value with orignal value as argument, used forLineChart,AreaChart,BarChartandArcChart.titletitle String , currently only used forBarChart.easeease function for animatiion, defaultin-out-quad.durationduration Number in milisecond for animatiion, default500.
LineChart(parentNode)
Append LineChart to parentNode, LineChart accept one or two series.
LineChart#add(Number|Array)
Add one value or two values to LineChart.
AreaChart(parentNode)
Append AreaChart to parentNode, AreaChart accept one or two series.
AreaChart#add(Number|Array)
Add one value or two values to AreaChart.
Histogram(parentNode)
Append Histogram to parentNode.
Histogram#add(Number)
Add one value for histogram.
PieChart(parentNode)
Append PieChart to parentNode.
PieChart#add(Array)
Change values for PieChart.
ArcChart(parentNode)
Append ArcChart to parentNode, ArcChart accept one or two series.
ArcChart#add(Array)
Change values for ArcChart.
PolarChart(parentNode)
Append PolarChart to parentNode.
PolarChart#add(Array)
Change values for PolarChart.
License
MIT