Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/.vuepress/public/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<div>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you adding these files in the public folder of vuepress?

Same goes for all the files and folders you added in the usage folder.

I think its better to just integrete these kind of examples in the docs pages itself (md files) and use place a chart chart custom chart undeaneath it with that config.

Maby we can look into the plugin to add them so we can disable the user input so the user only sees the chart

Copy link
Member Author

@igorlukanin igorlukanin Oct 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeeLenaleee Cool question! So, these public files represent self-contained, pre-built Chart.js examples that I embed into the step-by-step guide. If you'd like to, consider running pnpm docs:dev and checking out http://localhost:8080/docs/master/getting-started/; you might enjoy it 😄

Some of these examples rely on an external dependency to fetch substantially sized "real-world data," and embedding the library in the docs would be unreasonable. I've explored embedding the datasets directly, but they are dozens of KBs, so it's also not an option.

Maby we can look into the plugin to add them so we can disable the user input, so the user only sees the chart

Yep, it's a viable option for the file you're commenting (demo.html). I've submitted a PR to vuepress-theme-chartjs that would allow that: simonbrunel/vuepress-theme-chartjs#4

I think its better to just integrete these kind of examples in the docs pages itself (md files)

Right. With the PR above, that one can be replaced with something like this:

```js chart-editor
const data = [
  { year: 2010, count: 10 },
  { year: 2011, count: 20 },
  { year: 2012, count: 15 },
  { year: 2013, count: 25 },
  { year: 2014, count: 22 },
  { year: 2015, count: 30 },
  { year: 2016, count: 28 },
];

module.exports = {
  config: {
    type: 'bar',
    data: {
      labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
      datasets: [{
        label: '# of Votes',
        data: [12, 19, 3, 5, 2, 3],
        borderWidth: 1
      }]
    },
    options: {
      scales: {
        y: {
          beginAtZero: true
        }
      }
    }
  },
  chartOnly: true
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait for @simonbrunel to merge the PR to vuepress-theme-chartjs. Alternatively, I can submit a follow-up PR later after the theme is updated so this one is not blocked.

Copy link
Collaborator

@LeeLenaleee LeeLenaleee Oct 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I appreciate the work I am against merging this for the following reasons:

  1. I find it a security risk, those js files are big and hard to read so difficult to know if you putted something in there that's not supposed to be there.

  2. Its a maintenance burden to update them Everytime something in the codebase has changed

  3. Sample in the docs should be minimalistic in my eyes and not rely on external data which can change or go down. If we want an example with loads of data we should add it in the samples section with generated data.

So instead of embedding these kind of charts, just show simple charts and in the way we do it elsware in the docs with Simons plugin

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fully agree with @LeeLenaleee, especially on the maintenance part. There should be no pre-built files in the repository. I'm not even sure how the usage/* files are supposed to be generated? where are the sources? IMO, embedding complex examples in the docs should go through some services like CodePen or alternatives, so users have access to the entire source code.

But as a getting started, I would indeed expect something minimalistic as mentioned by @LeeLenaleee.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LeeLenaleee @simonbrunel This is excellent feedback; thanks! Honestly, I dislike the current state of things just like you do. It was an attempt to have interactive charts rather than images, but it looks ugly now. Let me roll this PR back to just images and remove all the bloat.

@simonbrunel has a great point on CodePen/CodeSandbox/etc. However, they would still be external to docs and could potentially break, so let's skip that options for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rolled back to images. (No new files under .vuepress anymore.) IMO, much better now. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Images make sense to me. A CodePen or similar could work, but the maintenance burden is there. Maybe there are ways we could automatically update the codepen during deploys?

<canvas id="myChart"></canvas>
</div>

<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>

<script>
const ctx = document.getElementById('myChart');

new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
</script>
14 changes: 14 additions & 0 deletions docs/.vuepress/public/usage/1/index.2979bcd3.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/1/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><title>Chart.js example</title></head><body> <div style="width:800px"><canvas id="acquisitions"></canvas></div> <script type="module" src="index.2979bcd3.js"></script> </body></html>
13 changes: 13 additions & 0 deletions docs/.vuepress/public/usage/2/index.1de0334e.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><title>Chart.js example</title></head><body> <div style="width:800px"><canvas id="acquisitions"></canvas></div> <script type="module" src="index.1de0334e.js"></script> </body></html>
22 changes: 22 additions & 0 deletions docs/.vuepress/public/usage/3/index.1b874a14.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/3/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><title>Chart.js example</title></head><body> <div style="width:800px"><canvas id="acquisitions"></canvas></div> <script type="module" src="index.1b874a14.js"></script> </body></html>
1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/4/index.1fa2e270.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions docs/.vuepress/public/usage/4/index.b26b1a85.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/4/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><title>Chart.js example</title></head><body> <div style="width:500px"><canvas id="dimensions"></canvas></div><br> <div style="width:800px"><canvas id="acquisitions"></canvas></div> <script type="module" src="index.b26b1a85.js"></script> <script type="module" src="index.1fa2e270.js"></script> </body></html>
1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/5/index.1fa2e270.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions docs/.vuepress/public/usage/5/index.c2f80a4d.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/5/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><title>Chart.js example</title></head><body> <div style="width:500px"><canvas id="dimensions"></canvas></div><br> <div style="width:800px"><canvas id="acquisitions"></canvas></div> <script type="module" src="index.c2f80a4d.js"></script> <script type="module" src="index.1fa2e270.js"></script> </body></html>
1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/6/index.1fa2e270.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions docs/.vuepress/public/usage/6/index.a51116fb.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/6/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><title>Chart.js example</title></head><body> <div style="width:500px"><canvas id="dimensions"></canvas></div><br> <div style="width:800px"><canvas id="acquisitions"></canvas></div> <script type="module" src="index.a51116fb.js"></script> <script type="module" src="index.1fa2e270.js"></script> </body></html>
1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/7/index.1fa2e270.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions docs/.vuepress/public/usage/7/index.65688088.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/7/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><title>Chart.js example</title></head><body> <div style="width:500px"><canvas id="dimensions"></canvas></div><br> <div style="width:800px"><canvas id="acquisitions"></canvas></div> <script type="module" src="index.65688088.js"></script> <script type="module" src="index.1fa2e270.js"></script> </body></html>
1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/8/index.1fa2e270.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions docs/.vuepress/public/usage/8/index.4f16a936.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/8/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><title>Chart.js example</title></head><body> <div style="width:500px"><canvas id="dimensions"></canvas></div><br> <div style="width:800px"><canvas id="acquisitions"></canvas></div> <script type="module" src="index.4f16a936.js"></script> <script type="module" src="index.1fa2e270.js"></script> </body></html>
1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/9/index.1fa2e270.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions docs/.vuepress/public/usage/9/index.8aa3ce5e.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/.vuepress/public/usage/9/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><title>Chart.js example</title></head><body> <div style="width:500px"><canvas id="dimensions"></canvas></div><br> <div style="width:800px"><canvas id="acquisitions"></canvas></div> <script type="module" src="index.8aa3ce5e.js"></script> <script type="module" src="index.1fa2e270.js"></script> </body></html>
14 changes: 9 additions & 5 deletions docs/developers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ Latest builds are available for testing at:
- <https://www.chartjs.org/dist/master/chart.js>
- <https://www.chartjs.org/dist/master/chart.min.js>

**WARNING: Development builds MUST not be used for production purposes or as replacement for CDN.**
:::warning Warning

Development builds **must not** be used for production purposes or as replacement for a CDN. See [available CDNs](../getting-started/installation.html#cdn).

:::

## Browser support

All modern and up-to-date browsers are supported, including, but not limited to:

Chrome
Edge
Firefox
Safari
* Chrome
* Edge
* Firefox
* Safari

As of version 3, we have dropped Internet Explorer 11 support.

Expand Down
151 changes: 69 additions & 82 deletions docs/getting-started/index.md
Original file line number Diff line number Diff line change
@@ -1,106 +1,93 @@
# Getting Started

Let's get started using Chart.js!
Let's get started with Chart.js!

First, we need to have a canvas in our page. It's recommended to give the chart its own container for [responsiveness](../configuration/responsive.md).
* **[Follow a step-by-step guide](./usage) to get up to speed with Chart.js**
* [Install Chart.js](./installation) from npm or a CDN
* [Integrate Chart.js](./integration) with bundlers, loaders, and front-end frameworks

Alternatively, see the example below or check [samples](../samples).

## Create a Chart

In this example, we create a bar chart for a single dataset and render it on an HTML page. Add this code snippet to your page:

```html
<div>
<canvas id="myChart"></canvas>
</div>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>

