mirror of
https://github.com/pipipi-pikachu/PPTist.git
synced 2025-04-15 02:20:00 +08:00
perf: 图表提及优化(EChart按需加载)
This commit is contained in:
parent
26872cd6dc
commit
8a8210356e
@ -4,11 +4,25 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { onMounted, ref, computed, watch } from 'vue'
|
import { onMounted, ref, computed, watch } from 'vue'
|
||||||
import * as echarts from 'echarts'
|
|
||||||
import tinycolor from 'tinycolor2'
|
import tinycolor from 'tinycolor2'
|
||||||
import type { ChartData, ChartOptions, ChartType } from '@/types/slides'
|
import type { ChartData, ChartOptions, ChartType } from '@/types/slides'
|
||||||
import { getChartOption } from './chartOption'
|
import { getChartOption } from './chartOption'
|
||||||
|
|
||||||
|
import * as echarts from 'echarts/core'
|
||||||
|
import { BarChart, LineChart, PieChart, ScatterChart, RadarChart } from 'echarts/charts'
|
||||||
|
import { LegendComponent } from 'echarts/components'
|
||||||
|
import { SVGRenderer } from 'echarts/renderers'
|
||||||
|
|
||||||
|
echarts.use([
|
||||||
|
BarChart,
|
||||||
|
LineChart,
|
||||||
|
PieChart,
|
||||||
|
ScatterChart,
|
||||||
|
RadarChart,
|
||||||
|
LegendComponent,
|
||||||
|
SVGRenderer,
|
||||||
|
])
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
width: number
|
width: number
|
||||||
height: number
|
height: number
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
import type * as echarts from 'echarts'
|
import type { ComposeOption } from 'echarts/core'
|
||||||
|
import type {
|
||||||
|
BarSeriesOption,
|
||||||
|
LineSeriesOption,
|
||||||
|
PieSeriesOption,
|
||||||
|
ScatterSeriesOption,
|
||||||
|
RadarSeriesOption,
|
||||||
|
} from 'echarts/charts'
|
||||||
import type { ChartData, ChartType } from '@/types/slides'
|
import type { ChartData, ChartType } from '@/types/slides'
|
||||||
|
|
||||||
|
type EChartOption = ComposeOption<BarSeriesOption | LineSeriesOption | PieSeriesOption | ScatterSeriesOption | RadarSeriesOption>
|
||||||
|
|
||||||
export interface ChartOptionPayload {
|
export interface ChartOptionPayload {
|
||||||
type: ChartType
|
type: ChartType
|
||||||
data: ChartData
|
data: ChartData
|
||||||
@ -17,19 +26,13 @@ export const getChartOption = ({
|
|||||||
textColor,
|
textColor,
|
||||||
lineSmooth,
|
lineSmooth,
|
||||||
stack,
|
stack,
|
||||||
}: ChartOptionPayload): echarts.EChartsOption | null => {
|
}: ChartOptionPayload): EChartOption | null => {
|
||||||
if (type === 'bar') {
|
if (type === 'bar') {
|
||||||
return {
|
return {
|
||||||
color: themeColors,
|
color: themeColors,
|
||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
color: textColor,
|
color: textColor,
|
||||||
} : {},
|
} : {},
|
||||||
tooltip: {
|
|
||||||
trigger: 'axis',
|
|
||||||
axisPointer: {
|
|
||||||
type: 'shadow',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
legend: data.series.length > 1 ? {
|
legend: data.series.length > 1 ? {
|
||||||
top: 'bottom',
|
top: 'bottom',
|
||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
@ -44,7 +47,7 @@ export const getChartOption = ({
|
|||||||
type: 'value',
|
type: 'value',
|
||||||
},
|
},
|
||||||
series: data.series.map((item, index) => {
|
series: data.series.map((item, index) => {
|
||||||
const seriesItem: echarts.SeriesOption = {
|
const seriesItem: BarSeriesOption = {
|
||||||
data: item,
|
data: item,
|
||||||
name: data.legends[index],
|
name: data.legends[index],
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
@ -63,12 +66,6 @@ export const getChartOption = ({
|
|||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
color: textColor,
|
color: textColor,
|
||||||
} : {},
|
} : {},
|
||||||
tooltip: {
|
|
||||||
trigger: 'axis',
|
|
||||||
axisPointer: {
|
|
||||||
type: 'shadow',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
legend: data.series.length > 1 ? {
|
legend: data.series.length > 1 ? {
|
||||||
top: 'bottom',
|
top: 'bottom',
|
||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
@ -83,7 +80,7 @@ export const getChartOption = ({
|
|||||||
type: 'value',
|
type: 'value',
|
||||||
},
|
},
|
||||||
series: data.series.map((item, index) => {
|
series: data.series.map((item, index) => {
|
||||||
const seriesItem: echarts.SeriesOption = {
|
const seriesItem: BarSeriesOption = {
|
||||||
data: item,
|
data: item,
|
||||||
name: data.legends[index],
|
name: data.legends[index],
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
@ -102,12 +99,6 @@ export const getChartOption = ({
|
|||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
color: textColor,
|
color: textColor,
|
||||||
} : {},
|
} : {},
|
||||||
tooltip: {
|
|
||||||
trigger: 'axis',
|
|
||||||
axisPointer: {
|
|
||||||
type: 'shadow',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
legend: data.series.length > 1 ? {
|
legend: data.series.length > 1 ? {
|
||||||
top: 'bottom',
|
top: 'bottom',
|
||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
@ -122,7 +113,7 @@ export const getChartOption = ({
|
|||||||
type: 'value',
|
type: 'value',
|
||||||
},
|
},
|
||||||
series: data.series.map((item, index) => {
|
series: data.series.map((item, index) => {
|
||||||
const seriesItem: echarts.SeriesOption = {
|
const seriesItem: LineSeriesOption = {
|
||||||
data: item,
|
data: item,
|
||||||
name: data.legends[index],
|
name: data.legends[index],
|
||||||
type: 'line',
|
type: 'line',
|
||||||
@ -142,12 +133,6 @@ export const getChartOption = ({
|
|||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
color: textColor,
|
color: textColor,
|
||||||
} : {},
|
} : {},
|
||||||
tooltip: {
|
|
||||||
trigger: 'item',
|
|
||||||
axisPointer: {
|
|
||||||
type: 'shadow',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
legend: {
|
legend: {
|
||||||
top: 'bottom',
|
top: 'bottom',
|
||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
@ -184,12 +169,6 @@ export const getChartOption = ({
|
|||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
color: textColor,
|
color: textColor,
|
||||||
} : {},
|
} : {},
|
||||||
tooltip: {
|
|
||||||
trigger: 'item',
|
|
||||||
axisPointer: {
|
|
||||||
type: 'shadow',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
legend: {
|
legend: {
|
||||||
top: 'bottom',
|
top: 'bottom',
|
||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
@ -226,12 +205,6 @@ export const getChartOption = ({
|
|||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
color: textColor,
|
color: textColor,
|
||||||
} : {},
|
} : {},
|
||||||
tooltip: {
|
|
||||||
trigger: 'axis',
|
|
||||||
axisPointer: {
|
|
||||||
type: 'shadow',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
legend: data.series.length > 1 ? {
|
legend: data.series.length > 1 ? {
|
||||||
top: 'bottom',
|
top: 'bottom',
|
||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
@ -247,7 +220,7 @@ export const getChartOption = ({
|
|||||||
type: 'value',
|
type: 'value',
|
||||||
},
|
},
|
||||||
series: data.series.map((item, index) => {
|
series: data.series.map((item, index) => {
|
||||||
const seriesItem: echarts.SeriesOption = {
|
const seriesItem: LineSeriesOption = {
|
||||||
data: item,
|
data: item,
|
||||||
name: data.legends[index],
|
name: data.legends[index],
|
||||||
type: 'line',
|
type: 'line',
|
||||||
@ -274,12 +247,6 @@ export const getChartOption = ({
|
|||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
color: textColor,
|
color: textColor,
|
||||||
} : {},
|
} : {},
|
||||||
tooltip: {
|
|
||||||
trigger: 'item',
|
|
||||||
axisPointer: {
|
|
||||||
type: 'shadow',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
legend: data.series.length > 1 ? {
|
legend: data.series.length > 1 ? {
|
||||||
top: 'bottom',
|
top: 'bottom',
|
||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
@ -310,12 +277,6 @@ export const getChartOption = ({
|
|||||||
textStyle: textColor ? {
|
textStyle: textColor ? {
|
||||||
color: textColor,
|
color: textColor,
|
||||||
} : {},
|
} : {},
|
||||||
tooltip: {
|
|
||||||
trigger: 'item',
|
|
||||||
axisPointer: {
|
|
||||||
type: 'shadow',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
xAxis: {},
|
xAxis: {},
|
||||||
yAxis: {},
|
yAxis: {},
|
||||||
series: [
|
series: [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user