score:5
Accepted answer
You can use props
.
NOTE - For reactivity problems you can see https://vue-chartjs.org/guide/#updating-charts
JS
import { Line, mixins } from 'vue-chartjs'
const { reactiveProp } = mixins
export default {
extends: Line,
mixins: [reactiveProp],
props: {
labels: Array,
datasets: Object
},
mounted () {
this.renderChart({
labels: this.labels,
datasets: this.datasets,
}, {responsive: true, maintainAspectRatio: false})
}
}
Component
<template>
<div class="Chart">
<h2>Linechart 1</h2>
<line-example :labels="labels" :datasets="datasets"></line-example>
<h2>Linechart 2</h2>
<line-example :labels="labels2" :datasets="datasets2"></line-example>
</div>
</template>
<script>
import LineExample from './LineChart.js'
export default {
name: 'tes',
components: {
LineExample
},
data () {
return {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
labels2: ['Foo', 'Bar'],
datasets: [
{
label: 'Data One',
backgroundColor: '#FC2525',
data: [40, 39, 10, 40, 39, 80, 40]
},{
label: 'Data Two',
backgroundColor: '#05CBE1',
data: [60, 55, 32, 10, 2, 12, 53]
}
],
datasets2: [
{
label: 'Data One',
backgroundColor: '#FC2525',
data: [1, 2]
},{
label: 'Data Two',
backgroundColor: '#05CBE1',
data: [3, 4]
}
]
}
}
}
</script>
Source: stackoverflow.com
Related Query
- how to create multiple chart on one component vue
- how can i use chart.js to create a chart that has one time series line and one linear line on it at the same time?
- How to make dynamic chart using Vue component with chart-js
- How to create multiple y-axis time series chart
- How can I create a bar chart that has multiple yAxes scales?
- how to not repeat code while creating multiple charts in chart js
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- How to create stacked bar chart using react-chartjs-2?
- How to display value of only one datapoint in line chart
- How to create a gradient fill line chart in latest Chart JS version (3.3.2)?
- How to create single value Doughnut or Pie chart using Chart.js?
- (Vue, ChartJS) Create gradient background for chart from child component canvas context
- Create multiple dynamic stacked chart using chart.js in Angular 10?
- How to create a gantt chart using Chart.js and populate dates?
- How to create chartjs chart with data from database C#
- How to create a chart that uses strings for both the X and Y axes?
- Chart is too big. How can I reduce size for the chart in vue js?
- How to create a variable for chart js datalabel plugin formatter
- How to create a pannable real-time chart
- How to create Bar chart that gets updated from new ajax requests with ChartJS?
- How do I create stacked chart with Chart.js version 2.0.0-beta
- How to draw multiple color bar in a bar chart using chart.js
- how to display multiple sum with chart js and laravel?
- How can I merge multiple HTTP calls to one entity model in Angular
- chart.js-plugin-annotations multiple horizontal lines in one chart
- How to reuse a Chartjs Chart component in with different Data and get past the **Canvas is already in use** error?
- How do I create a stacked horizontal bar chart with Chart.js in React?
- How to create Waterfall model chart using QuickChart?
- How to make bar chart cover multiple labels?
- How to create a line chart indicating which month a user wrote more or less blogs?
More Query from same tag
- Want to save chart.js charts to image using django cron job
- How can I add some text in the middle of a half doughnut chart in Chart.JS?
- Isn't draws vertical line on hover when I move cursor fast
- Multiple lines / data series from JSON file with Chart.js
- Uncaught Error: [$injector:modulerr] (Error came up when I included chart.js)
- How to show the data labels without hovering the mouse on the bubbles
- Dynamic js chart display problems
- ChartJS doughnut legend click
- how to dynamically render and update chart.js line graph
- Angular 9 - chartjs-plugin-annotation error
- ChartJs - Pie Chart - how to remove labels that are on the pie chart
- Chart JS Layered Vertical Bar Chart
- PHP restructure array of data
- Where is the documention for the chart.js Chart constructor?
- Update Chart JS with date range selector
- Javascript OnChange to update data
- How to connect a charts.js chart to data
- Is it possible to add image behind doughnut chart with transparency color in ng2chart?
- Execute onClick function on Custom Legend
- chart.js label and value overlap issue
- Remove only y-axis line from chat drawn using chart.js 1.0.2
- How to Draw Gantt chart using chart js or other libraries
- How can I change only a specific option in a chart with chart.js?
- VueJS + Chartjs - Chart only renders after code change
- How can I make lines fully connected in a multi-line chart even when one dataset is more sparse than another?
- Chart.js v2.0: Tooltip only for one dataset
- how to highlight the bars in stacked bar chart of chart.js on clicking a legend
- How to fix ERROR in node_modules/chart.js/types/animation.d.ts(20,37): error TS1005: ',' expected. in chart.js
- how to dynamicly change the json data in chartjs
- Angular 5 and chart.js ts error