Chart.js/docs/getting-started
Simon Brunel 55128f74c1 Move CSS in a separate file to be CSP-compliant (#6048)
In order to be compatible with any CSP, we need to prevent the automatic creation of the DOM 'style' element and offer our CSS as a separate file that can be manually loaded (`Chart.js` or `Chart.min.js`). Users can now opt-out the style injection using `Chart.platform.disableCSSInjection = true` (note that the style sheet is now injected on the first chart creation).

To prevent duplicating and maintaining the same CSS code at different places, move all these rules in `platform.dom.css` and write a minimal rollup plugin to inject that style as string in `platform.dom.js`. Additionally, this plugin extract the imported style in `./dist/Chart.js` and `./dist/Chart.min.js`.
2019-02-08 19:06:04 +01:00
..
installation.md Fix duplicate anchor (#6038) 2019-02-04 20:00:44 -05:00
integration.md Move CSS in a separate file to be CSP-compliant (#6048) 2019-02-08 19:06:04 +01:00
README.md Fix typos and make the docs consistent (#6020) 2019-01-29 13:34:16 +01:00
usage.md Fix typos and make the docs consistent (#6020) 2019-01-29 13:34:16 +01:00

Getting Started

Let's get started using Chart.js!

First, we need to have a canvas in our page.

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

Now that we have a canvas we can use, we need to include Chart.js in our page.

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js"></script>

Now, we can create a chart. We add a script to our page:

var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
    // The type of chart we want to create
    type: 'line',

    // The data for our dataset
    data: {
        labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
        datasets: [{
            label: 'My First dataset',
            backgroundColor: 'rgb(255, 99, 132)',
            borderColor: 'rgb(255, 99, 132)',
            data: [0, 10, 5, 2, 20, 30, 45]
        }]
    },

    // Configuration options go here
    options: {}
});

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.

All our examples are available online but you can also download the Chart.js.zip archive attached to every release to experiment with our samples locally from the /samples folder.