Showing posts with label Chart. Show all posts
Showing posts with label Chart. Show all posts

How to create a simple JavaScript chart in html5 canvas?

Here we are creating a simple JavaScript line chart in html5 canvas by using chart.js. In this chart required X & Y axis data. Here we are using some sample data. You can replace with your own data.

You can download the latest version of Chart.js from the GitHub releases or use a Chart.js CDN.

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js"></script>
Add a '<canvas>' element to your html page.

<canvas id="myChart" width="400" height="400"></canvas>
After that we should use the chart api.

The final code & demo is here


Demo

How to create a simple JavaScript chart in div?

Here we are creating a simple JavaScript line chart in div using chart.js. In this chart required X & Y axis data. Here we are using some sample data. You can replace with your own data.

1) You can download the latest version of Chart.js from the GitHub releases or use a Chart.js CDN.

<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js"></script>
Add a '<div>' element to your html page.

<div class="Chart">
After that we should use the chart api.

The final code & demo is here


Demo