0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

vue3 sfc vue-chartjs

Posted at

https://www.chartjs.org/
https://vue-chartjs.org/

"chart.js": "3.9.1",
"vue": "3.2.36",
"vue-chartjs": "4.1.2"

<script setup>
import {Bar, Pie} from 'vue-chartjs'
import {Chart as ChartJS, Title, Tooltip, Legend, BarElement, CategoryScale, LinearScale, ArcElement} from 'chart.js'

ChartJS.register(Title, Tooltip, Legend, BarElement, CategoryScale, LinearScale, ArcElement);

const chartOptions1 = {responsive: true};
const chartData1 = {
    labels: ['1月', '2月', '3月'],
    datasets: [
        {
            label: '2021年',
            backgroundColor: ['#f7fcf0', '#e0f3db', '#ccebc5'],
            data: [30, 20, 12]
        },
        {
            label: '2022年',
            backgroundColor: ['#f7fcf0', '#e0f3db', '#ccebc5'],
            data: [10, 25, 22]
        }

    ]
};
const chartId1 = 'bar-chart';

const chartOptions2 = {responsive: true, maintainAspectRatio: false}
const chartData2 = {
    labels: ['その1', 'その2', 'その3', 'その4'],
    datasets: [
        {
            backgroundColor: ['#f7fcf0', '#e0f3db', '#ccebc5', '#a8ddb5', '#7bccc4'],
            data: [40, 20, 80, 10]
        }
    ]
}
const chartId2 = 'pie-chart';

const width = 400;
const height = 400;
</script>

<template>
    <Bar
        :chart-options="chartOptions1"
        :chart-data="chartData1"
        :chart-id="chartId1"
        :width="width"
        :height="height"
    />
    <hr>
    <Pie
        :chart-options="chartOptions2"
        :chart-data="chartData2"
        :chart-id="chartId2"
        :width="width"
        :height="height"
    />
</template>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?