2020-08-17 18:39:14 +00:00
|
|
|
<template>
|
2023-05-09 18:06:24 +00:00
|
|
|
<e-charts
|
2022-04-19 18:07:59 +00:00
|
|
|
v-if="dailyStats.data"
|
|
|
|
:option="dailyChartOptions"
|
|
|
|
:theme="settingsStore.chartTheme"
|
|
|
|
autoresize
|
|
|
|
/>
|
2020-08-17 18:39:14 +00:00
|
|
|
</template>
|
|
|
|
|
2023-05-09 18:06:24 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { computed, ComputedRef } from 'vue';
|
2020-08-17 18:39:14 +00:00
|
|
|
import ECharts from 'vue-echarts';
|
2021-12-25 12:45:26 +00:00
|
|
|
// 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';
|
2021-08-08 17:53:05 +00:00
|
|
|
import {
|
|
|
|
DatasetComponent,
|
|
|
|
GridComponent,
|
|
|
|
LegendComponent,
|
|
|
|
TitleComponent,
|
|
|
|
TooltipComponent,
|
|
|
|
VisualMapComponent,
|
|
|
|
} from 'echarts/components';
|
2020-08-17 18:39:14 +00:00
|
|
|
|
2020-08-29 09:23:39 +00:00
|
|
|
import { DailyReturnValue } from '@/types';
|
2022-04-19 18:07:59 +00:00
|
|
|
import { useSettingsStore } from '@/stores/settings';
|
2022-04-22 18:02:50 +00:00
|
|
|
import { EChartsOption } from 'echarts';
|
2020-08-17 18:39:14 +00:00
|
|
|
|
2021-08-08 17:53:05 +00:00
|
|
|
use([
|
|
|
|
BarChart,
|
|
|
|
LineChart,
|
|
|
|
CanvasRenderer,
|
|
|
|
GridComponent,
|
|
|
|
DatasetComponent,
|
|
|
|
LegendComponent,
|
|
|
|
TitleComponent,
|
|
|
|
TooltipComponent,
|
|
|
|
VisualMapComponent,
|
|
|
|
]);
|
2021-05-24 15:45:20 +00:00
|
|
|
|
2020-08-17 18:39:14 +00:00
|
|
|
// Define Column labels here to avoid typos
|
|
|
|
const CHART_ABS_PROFIT = 'Absolute profit';
|
|
|
|
const CHART_TRADE_COUNT = 'Trade Count';
|
|
|
|
|
2023-05-09 18:06:24 +00:00
|
|
|
const props = defineProps({
|
|
|
|
dailyStats: {
|
|
|
|
type: Object as () => DailyReturnValue,
|
|
|
|
required: true,
|
2020-08-17 18:39:14 +00:00
|
|
|
},
|
2023-05-09 18:06:24 +00:00
|
|
|
showTitle: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
2021-12-25 12:45:26 +00:00
|
|
|
},
|
2023-05-09 18:06:24 +00:00
|
|
|
});
|
2020-12-28 19:34:54 +00:00
|
|
|
|
2023-05-09 18:06:24 +00:00
|
|
|
const settingsStore = useSettingsStore();
|
|
|
|
const absoluteMin = computed(() =>
|
|
|
|
props.dailyStats.data.reduce(
|
|
|
|
(min, p) => (p.abs_profit < min ? p.abs_profit : min),
|
|
|
|
props.dailyStats.data[0]?.abs_profit,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
const absoluteMax = computed(() =>
|
|
|
|
props.dailyStats.data.reduce(
|
|
|
|
(max, p) => (p.abs_profit > max ? p.abs_profit : max),
|
|
|
|
props.dailyStats.data[0]?.abs_profit,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
const dailyChartOptions: ComputedRef<EChartsOption> = computed(() => {
|
|
|
|
return {
|
|
|
|
title: {
|
|
|
|
text: 'Daily profit',
|
|
|
|
show: props.showTitle,
|
|
|
|
},
|
|
|
|
backgroundColor: 'rgba(0, 0, 0, 0)',
|
|
|
|
dataset: {
|
|
|
|
dimensions: ['date', 'abs_profit', 'trade_count'],
|
|
|
|
source: props.dailyStats.data,
|
|
|
|
},
|
|
|
|
tooltip: {
|
|
|
|
trigger: 'axis',
|
|
|
|
axisPointer: {
|
|
|
|
type: 'line',
|
|
|
|
label: {
|
|
|
|
backgroundColor: '#6a7985',
|
2020-08-17 18:39:14 +00:00
|
|
|
},
|
2023-05-09 18:06:24 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
data: [CHART_ABS_PROFIT, CHART_TRADE_COUNT],
|
|
|
|
right: '5%',
|
|
|
|
},
|
|
|
|
xAxis: [
|
|
|
|
{
|
|
|
|
type: 'category',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
visualMap: [
|
|
|
|
{
|
|
|
|
dimension: 1,
|
|
|
|
seriesIndex: 0,
|
|
|
|
show: false,
|
|
|
|
pieces: [
|
2022-04-22 18:02:50 +00:00
|
|
|
{
|
2023-05-09 18:06:24 +00:00
|
|
|
max: 0.0,
|
|
|
|
min: absoluteMin.value,
|
|
|
|
color: 'red',
|
2022-04-22 18:02:50 +00:00
|
|
|
},
|
|
|
|
{
|
2023-05-09 18:06:24 +00:00
|
|
|
min: 0.0,
|
|
|
|
max: absoluteMax.value,
|
|
|
|
color: 'green',
|
2022-04-22 18:02:50 +00:00
|
|
|
},
|
|
|
|
],
|
2023-05-09 18:06:24 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
yAxis: [
|
|
|
|
{
|
|
|
|
type: 'value',
|
|
|
|
name: CHART_ABS_PROFIT,
|
|
|
|
splitLine: {
|
|
|
|
show: false,
|
|
|
|
},
|
|
|
|
nameRotate: 90,
|
|
|
|
nameLocation: 'middle',
|
|
|
|
nameGap: 40,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'value',
|
|
|
|
name: CHART_TRADE_COUNT,
|
|
|
|
nameRotate: 90,
|
|
|
|
nameLocation: 'middle',
|
|
|
|
nameGap: 30,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
series: [
|
|
|
|
{
|
|
|
|
type: 'line',
|
|
|
|
name: CHART_ABS_PROFIT,
|
|
|
|
// Color is induced by visualMap
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'bar',
|
|
|
|
name: CHART_TRADE_COUNT,
|
|
|
|
itemStyle: {
|
|
|
|
color: 'rgba(150,150,150,0.3)',
|
|
|
|
},
|
|
|
|
yAxisIndex: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2021-12-25 12:45:26 +00:00
|
|
|
});
|
2020-08-17 18:39:14 +00:00
|
|
|
</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>
|