<script>
const ctx = document.getElementById('myChart');

new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
</script>
```

Now that we have a canvas we can use, we need to include Chart.js in our page.
You should get a chart like this:

<iframe src="../demo.html" frameBorder="0" scrolling="no" width="825" height="400"></iframe>

Let's break this code down.

First, we need to have a canvas in our page. It's recommended to give the chart its own container for [responsiveness](../configuration/responsive.md).

```html
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<div>
<canvas id="myChart"></canvas>
</div>
```

Now, we can create a chart. We add a script to our page:
Now that we have a canvas, we can include Chart.js from a CDN.

```html
<script>
const labels = [
'January',
'February',
'March',
'April',
'May',
'June',
];

const data = {
labels: labels,
datasets: [{
label: 'My First dataset',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: [0, 10, 5, 2, 20, 30, 45],
}]
};

const config = {
type: 'line',
data: data,
options: {}
};
</script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
```

Finally, render the chart using our configuration:
Finally, we can create a chart. We add a script that acquires the `myChart` canvas element and instantiates `new Chart` with desired configuration: `bar` chart type, labels, data points, and options.

```html
<script>
const myChart = new Chart(
document.getElementById('myChart'),
config
);
const ctx = document.getElementById('myChart');

new Chart(ctx, {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderWidth: 1
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});
</script>
```

It's that easy to get started using Chart.js! From here you can explore the many options that can help you customise your charts with scales, tooltips, labels, colors, custom actions, and much more.

Here the sample above is presented with our sample block:

```js chart-editor
// <block:setup:1>
const labels = [
'January',
'February',
'March',
'April',
'May',
'June',
];
const data = {
labels: labels,
datasets: [{
label: 'My First dataset',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: [0, 10, 5, 2, 20, 30, 45],
}]
};
// </block:setup>

