Comments (2)
Great, thank you!
from vue3-chartjs.
Hi Alexander.
I have updated your example with some random colour updates on a button click.
Edit*: also just a note that this looks like its for package version 0.3.0 and ChartJS 2.9.4. This will not work for version 1.0 and ChartJS 3 since they have changed the structure of their options. If you decide to move to version 1, there is a similar example in the src/App.vue for this library. You can clone the repo, install the packages and run yarn dev to try them out.
<template>
<div style="height: 300px; width: 300px; border: 1px solid #000111">
<Vue3ChartJS
:id="lineChart.id"
ref="chartRef"
:type="lineChart.type"
:data="lineChart.data"
:options="lineChart.options"
/>
</div>
<button @click="update_Chart">Click Me</button>
</template>
<script>
import Vue3ChartJS from '@j-t-mcc/vue3-chartjs';
import { ref } from 'vue';
export default {
components: {
Vue3ChartJS,
},
setup() {
const chartRef = ref(null)
const new_number = ref(null);
const dataSet = [
{
data: [40, 20, 80, 10],
},
]
const lineChart = {
id: 'line-001',
type: 'line',
data: {
labels: ["Vue", "A", "B", "C"],
datasets: dataSet,
},
options: {
maintainAspectRatio: false,
responsive:true,
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: "Frequency (Hz)",
fontFamily: "Montserrat",
fontColor: "black",
},
ticks: {
fontColor: "green",
fontSize: 18,
stepSize: 1,
beginAtZero: true,
min: -10,
max: 120,
}
}],
xAxes: [{
ticks: {
fontColor: "purple",
fontSize: 14,
stepSize: 1,
beginAtZero: true
}
}]
}
}
}
const update_Chart= () => {
lineChart.data.labels.push("N");
lineChart.data.datasets[0].data.push(Math.random() * 100);
lineChart.data.datasets[0].backgroundColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
lineChart.data.datasets[0].borderColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
lineChart.options.scales.yAxes[0].ticks.fontColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
lineChart.options.scales.yAxes[0].scaleLabel.fontColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
lineChart.options.scales.xAxes[0].ticks.fontColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
lineChart.options.color = '#' + Math.floor(Math.random() * 16777215).toString(16);
chartRef.value.update(500);
}
return {
lineChart, new_number, update_Chart, chartRef
}
}
}
</script>
from vue3-chartjs.
Related Issues (18)
- Changing Font Family HOT 1
- TypeScript support HOT 6
- Cannot read property 'Chart' of undefined HOT 1
- How to set chart fixed height? HOT 6
- Tooltip options not working HOT 2
- Can not render horizontal bar chart HOT 1
- can't change chart type HOT 1
- Updating options does not have effect after update HOT 2
- Multiple chartRefs did not work
- Sandbox Examples Problem HOT 2
- Auto reset zoom after chart update
- [email protected] support HOT 1
- Really strange behavior with vue-cli HOT 1
- Chart.js v4 support
- Error: Maximum recursive updates exceeded - watch chart data from props and trigger chartRef.value.update() HOT 1
- How to change default aspect ratio of charts HOT 1
- Correct way to add plugins HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue3-chartjs.