I am currently utilizing the PrimeVue chart component, which is built on top of ChartJS.
The configuration is very similar.
The documentation indicates that I need to instantiate a new Chart() and then call toBase64Image();
https://i.sstatic.net/NMHjV.png
My main query is, how do I access the Chart constructor?
<script lang="ts" setup>
import Chart from 'primevue/chart';
import ChartDataLabels from 'chartjs-plugin-datalabels';
import { ref } from 'vue';
import { ChartData } from 'chart.js';
const props = defineProps<{
data?: ChartData;
aspectRatio?: number;
title?: string;
printWidth?: number;
printHeight?: number;
}>();
const options = ref({
plugins: {
datalabels: {
labels: {
title: {
color: 'black',
},
},
align: 'end',
anchor: 'start',
offset: 1,
formatter
}
},
aspectRatio: props.aspectRatio
animation: {
onComplete: () => {
// How can I access the Chart constructor in this context?
var base64Chart = Chart.toBase64Image();
}
}
});
</script>
<template>
<section class="config-asset-chart">
<span>{{title}}</span>
<Chart
class="px-2"
:data="data"
:width="props.printWidth"
:height="props.printHeight"
:options="options"
:plugins="[ChartDataLabels]"
/>
</section>
</template>