How to install and use Chart.js in Vue.js 3

How to install and use Chart.js in Vue.js 3

Simon Suh

2 года назад

32,530 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Lucas Saliés Brum
Lucas Saliés Brum - 16.12.2022 03:14

Anyway to use with setup script?

Ответить
muenzi01
muenzi01 - 01.12.2022 18:01

thank you very much

Ответить
Sacha Wicky
Sacha Wicky - 26.10.2022 15:34

Thank you, you literary saved me for my assignment

Ответить
Mahbubur Rahman
Mahbubur Rahman - 16.07.2022 20:36

Any idea how to use the onClick callback to find which point was clicked upon on the chart. I am using <script setup>. onClick only returns the actual x and y value of the canvas but not the data point

Ответить
VISHAL SHRIVASTAV
VISHAL SHRIVASTAV - 16.06.2022 13:37

great work sir . I loved you video

Ответить
NASAOrbit
NASAOrbit - 08.06.2022 20:36

HI @simon Suh,

I am geting an error when I am using composition Api using Vue 3.

TypeError: Cannot read properties of null (reading 'getContext')

<script setup>
import { onMounted } from "vue";
import Chart from "chart.js/auto";
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
onMounted(() => {
const 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],
backgroundColor: [
"rgba(255, 99, 132, 0.2)",
"rgba(54, 162, 235, 0.2)",
"rgba(255, 206, 86, 0.2)",
"rgba(75, 192, 192, 0.2)",
"rgba(153, 102, 255, 0.2)",
"rgba(255, 159, 64, 0.2)",
],
borderColor: [
"rgba(255, 99, 132, 1)",
"rgba(54, 162, 235, 1)",
"rgba(255, 206, 86, 1)",
"rgba(75, 192, 192, 1)",
"rgba(153, 102, 255, 1)",
"rgba(255, 159, 64, 1)",
],
borderWidth: 1,
},
],
},
options: {
scales: {
y: {
beginAtZero: true,
},
},
},
});
myChart;
});
</script>
<template>
<canvas id="myChart" width="400" height="400"></canvas>
</template>

Ответить
Guest Ofallah
Guest Ofallah - 07.05.2022 13:47

Dude u was struggling for hours to make it work with vue , thank you !

Ответить
Amir Torabi
Amir Torabi - 20.04.2022 11:27

It should be amazing if a full video about chart js create

Ответить
Animaline
Animaline - 06.04.2022 20:14

Hey SImon, could you show us how to do this but while using an API we created?

Ответить
Cheikh Mohamed
Cheikh Mohamed - 05.04.2022 21:09

Great content !
I subscribed

Ответить