// <block:config:0>
const config = {
type: 'line',
data: data,
options: {}
};
// </block:config>

module.exports = {
actions: [],
config: config,
};
```

:::tip Note
As you can see, some of the boilerplate needed is not visible in our sample blocks, as the samples focus on the configuration options.
:::

All our examples are [available online](../samples/).

To run the samples locally you first have to install all the necessary packages using the `npm ci` command, after this you can run `npm run docs:dev` to build the documentation. As soon as the build is done, you can go to [http://localhost:8080/samples/](http://localhost:8080/samples/) to see the samples.
You can see all the ways to use Chart.js in the [step-by-step guide](./usage).
6 changes: 2 additions & 4 deletions docs/getting-started/installation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
title: Installation
---
# Installation

## npm

Expand Down Expand Up @@ -29,7 +27,7 @@ Chart.js built files are also available through [jsDelivr](https://www.jsdelivr.

<https://www.jsdelivr.com/package/npm/chart.js?path=dist>

## Github
## GitHub

[![github](https://img.shields.io/github/release/chartjs/Chart.js.svg?style=flat-square&maxAge=600)](https://github.com/chartjs/Chart.js/releases/latest)

Expand Down
9 changes: 7 additions & 2 deletions docs/getting-started/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Chart.js can be integrated with plain JavaScript or with different module loaders. The examples below show how to load Chart.js in different systems.

If you're using a front-end framework (e.g., React, Angular, or Vue), please see [available integrations](https://github.com/chartjs/awesome#integrations).

## Script Tag

```html
Expand Down Expand Up @@ -118,7 +120,7 @@ Because Chart.js is an ESM library, in CommonJS modules you should use a dynamic
const { Chart } = await import('chart.js');
```

## Require JS
## RequireJS

**Important:** RequireJS can load only [AMD modules](https://requirejs.org/docs/whyamd.html), so be sure to require one of the UMD builds instead (i.e. `dist/chart.umd.js`).

Expand All @@ -128,7 +130,9 @@ require(['path/to/chartjs/dist/chart.umd.js'], function(Chart){
});
```

**Note:** in order to use the time scale, you need to make sure [one of the available date adapters](https://github.com/chartjs/awesome#adapters) and corresponding date library are fully loaded **after** requiring Chart.js. For this you can use nested requires:
:::tip Note

In order to use the time scale, you need to make sure [one of the available date adapters](https://github.com/chartjs/awesome#adapters) and corresponding date library are fully loaded **after** requiring Chart.js. For this you can use nested requires:

```javascript
require(['chartjs'], function(Chart) {
Expand All @@ -139,3 +143,4 @@ require(['chartjs'], function(Chart) {
});
});
```
:::
Loading