Skip to content

Commit 63e60e6

Browse files
authored
Move readme example from codepen to docs (#436)
1 parent 550cf4a commit 63e60e6

File tree

4 files changed

+109
-2
lines changed

4 files changed

+109
-2
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ This plugin draws lines, boxes, points and ellipses on the chart area.
1919

2020
Annotations work with line, bar, scatter and bubble charts that use linear, logarithmic, time, or category scales. Annotations will not work on any chart that does not have exactly two axes, including pie, radar, and polar area charts.
2121

22-
![Example Screenshot from Dropbox](https://www.dropbox.com/s/92cmt8zrth55z55/Screenshot%202017-05-20%2018.26.39.png?raw=1)
22+
![Example Screenshot](docs/guide/banner.png)
2323

24-
[View this example on CodePen](https://codepen.io/compwright/full/mmQMrZ/)
24+
[View this example](https://chartjs.org/chartjs-plugin-annotation/samples/intro.html)
2525

2626
## To-do Items
2727

docs/.vuepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ module.exports = {
5353
}
5454
],
5555
'/samples/': [
56+
'intro',
5657
{
5758
title: 'Types',
5859
collapsable: false,

docs/samples/.eslintrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rules:
2+
no-console: "off"

docs/samples/intro.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Intro
2+
3+
```js chart-editor
4+
// <block:setup:4>
5+
Utils.srand(8);
6+
7+
const data = {
8+
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
9+
datasets: [{
10+
type: 'line',
11+
label: 'Dataset 1',
12+
borderColor: 'rgb(54, 162, 235)',
13+
borderWidth: 2,
14+
fill: false,
15+
data: Utils.numbers({count: 7, min: -100, max: 100}),
16+
}, {
17+
type: 'bar',
18+
label: 'Dataset 2',
19+
backgroundColor: 'rgb(255, 99, 132)',
20+
data: Utils.numbers({count: 7, min: -100, max: 100}),
21+
borderColor: 'white',
22+
borderWidth: 2
23+
}, {
24+
type: 'bar',
25+
label: 'Dataset 3',
26+
backgroundColor: 'rgb(75, 192, 192)',
27+
data: Utils.numbers({count: 7, min: -100, max: 100}),
28+
}]
29+
};
30+
// </block:setup>
31+
32+
// <block:annotation1:1>
33+
const annotation1 = {
34+
type: 'line',
35+
scaleID: 'y',
36+
value: Utils.rand(-100, 100),
37+
borderColor: 'black',
38+
borderWidth: 5,
39+
label: {
40+
backgroundColor: 'red',
41+
content: 'Test Label',
42+
enabled: true
43+
},
44+
click: function({chart, element}) {
45+
console.log('Line annotation clicked');
46+
}
47+
};
48+
// </block:annotation1>
49+
50+
// <block:annotation2:2>
51+
const annotation2 = {
52+
drawTime: 'beforeDatasetsDraw',
53+
type: 'box',
54+
xScaleID: 'x',
55+
yScaleID: 'y',
56+
xMin: 'February',
57+
xMax: 'April',
58+
yMin: Utils.rand(-100, 100),
59+
yMax: Utils.rand(-100, 100),
60+
backgroundColor: 'rgba(101, 33, 171, 0.5)',
61+
borderColor: 'rgb(101, 33, 171)',
62+
borderWidth: 1,
63+
click: function({chart, element}) {
64+
console.log('Box annotation clicked');
65+
}
66+
};
67+
// </block:annotation2>
68+
69+
/* <block:config:0> */
70+
const config = {
71+
type: 'line',
72+
data,
73+
options: {
74+
plugins: {
75+
annotation: {
76+
annotations: {
77+
annotation1,
78+
annotation2
79+
}
80+
}
81+
},
82+
}
83+
};
84+
/* </block:config> */
85+
86+
var actions = [
87+
{
88+
name: 'Randomize',
89+
handler: function(chart) {
90+
chart.data.datasets.forEach(function(dataset, i) {
91+
dataset.data = Utils.numbers({count: 7, min: -100, max: 100});
92+
});
93+
94+
chart.update();
95+
}
96+
},
97+
];
98+
99+
module.exports = {
100+
actions: actions,
101+
config: config,
102+
output: 'console.log output is shown here, click one of the annotations'
103+
};
104+
```

0 commit comments

Comments
 (0)