0👍
At the moment of component creation, testData
is null and is immediately passed down to DoughnutChart
component as a prop, but DoughtnutChart
expects an object, not null, hence why you have an error.
You’re not setting the value of testData
until the OnMounted
hook, which if you’ve seen the Vue component lifecycle chart, happens some (short) time after component creation.
You either need to make sure testData
has a value at the time of component creation, or prevent the rendering of the DoughnutChart
component until testData
has a value:
<DoughnutChart v-if="testData" :chartData="testData" ref="doughnutRef" />
edit:
In addition, your testData
variable is not reactive so it’s value in the template will never actually update from being null
. You must assign it’s initial value using ref()
:
let testData = ref(null);
and update anywhere you use testData
in your <script>
to be testData.value
since it’s now a ref, namely the OnMounted hook:
onMounted(() => {
testData.value = {
labels: ['Female', 'Male'],
datasets: [
{
data: doughnutRef.value,
backgroundColor: ['#77CEFF', '#0079AF']
}
]
};
});
- Chartjs-How to force animation on chartjs?
- Chartjs-How do I make the legends tab focusable in a chart.js Line chart using React.js?
0👍
You need to define the default value of props as null. Because initially, it’s null. So the warning is showing.
- Chartjs-How can I represent data over timeslots in ChartJS?
- Chartjs-Looping through json array properties