This repository has been archived on 2023-06-18. You can view files and clone it, but cannot push or open issues or pull requests.
va-project/stockingly-frontend/src/components/EpsChart.vue

95 lines
2.1 KiB
Vue

<template>
<v-card variant="outlined">
<v-card-item>
<v-card-title>Earnings per Share (EPS)</v-card-title>
</v-card-item>
<v-card-text>
<v-skeleton-loader class="chart-loader" v-if="epsData.loading" />
<ag-charts-vue class="chart" v-else :options="options" />
</v-card-text>
</v-card>
</template>
<script setup lang="ts">
import { Eps, getEps } from '@/api';
import { defineLoader } from '@/api/loader';
import { roundTo } from 'round-to';
import { onMounted, computed } from 'vue';
import { AgChartsVue } from 'ag-charts-vue3';
const renderer = (params: any) => ({
title: params.title,
content: params.xValue + ': ' + roundTo(params.yValue, 4),
});
const props = defineProps<{
tickers: string[],
colors: string[]
}>();
const getTickerColor = (ticker: string) => props.colors[props.tickers.indexOf(ticker)];
const epsData = defineLoader<Eps[]>(() => getEps(props.tickers));
const options = computed(() => {
if (epsData.loading) return null;
return {
theme: 'ag-material',
data: epsData.data ?? [],
series: props.tickers.map((t: string) => ({
xKey: 'quarter',
type: 'column',
yKey: t,
yName: t,
fill: getTickerColor(t),
stroke: getTickerColor(t),
tooltip: { renderer: renderer },
highlightStyle: {
item: { fillOpacity: 0 },
series: { enabled: false }
},
})),
axes: [
{
type: 'category',
position: 'bottom',
label: {
autoRotate: true,
autoRotateAngle: 335,
},
gridStyle: [{
lineDash: [Infinity]
}, {
lineDash: [Infinity]
}],
title: {
enabled: true,
text: 'Quarter'
},
},
{
type: 'number',
position: 'left',
min: 0,
gridStyle: [{
lineDash: [Infinity]
}, {
lineDash: [Infinity]
}],
title: {
enabled: true,
text: 'Amount in USD'
},
},
],
legend: {
position: 'bottom',
}
};
});
onMounted(() => {
epsData.load();
});
</script>