|
|
@@ -94,23 +94,42 @@ const lineBarSeriesOption = (chart: any, serieData: Array<any>, serieType: strin
|
|
|
const series = []
|
|
|
let yAxisMax = 0
|
|
|
let maxData = 0
|
|
|
+ let showLabel = getOption(chartOptions, "showLabel", false)
|
|
|
+ //const markPointStyles = getOption(chartOptions, "markPointStyles", [])
|
|
|
+ //const markPointLabel = getOption(chartOptions, "markPointLabel", {})
|
|
|
+ const markLineStyles = getOption(chartOptions, "markLineStyles", [
|
|
|
+ {
|
|
|
+ color: "#FF5147",
|
|
|
+ },
|
|
|
+ ])
|
|
|
+ const markLineLabel = getOption(chartOptions, "markLineLabel", {
|
|
|
+ color: "#FF5147",
|
|
|
+ })
|
|
|
+ const markAreaStyles = getOption(chartOptions, "markAreaStyles", {
|
|
|
+ color: "rgba(255,81,71,0.2)",
|
|
|
+ })
|
|
|
+ const markAreaLabel = getOption(chartOptions, "markAreaLabel", {
|
|
|
+ color: "#F2637B",
|
|
|
+ offset: [31, 0],
|
|
|
+ })
|
|
|
+ const labelFormatter = getOption(chartOptions, "labelFormatter", undefined)
|
|
|
+ const markPoint = getOption(chartOptions, "markPoint", {})
|
|
|
+ const markLine = getOption(chartOptions, "markLine", {})
|
|
|
+ const markArea = getOption(chartOptions, "markArea", {})
|
|
|
+ const barGap = getOption(chartOptions, "barGap", defaultOption.SIZE.barGap)
|
|
|
+ const symbol = getOption(chartOptions, "symbol", "circle")
|
|
|
+ const smooth = getOption(chartOptions, "smooth", 0.5)
|
|
|
+ const areaStyleColors = getOption(chartOptions, "areaStyle", [
|
|
|
+ "rgba(56,164,90,.5)",
|
|
|
+ "rgb(76,136,207,.3)",
|
|
|
+ "rgb(255,185,126,.3)",
|
|
|
+ ])
|
|
|
+ const dataMarkLine = getOption(chart, "markLine", {})
|
|
|
+ const dataMarkArea = getOption(chart, "markArea", {})
|
|
|
serieData.forEach((v: any, i: number) => {
|
|
|
legend.data.push({
|
|
|
name: v.name,
|
|
|
})
|
|
|
- let showLabel = getOption(chartOptions, "showLabel", false)
|
|
|
- // (params: any) => {
|
|
|
- // if (params.value == undefined || params.value !== params.value) {
|
|
|
- // params.value = 0
|
|
|
- // }
|
|
|
- // if (totalArr[params.dataIndex] == 0) {
|
|
|
- // return ""
|
|
|
- // } else {
|
|
|
- // const percent = ((params.value / totalArr[params.dataIndex]) * 100).toFixed(2)
|
|
|
- // return percent + "%"
|
|
|
- // }
|
|
|
- // }
|
|
|
- const labelFormatter = getOption(chartOptions, "labelFormatter", undefined)
|
|
|
if (typeof labelFormatter == "function") {
|
|
|
showLabel = true
|
|
|
}
|
|
|
@@ -121,9 +140,10 @@ const lineBarSeriesOption = (chart: any, serieData: Array<any>, serieType: strin
|
|
|
name: v.name,
|
|
|
data: v.data,
|
|
|
stack: has(v, "stack") ? v.stack : null,
|
|
|
- markPoint: getOption(chartOptions, "markPoint", {}),
|
|
|
- markLine: getOption(chartOptions, "markLine", {}),
|
|
|
- markArea: getOption(chartOptions, "markArea", {}),
|
|
|
+ itemStyle: getOption(v, "itemStyle", {}),
|
|
|
+ markPoint,
|
|
|
+ markLine,
|
|
|
+ markArea,
|
|
|
label: {
|
|
|
show: showLabel,
|
|
|
position: "",
|
|
|
@@ -136,18 +156,18 @@ const lineBarSeriesOption = (chart: any, serieData: Array<any>, serieType: strin
|
|
|
type == "bar"
|
|
|
? {
|
|
|
barWidth: defaultOption.SIZE.barWidth,
|
|
|
- barGap: getOption(chartOptions, "barGap", defaultOption.SIZE.barGap),
|
|
|
+ barGap,
|
|
|
//barMinWidth: defaultOption.SIZE.barMinWidth,
|
|
|
barMaxWidth: defaultOption.SIZE.barMaxWidth,
|
|
|
}
|
|
|
: {
|
|
|
- symbol: getOption(chartOptions, "symbol", "circle"),
|
|
|
+ symbol,
|
|
|
symbolSize: defaultOption.SIZE.symbolSize,
|
|
|
connectNulls: true,
|
|
|
- smooth: getOption(chartOptions, "smooth", 0.5),
|
|
|
+ smooth,
|
|
|
smoothMonotone: "x",
|
|
|
areaStyle: {
|
|
|
- color: getOption(chartOptions, "areaStyle", [])[i],
|
|
|
+ color: areaStyleColors[i],
|
|
|
},
|
|
|
}
|
|
|
)
|
|
|
@@ -159,26 +179,35 @@ const lineBarSeriesOption = (chart: any, serieData: Array<any>, serieType: strin
|
|
|
})
|
|
|
yAxisMax = Math.floor(maxData * 1.2)
|
|
|
}
|
|
|
-
|
|
|
+ if (dataMarkLine) {
|
|
|
+ seriesOption.markLine = dataMarkLine
|
|
|
+ }
|
|
|
if (has(chart, "warning")) {
|
|
|
const markLine: any = {
|
|
|
silent: true,
|
|
|
- label: getOption(chartOptions, "markLineLabel", {}),
|
|
|
+ label: markLineLabel,
|
|
|
data: [
|
|
|
{
|
|
|
yAxis: chart.warning,
|
|
|
},
|
|
|
],
|
|
|
}
|
|
|
- if (has(chart, "markLineStyles") && isArray(chart.markLineStyles)) {
|
|
|
- markLine.lineStyle = chart.markLineStyles[i % chart.markLineStyles.length]
|
|
|
- delete chartOptions.markLineStyles
|
|
|
+ if (markLineStyles && markLineStyles.length) {
|
|
|
+ markLine.lineStyle = markLineStyles[i % markLineStyles.length]
|
|
|
}
|
|
|
if (chart.warning > maxData) {
|
|
|
yAxisMax = Math.floor(chart.warning * 1.1)
|
|
|
}
|
|
|
seriesOption.markLine = markLine
|
|
|
}
|
|
|
+
|
|
|
+ if (dataMarkArea) {
|
|
|
+ seriesOption.markArea = {
|
|
|
+ data: dataMarkArea,
|
|
|
+ label: markAreaLabel,
|
|
|
+ itemStyle: markAreaStyles,
|
|
|
+ }
|
|
|
+ }
|
|
|
const seriesItem = extendDeep(seriesOption, chartOptions.series || {})
|
|
|
|
|
|
series.push(seriesItem)
|
|
|
@@ -308,7 +337,7 @@ const pieSeriesOption = (chart: any, serieData: Array<any>, serieType: string, c
|
|
|
title.text = `{title|${titleText}}`
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ const itemStyle = getOption(chartOptions, "pieItemStyle", undefined)
|
|
|
serieData.forEach((v: any) => {
|
|
|
const name = showPercent ? `${v.name}:${getPercent(total, v.value)}` : v.name
|
|
|
legend.data.push({
|
|
|
@@ -317,7 +346,7 @@ const pieSeriesOption = (chart: any, serieData: Array<any>, serieType: string, c
|
|
|
const item = {
|
|
|
name,
|
|
|
value: v.value,
|
|
|
- itemStyle: getOption(chartOptions, "pieItemStyle", undefined),
|
|
|
+ itemStyle,
|
|
|
}
|
|
|
data.push(item)
|
|
|
})
|
|
|
@@ -326,8 +355,7 @@ const pieSeriesOption = (chart: any, serieData: Array<any>, serieType: string, c
|
|
|
return { legend, title, tooltip, series }
|
|
|
}
|
|
|
|
|
|
-export default {
|
|
|
- /**
|
|
|
+/**
|
|
|
*
|
|
|
* @param data 远程数据
|
|
|
* @param options 为eChart的配置项
|
|
|
@@ -349,48 +377,68 @@ export default {
|
|
|
* @param serieType 图表类型
|
|
|
* @returns eChart的配置项
|
|
|
*/
|
|
|
- chart(data: any, options: any, serieType?: string) {
|
|
|
- if (data == null) {
|
|
|
- throw new Error("no data")
|
|
|
- }
|
|
|
- const chartOptions = extendDeep({}, options)
|
|
|
- serieType = getOption(chartOptions, "serieType", serieType)
|
|
|
- const _chart = compatibleData(data)
|
|
|
- const _series = compatibleSeries(_chart)
|
|
|
- //const _xAxisData = has(_chart, "categories") ? _chart.categories : []
|
|
|
+const chart = (data: any, options: any, serieType?: string) => {
|
|
|
+ if (data == null) {
|
|
|
+ throw new Error("NO CHART DATA")
|
|
|
+ }
|
|
|
+ const _chart = compatibleData(data)
|
|
|
+ const _series = compatibleSeries(_chart)
|
|
|
+ const chartOptions = extendDeep({}, options)
|
|
|
+ serieType = getOption(chartOptions, "serieType", serieType)
|
|
|
+ //const _xAxisData = has(_chart, "categories") ? _chart.categories : []
|
|
|
|
|
|
- //标题默认在图表下居中 ,使用远程数据 yzTitle 字段
|
|
|
- const title = {
|
|
|
- show: true,
|
|
|
- text: getOption(_chart, "title", "") || getOption(_chart, "yzTitle", ""),
|
|
|
- }
|
|
|
- const grid = Object.assign({}, defaultOption.SIZE.grid)
|
|
|
+ //标题默认在图表下居中 ,使用远程数据 yzTitle 字段
|
|
|
+ const title = {
|
|
|
+ show: true,
|
|
|
+ text: getOption(_chart, "title", "") || getOption(_chart, "yzTitle", ""),
|
|
|
+ }
|
|
|
+ const grid = Object.assign({}, defaultOption.SIZE.grid)
|
|
|
|
|
|
- let seriesOption = {}
|
|
|
- switch (serieType) {
|
|
|
- case "bar":
|
|
|
- case "line":
|
|
|
- seriesOption = lineBarSeriesOption(_chart, _series, serieType ?? "bar", chartOptions)
|
|
|
- break
|
|
|
- case "pie":
|
|
|
- seriesOption = pieSeriesOption(_chart, _series, serieType ?? "pie", chartOptions)
|
|
|
- break
|
|
|
- }
|
|
|
- const option = extendDeep({ title, grid }, seriesOption, chartOptions)
|
|
|
- return option
|
|
|
- //return Object.assign(true, {}, opt, options || {})
|
|
|
- },
|
|
|
+ let seriesOption = {}
|
|
|
+ switch (serieType) {
|
|
|
+ case "bar":
|
|
|
+ case "line":
|
|
|
+ seriesOption = lineBarSeriesOption(_chart, _series, serieType ?? "bar", chartOptions)
|
|
|
+ break
|
|
|
+ case "pie":
|
|
|
+ seriesOption = pieSeriesOption(_chart, _series, serieType ?? "pie", chartOptions)
|
|
|
+ break
|
|
|
+ }
|
|
|
+ const option = extendDeep({ title, grid }, seriesOption, chartOptions)
|
|
|
+ return option
|
|
|
+ //return Object.assign(true, {}, opt, options || {})
|
|
|
+}
|
|
|
+
|
|
|
+// const doubleTypes = (data: any, options: any, types = ["bar", "line"]) => {
|
|
|
+// if (data == null) {
|
|
|
+// throw new Error("no data")
|
|
|
+// }
|
|
|
+// const chartOptions = extendDeep({}, options)
|
|
|
+// const _charts = compatibleMultChartData(data)
|
|
|
+
|
|
|
+// const grid = Object.assign({}, defaultOption.SIZE.grid)
|
|
|
+// _charts.forEach((_chart: any, i: number) => {
|
|
|
+// const _series = compatibleSeries(_chart)
|
|
|
+// //标题默认在图表下居中 ,使用远程数据 title , yzTitle 字段
|
|
|
+// const title = {
|
|
|
+// show: true,
|
|
|
+// text: getOption(_chart, "title", "") || getOption(_chart, "yzTitle", ""),
|
|
|
+// }
|
|
|
+// })
|
|
|
+// }
|
|
|
+
|
|
|
+export default {
|
|
|
bar(data: any, options: any) {
|
|
|
- return this.chart(data, options, "bar")
|
|
|
+ return chart(data, options, "bar")
|
|
|
},
|
|
|
line(data: any, options: any) {
|
|
|
- return this.chart(data, options, "line")
|
|
|
+ return chart(data, options, "line")
|
|
|
},
|
|
|
pie(data: any, options: any) {
|
|
|
- return this.chart(data, options, "pie")
|
|
|
+ return chart(data, options, "pie")
|
|
|
},
|
|
|
ring(data: any, options: any) {
|
|
|
options = Object.assign({ pieRadius: defaultOption.SIZE.ringRadius }, options)
|
|
|
- return this.chart(data, options, "pie")
|
|
|
+ return chart(data, options, "pie")
|
|
|
},
|
|
|
}
|