|
@@ -148,8 +148,10 @@ export function barUtilsOne(id, name, Xdata, Ydata, seriesName, yAxisName) {
|
|
|
}
|
|
|
|
|
|
let series = []
|
|
|
+ let gradientColor = getGradientColor(seriesName.length)
|
|
|
|
|
|
for (let i = 0; i < seriesName.length; i++) {
|
|
|
+ let arrColor = gradientColor[i]
|
|
|
series.push({
|
|
|
name: seriesName[i],
|
|
|
type: 'bar',
|
|
@@ -163,23 +165,24 @@ export function barUtilsOne(id, name, Xdata, Ydata, seriesName, yAxisName) {
|
|
|
colorStops: [
|
|
|
{
|
|
|
offset: 0,
|
|
|
- color: '#6633ff',
|
|
|
+ // color: '#6633ff',
|
|
|
+ color: arrColor[0]
|
|
|
},
|
|
|
{
|
|
|
offset: 0.5,
|
|
|
- color: '#6699ff'
|
|
|
+ // color: '#6699ff'
|
|
|
+ color: arrColor[1]
|
|
|
},
|
|
|
{
|
|
|
offset: 1,
|
|
|
- color: '#66ffff'
|
|
|
+ // color: '#66ffff'
|
|
|
+ color: arrColor[2]
|
|
|
}
|
|
|
]
|
|
|
},
|
|
|
label: {
|
|
|
show: true,
|
|
|
- textStyle: {
|
|
|
- color: '#0000ff'
|
|
|
- },
|
|
|
+ color: '#000000',
|
|
|
position: 'top',
|
|
|
formatter(p) {
|
|
|
return p.value > 0 ? p.value : ''
|
|
@@ -253,3 +256,189 @@ export function createColorCode(data) {
|
|
|
}
|
|
|
return list
|
|
|
}
|
|
|
+
|
|
|
+function getGradientColor(num) {
|
|
|
+ let arr = createGradientColor()
|
|
|
+ let return_arr = []
|
|
|
+ for (let i = 0; i < num; i++) {
|
|
|
+ if (arr.length > 0) {
|
|
|
+ let arrIndex = Math.floor(Math.random() * arr.length)
|
|
|
+ return_arr[i] = arr[arrIndex]
|
|
|
+ arr.splice(arrIndex, 1)
|
|
|
+ } else {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return return_arr
|
|
|
+}
|
|
|
+
|
|
|
+function createGradientColor() {
|
|
|
+ let list = []
|
|
|
+ let a = ['#00C5CD', '#00E5EE', '#00F5FF']
|
|
|
+ let b = ['#CD4F39', '#EE5C42', '#FF6347']
|
|
|
+ let c = ['#6633FF', '#6699FF', '#66FFFF']
|
|
|
+ let d = ['#1E90FF', '#63B8FF', '#00BFFF']
|
|
|
+ let e = ['#BF3EFF', '#9B30FF', '#AB82FF']
|
|
|
+ let f = ['#6A5ACD', '#7B68EE', '#8470FF']
|
|
|
+ let g = ['#1E90FF', '#00BFFF', '#87CEFA']
|
|
|
+ let h = ['#00CED1', '#48D1CC', '#40E0D0']
|
|
|
+ let i = ['#00CD66', '#00FF7F', '#9AFF9A']
|
|
|
+ let j = ['#9400D3', '#A020F0', '#BA55D3']
|
|
|
+ list.push(a)
|
|
|
+ list.push(b)
|
|
|
+ list.push(c)
|
|
|
+ list.push(d)
|
|
|
+ list.push(e)
|
|
|
+ list.push(f)
|
|
|
+ list.push(g)
|
|
|
+ list.push(h)
|
|
|
+ list.push(i)
|
|
|
+ list.push(j)
|
|
|
+ return list
|
|
|
+}
|
|
|
+
|
|
|
+// unit:新增tip单位
|
|
|
+export function barUtilsTwo(id, name, Xdata, Ydata, seriesName, yAxisName, unit) {
|
|
|
+ // 验证 这个 是否被创建了
|
|
|
+ let linearBarDom = echarts.getInstanceByDom(id)
|
|
|
+ if (linearBarDom == null) {
|
|
|
+ linearBarDom = echarts.init(id)
|
|
|
+ }
|
|
|
+
|
|
|
+ linearBarDom.setOption({
|
|
|
+ title: {
|
|
|
+ text: name,
|
|
|
+ x: 'center',
|
|
|
+ y: 'bottom',
|
|
|
+ textAlign: 'left',
|
|
|
+ },
|
|
|
+ xAxis: {
|
|
|
+ type: 'category',
|
|
|
+ data: Xdata,
|
|
|
+ axisLabel: {
|
|
|
+ color: '#bb3137',
|
|
|
+ fontSize: 16
|
|
|
+ }
|
|
|
+ },
|
|
|
+ yAxis: {
|
|
|
+ type: 'value',
|
|
|
+ name: yAxisName,
|
|
|
+ nameLocation: 'end',
|
|
|
+ axisLabel: {
|
|
|
+ show: true,
|
|
|
+ interval: 0,
|
|
|
+ formatter: function (value, index) {
|
|
|
+ return value / 1000000
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ legend: {
|
|
|
+ data: [
|
|
|
+ {
|
|
|
+ name: seriesName,
|
|
|
+ icon: 'rect',
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ top: "0%"
|
|
|
+ },
|
|
|
+ tooltip: {
|
|
|
+ trigger: 'axis',
|
|
|
+ confine: true,
|
|
|
+ formatter: function (param) {
|
|
|
+ let relVal = param[0].name + '<br>'
|
|
|
+ param.forEach((item, index) => {
|
|
|
+ if (item.value && 'bar' == param[index].seriesType) {
|
|
|
+ relVal += item.marker + ' ' + item.seriesName + ' : ' + item.value + unit + '</br>'
|
|
|
+ } else if (item.value && 'line' == param[index].seriesType) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+ relVal += item.marker + ' ' + item.seriesName + ' : - </br>'
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return relVal
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ toolbox: {
|
|
|
+ show: 1,
|
|
|
+ itemSize: 24,
|
|
|
+ x: 'right',
|
|
|
+ y: 'top',
|
|
|
+ feature: {
|
|
|
+ saveAsImage: {
|
|
|
+ show: true,
|
|
|
+ title: '下载图片',
|
|
|
+ type: 'png'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ series: [
|
|
|
+ {
|
|
|
+ name: seriesName,
|
|
|
+ type: 'bar',
|
|
|
+ // stack: 'all',
|
|
|
+ barMaxwidth: 35,
|
|
|
+ barGap: '10%',
|
|
|
+ color: {
|
|
|
+ type: 'linear',
|
|
|
+ x: 0,
|
|
|
+ y: 1,
|
|
|
+ colorStops: [
|
|
|
+ {
|
|
|
+ offset: 0,
|
|
|
+ color: '#6633ff',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ offset: 0.35,
|
|
|
+ color: '#6699ff'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ offset: 1,
|
|
|
+ color: '#66ffff'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ label: {
|
|
|
+ show: true,
|
|
|
+ color: '#000000',
|
|
|
+ position: 'top',
|
|
|
+ formatter(p) {
|
|
|
+ return (p.value / 1000000).toFixed(2)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data: Ydata,
|
|
|
+ emphasis: {
|
|
|
+ itemStyle: {
|
|
|
+ borderRadius: 30
|
|
|
+ }
|
|
|
+ },
|
|
|
+ itemStyle: {
|
|
|
+ borderRadius: [12, 12, 0, 0],
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: seriesName,
|
|
|
+ type: 'line',
|
|
|
+ data: Ydata,
|
|
|
+ smooth: true,
|
|
|
+ symbol: 'circle',
|
|
|
+ symbolSize: 1,
|
|
|
+ itemStyle: {
|
|
|
+ lineStyle: {
|
|
|
+ with: 3,
|
|
|
+ color: '#27dba0'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ emphasis: {
|
|
|
+ itemStyle: {
|
|
|
+ color: '#4ccefe'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ })
|
|
|
+ window.onresize = function () {
|
|
|
+ //自适应大小, 不用的话不会自适应大小。
|
|
|
+ linearBarDom.resize()
|
|
|
+ }
|
|
|
+}
|