0
 "vue": "^3.2.37",
 "vue-chartjs": "^4.1.2",

Using this code I would like download the chart as base64 image, but I cannot find the instance of chartJs, to invoke toBase64Image() method.

Any help please ? Thanks

<script setup lang="ts">
import { Line } from 'vue-chartjs'
import { Chart as ChartJS, Title, Tooltip, Legend, BarElement, CategoryScale, LinearScale, ChartData, ChartOptions } from 'chart.js'
ChartJS.register(Title, Tooltip, Legend, BarElement, CategoryScale, LinearScale)
const lineChartRef = ref()
const exportChart = () => {
  console.log(lineChartRef.value.chartInstance)
  lineChartRef.value.chartInstance.toBase64Image()
}
...
<template>
  <n-card :bordered="true" class="shadow-sm rounded-xl">
    <button type="submit" @click="exportChart">Export Chart as PNG</button>
    <Line ref="lineChartRef" chart-id="lineChart" :chart-data="props.chartData" :chart-options="props.chartOptions" :height="250" />
  </n-card>
</template>

0 Answers0