frequi_origin/src/components/charts/DailyChart.vue

147 lines
3.3 KiB
Vue
Raw Normal View History

<template>
2021-05-24 14:24:46 +00:00
<v-chart v-if="dailyStats.data" :option="dailyChartOptions" :theme="getChartTheme" autoresize />
</template>
<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator';
import { Getter } from 'vuex-class';
import ECharts from 'vue-echarts';
import { EChartsOption } from 'echarts';
2020-10-04 17:24:21 +00:00
2021-05-24 15:45:20 +00:00
import { use } from 'echarts/core';
import { CanvasRenderer } from 'echarts/renderers';
import { LineChart, BarChart } from 'echarts/charts';
import { TitleComponent, TooltipComponent, LegendComponent } from 'echarts/components';
2020-08-29 09:23:39 +00:00
import { DailyReturnValue } from '@/types';
2021-05-24 15:45:20 +00:00
use([BarChart, LineChart, CanvasRenderer, TitleComponent, TooltipComponent, LegendComponent]);
// Define Column labels here to avoid typos
const CHART_ABS_PROFIT = 'Absolute profit';
const CHART_TRADE_COUNT = 'Trade Count';
@Component({
components: {
'v-chart': ECharts,
},
})
export default class DailyChart extends Vue {
2020-08-17 18:42:37 +00:00
@Prop({ required: true }) dailyStats!: DailyReturnValue;
2020-08-31 15:47:26 +00:00
@Prop({ default: true, type: Boolean }) showTitle!: boolean;
@Getter getChartTheme!: string;
2020-08-18 18:51:16 +00:00
get absoluteMin() {
return Number(
this.dailyStats.data.reduce(
(min, p) => (p.abs_profit < min ? p.abs_profit : min),
this.dailyStats.data[0].abs_profit,
),
);
}
get absoluteMax() {
return Number(
this.dailyStats.data.reduce(
(max, p) => (p.abs_profit > max ? p.abs_profit : max),
this.dailyStats.data[0].abs_profit,
),
);
}
get dailyChartOptions(): EChartsOption {
return {
title: {
text: 'Daily profit',
2020-08-31 15:47:26 +00:00
show: this.showTitle,
},
2021-05-25 20:06:43 +00:00
backgroundColor: 'rgba(0, 0, 0, 0)',
dataset: {
dimensions: ['date', 'abs_profit', 'trade_count'],
source: this.dailyStats.data,
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'line',
label: {
backgroundColor: '#6a7985',
},
},
},
legend: {
data: [CHART_ABS_PROFIT, CHART_TRADE_COUNT],
right: '5%',
},
xAxis: {
type: 'category',
inverse: true,
},
2020-10-04 17:24:21 +00:00
visualMap: [
{
dimension: 1,
seriesIndex: 0,
show: false,
pieces: [
{
max: 0.0,
min: this.absoluteMin,
2020-10-04 17:24:21 +00:00
color: 'red',
},
{
min: 0.0,
max: this.absoluteMax,
2020-10-04 17:24:21 +00:00
color: 'green',
},
],
},
],
yAxis: [
{
type: 'value',
name: CHART_ABS_PROFIT,
splitLine: {
show: false,
},
nameRotate: 90,
nameLocation: 'middle',
nameGap: 50,
},
{
type: 'value',
name: CHART_TRADE_COUNT,
nameRotate: 90,
nameLocation: 'middle',
nameGap: 30,
},
],
series: [
{
type: 'line',
name: CHART_ABS_PROFIT,
2020-10-04 17:24:21 +00:00
// Color is induced by visualMap
},
{
type: 'bar',
name: CHART_TRADE_COUNT,
2020-10-04 17:24:21 +00:00
itemStyle: {
color: 'rgba(150,150,150,0.3)',
},
yAxisIndex: 1,
},
],
};
}
}
</script>
2020-08-18 05:05:40 +00:00
<style lang="scss" scoped>
.echarts {
width: 100%;
height: 100%;
2021-05-26 19:00:39 +00:00
min-height: 240px;
2020-08-18 05:05:40 +00:00
}
</style>