mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-20 12:00:53 +08:00
117 lines
3.1 KiB
TypeScript
117 lines
3.1 KiB
TypeScript
///<reference path="chartist.d.ts" />
|
|
|
|
new Chartist.Line('.ct-chart', {
|
|
labels: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
|
|
series: [
|
|
[12, 9, 7, 8, 5],
|
|
[2, 1, 3.5, 7, 3],
|
|
[1, 3, 4, 5, 6]
|
|
]
|
|
}, {
|
|
fullWidth: true,
|
|
chartPadding: {
|
|
right: 40
|
|
}
|
|
});
|
|
|
|
var lineChart = new Chartist.Line('.ct-chart', {
|
|
labels: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
|
series: [
|
|
[5, 5, 10, 8, 7, 5, 4, null, null, null, 10, 10, 7, 8, 6, 9],
|
|
[10, 15, null, 12, null, 10, 12, 15, null, null, 12, null, 14, null, null, null],
|
|
[null, null, null, null, 3, 4, 1, 3, 4, 6, 7, 9, 5, null, null, null]
|
|
]
|
|
}, {
|
|
fullWidth: true,
|
|
chartPadding: {
|
|
right: 10
|
|
},
|
|
low: 0
|
|
});
|
|
|
|
new Chartist.Line('.ct-chart', {
|
|
labels: ['1', '2', '3', '4', '5', '6'],
|
|
series: [
|
|
{
|
|
name: 'Fibonacci sequence',
|
|
data: [1, 2, 3, 5, 8, 13]
|
|
},
|
|
{
|
|
name: 'Golden section',
|
|
data: [1, 1.618, 2.618, 4.236, 6.854, 11.09]
|
|
}
|
|
]
|
|
});
|
|
|
|
var data = {
|
|
series: [5, 3, 4]
|
|
};
|
|
|
|
var sum = function(a: number, b: number) { return a + b };
|
|
|
|
new Chartist.Pie('.ct-chart', data, {
|
|
labelInterpolationFnc: function(value: number) {
|
|
return Math.round(value / data.series.reduce(sum) * 100) + '%';
|
|
}
|
|
});
|
|
|
|
new Chartist.Pie('.ct-chart', {
|
|
series: [20, 10, 30, 40]
|
|
}, {
|
|
donut: true,
|
|
donutWidth: 60,
|
|
startAngle: 270,
|
|
total: 200,
|
|
showLabel: false
|
|
});
|
|
|
|
|
|
// Animation Donut example
|
|
|
|
var chart = new Chartist.Pie('.ct-chart', {
|
|
series: [10, 20, 50, 20, 5, 50, 15],
|
|
labels: [1, 2, 3, 4, 5, 6, 7]
|
|
}, {
|
|
donut: true,
|
|
showLabel: false
|
|
});
|
|
|
|
chart.on('draw', function(data: any) {
|
|
if(data.type === 'slice') {
|
|
// Get the total path length in order to use for dash array animation
|
|
var pathLength = data.element._node.getTotalLength();
|
|
|
|
// Set a dasharray that matches the path length as prerequisite to animate dashoffset
|
|
data.element.attr({
|
|
'stroke-dasharray': pathLength + 'px ' + pathLength + 'px'
|
|
});
|
|
|
|
// Create animation definition while also assigning an ID to the animation for later sync usage
|
|
var animationDefinition: any = {
|
|
'stroke-dashoffset': {
|
|
id: 'anim' + data.index,
|
|
dur: 1000,
|
|
from: -pathLength + 'px',
|
|
to: '0px',
|
|
easing: Chartist.Svg.Easing.easeOutQuint,
|
|
// We need to use `fill: 'freeze'` otherwise our animation will fall back to initial (not visible)
|
|
fill: 'freeze'
|
|
}
|
|
};
|
|
|
|
// If this was not the first slice, we need to time the animation so that it uses the end sync event of the previous animation
|
|
if(data.index !== 0) {
|
|
animationDefinition['stroke-dashoffset'].begin = 'anim' + (data.index - 1) + '.end';
|
|
}
|
|
|
|
// We need to set an initial value before the animation starts as we are not in guided mode which would do that for us
|
|
data.element.attr({
|
|
'stroke-dashoffset': -pathLength + 'px'
|
|
});
|
|
|
|
// We can't use guided mode as the animations need to rely on setting begin manually
|
|
// See http://gionkunz.github.io/chartist-js/api-documentation.html#chartistsvg-function-animate
|
|
data.element.animate(animationDefinition, false);
|
|
}
|
|
});
|