|
@@ -1,5 +1,8 @@
|
|
|
import { type PropType } from "vue";
|
|
|
import { EChartsOption } from "echarts";
|
|
|
+import { getNormalizedChart } from "@/utils/common";
|
|
|
+import { dataSource } from "@/utils/common";
|
|
|
+import { DataSourceType } from "@/enum";
|
|
|
|
|
|
export const basicLineProps = {
|
|
|
width: {
|
|
@@ -10,6 +13,7 @@ export const basicLineProps = {
|
|
|
type: Number as PropType<number>,
|
|
|
default: 260,
|
|
|
},
|
|
|
+ dataSource,
|
|
|
// 标题
|
|
|
title: {
|
|
|
type: Object as PropType<EChartsOption["title"]>,
|
|
@@ -48,6 +52,15 @@ export const basicLineProps = {
|
|
|
},
|
|
|
};
|
|
|
|
|
|
+const chartOptions = getNormalizedChart({
|
|
|
+ title: {
|
|
|
+ text: "折线图标题",
|
|
|
+ },
|
|
|
+ xAxis: {
|
|
|
+ data: ['轴标签A', '轴标签B', '轴标签C', '轴标签D']
|
|
|
+ },
|
|
|
+});
|
|
|
+
|
|
|
export const defaultPropsValue: EChartsOption = {
|
|
|
container: {
|
|
|
props: {
|
|
@@ -56,72 +69,47 @@ export const defaultPropsValue: EChartsOption = {
|
|
|
},
|
|
|
},
|
|
|
props: {
|
|
|
- title: {
|
|
|
- text: "折线图标题",
|
|
|
- left: "center",
|
|
|
- top: 8,
|
|
|
- textStyle: {
|
|
|
- color: "#fff",
|
|
|
- fontSize: 16,
|
|
|
- },
|
|
|
- },
|
|
|
- legend: {
|
|
|
- textStyle: {
|
|
|
- color: "#fff",
|
|
|
+ // 数据源
|
|
|
+ dataSource: {
|
|
|
+ sourceType: DataSourceType.STATIC,
|
|
|
+ data: {
|
|
|
+ xData: ['轴标签A', '轴标签B', '轴标签C', '轴标签D'],
|
|
|
+ series: [
|
|
|
+ {
|
|
|
+ type: 'bar',
|
|
|
+ name: '系列1',
|
|
|
+ data: [89.3, 92.1, 94.4, 85.4]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ type: 'bar',
|
|
|
+ name: '系列2',
|
|
|
+ data: [95.8, 89.4, 91.2, 76.9]
|
|
|
+ },
|
|
|
+ ]
|
|
|
},
|
|
|
- top: 32,
|
|
|
- },
|
|
|
- grid: {
|
|
|
- bottom: 34,
|
|
|
- right: 20,
|
|
|
- top: 60,
|
|
|
- },
|
|
|
- tooltip: {},
|
|
|
- xAxis: {
|
|
|
- type: "category",
|
|
|
- axisLabel: {
|
|
|
- color: "#9fadbf",
|
|
|
- },
|
|
|
- },
|
|
|
- yAxis: {
|
|
|
- axisLabel: {
|
|
|
- color: "#9fadbf",
|
|
|
- },
|
|
|
- splitLine: {
|
|
|
- lineStyle: {
|
|
|
- type: "dashed",
|
|
|
- color: "#36485f",
|
|
|
- },
|
|
|
- },
|
|
|
- },
|
|
|
- series: [
|
|
|
- { type: "line", itemStyle: { color: "#1890ff" } },
|
|
|
- { type: "line", itemStyle: { color: "#2fc25b" } },
|
|
|
- ],
|
|
|
- dataset: {
|
|
|
- dimensions: ["month", "city", "city2"],
|
|
|
- source: [
|
|
|
- {
|
|
|
- month: "纵轴A",
|
|
|
- city: Math.floor(Math.random() * 100),
|
|
|
- city2: Math.floor(Math.random() * 100),
|
|
|
- },
|
|
|
- {
|
|
|
- month: "纵轴B",
|
|
|
- city: Math.floor(Math.random() * 100),
|
|
|
- city2: Math.floor(Math.random() * 100),
|
|
|
- },
|
|
|
- {
|
|
|
- month: "纵轴C",
|
|
|
- city: Math.floor(Math.random() * 100),
|
|
|
- city2: Math.floor(Math.random() * 100),
|
|
|
- },
|
|
|
- {
|
|
|
- month: "纵轴D",
|
|
|
- city: Math.floor(Math.random() * 100),
|
|
|
- city2: Math.floor(Math.random() * 100),
|
|
|
- },
|
|
|
- ],
|
|
|
+ url: location.origin + "/mock/api/get/example/line",
|
|
|
+ method: "POST",
|
|
|
+ params: {},
|
|
|
+ headers: {},
|
|
|
+ refreshTime: 0,
|
|
|
+ dataProcess: `
|
|
|
+ (res) => {
|
|
|
+ // 取出列表
|
|
|
+ const data = res.data;
|
|
|
+ // x轴数据
|
|
|
+ const xData = data.map((item) => item.name);
|
|
|
+ // 系列数据
|
|
|
+ const series = [
|
|
|
+ { type: 'bar', name: '苹果', data: data.map(item => item.apple) },
|
|
|
+ { type: 'bar', name: 'VIVO', data: data.map(item => item.vivo) },
|
|
|
+ { type: 'bar', name: '小米', data: data.map(item => item.mi) },
|
|
|
+ ];
|
|
|
+
|
|
|
+ // 返回图表数据
|
|
|
+ return { xData, series };
|
|
|
+ }
|
|
|
+ `
|
|
|
},
|
|
|
+ ...chartOptions
|
|
|
},
|
|
|
};
|