score:0
Have you checked out the examples in the docs? https://vue-chartjs.org/guide/#chart-with-api-data
Your problem is, that your data api call is async. So your chart is rendered, even if your data is not fully loaded.
There is also an example with vuex which is a bit outdated https://github.com/apertureless/vue-chartjs-vuex
You have to make sure that your data is fully loaded before you render your chart.
score:0
I faced similar issue while implementing Charts with API data in one of my Vue JS apps I was working on. I am using Vuex for state management, a simple solution for this problem is to move "chartData" from "data" to "computed" which would make it reactive. Below is the sample code from my app.
<template>
<line-chart v-if="chartData"
style="height: 100%"
chart-id="big-line-chart"
:chart-data="chartData"
:extra-options="extraOptions"
>
</line-chart>
</template>
<script>
import { mapActions, mapGetters } from 'vuex';
import * as expenseTypes from '../../store/modules/expense/expense-types';
import * as chartConfig from "../../components/reports/chart.config";
import BarChart from "../../components/reports/BarChart";
export default {
components: {
BarChart,
},
data () {
return {
extraOptions: chartConfig.chartOptionsMain
}
},
computed: {
...mapGetters({
allExpenses: expenseTypes.GET_ALL_EXPENSES,
expenseCount: expenseTypes.GET_EXPENSE_COUNT,
}),
expenseAmount() {
let expenseAmount = [];
this.allExpenses.map((item) => {
expenseAmount.push(item.amount);
})
return expenseAmount;
},
expenseLabels() {
let expenseLabels = [];
this.allExpenses.map((item) => {
expenseLabels.push(item.note);
})
return expenseLabels;
},
chartData() {
return {
datasets: [
{
data: this.expenseAmount
},
],
labels: this.expenseLabels
}
}
},
async mounted() {
await this.getAllExpenses();
await this.fillChartData();
},
methods: {
...mapActions({
getAllExpenses: expenseTypes.GET_ALL_EXPENSES_ACTION,
}),
},
};
</script>
Source: stackoverflow.com
Related Query
- How To Use Api Data With Vue Chart.js
- How to use JSON data in creating a chart with chartjs?
- How to use computed property with data from JSON in data object for time axis in Vue using Chart.js
- How to fill my chart (chart.js) with my own data from API
- How to display data labels outside in pie chart with lines in ionic
- How to use 'time' (data from database, data type: timestamp ) for plotting graph in Chart JS
- Using data from API with Chart JS
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- Angular chart how to show the legend data value by default along with legend name
- How to create chartjs chart with data from database C#
- How do I use my chart.js line chart with handlebars?
- How to get chart from data points (arrays) with inconsistent time intervals and chart.js?
- How to use async data for use with chart.js in ionic
- Angular 2: How to pass my API data to graph and Display the Graph with data
- How to display chart using Chartjs with JSON data in Laravel
- Initialize a Chart.js chart with data from an api
- How to make dynamic chart using Vue component with chart-js
- How to reuse a Chartjs Chart component in with different Data and get past the **Canvas is already in use** error?
- How to get Data from API to display chart using chartjs in Vuejs
- How to create a chart with chartjs.org with data from an array?
- The chart doesn't display the data from my call to the API with Axios
- How to split data from api to get a chart
- How to use chart.js to plot line chart with x axis as time stamp in seconds
- How to use Axios API with Chart.js and React.js
- how to write labels along with data on top and bottom of each stack in bar chart
- How write the labels of the data inside a Doughnut Chart made with Chart.js?
- How to load new chart (chartsjs) from api call with jquery?
- React: How to get loading spinner to show whilst API data loads into my chart.js chart
- How to dynamically update data of line chart used with chart Js?
- How to get data on chart based on selected date (Filtering data Chart JS with datepicker)
More Query from same tag
- Chart.js bezier curve discontinuity
- How to change HTML style in ChartOption with if condition?
- Chartjs equidistance between X values
- How I can prevent of labels overlapping on mobile screen Chart.js
- Chartjs + DataLabelPlugin: Suddenly data labels are shown in every chart even without the plugin?
- Using data saved as a variable in HTML from Python
- Change color of measure unit with Chart.js
- Using public data for dynamic data
- Chart.js Bar Chart change width (not duplicated to bar width questions!)
- How to show bar labels in legend in Chart.js 2.1.6?
- How can I query data from my Cosmos DB in Angular 7?
- Adding model data to Charts.js in Rails
- How to add custom tooltips to only one label in Chart.js?
- How do I change the colour of a Chart.js line when drawn above/below an arbitary value?
- Chart JS stacked labels instead of making them horizontal
- Is there any way to change the font size of labels in bar chart in Chart.js v3?
- Chart.js: How to set the height of the rows manually
- Relative bar chart overlay on line chart in chart.js
- Adding custom text to Bar Chart label values using Chart.js
- angular-chart.js custom color based on chart label values
- How to hide Chart.js legend in Vue?
- Two pie charts in one flexbox container
- Chartjs - How to get last 7 days on x-axis labels?
- Chart won't draw. Returning a string value not a Number value - Meteor - Chartjs
- chart js bar chart add animation to change color
- Display JSON data in react-chartjs-2
- How to cut line graph in ChartJS
- Canvas is already in use. Chart with ID '0' must be destroyed before the canvas can be reused. chat.JS
- Angular Chart Js legends click event not working
- How to parse time 'HH:MM:SS' and display steps on xAxis every minute in Chart.js