-
+
@@ -29,12 +29,36 @@ export default {
name: "wtcEc",
data() {
return {
- opt: createOpt(),
+ opt: {},
form: {
token: "",
sRele: "",
},
- sourceData: []
+ load: false,
+ colors: [
+ "#54BF93",
+ "#3373CC",
+ "#CC9D12",
+ "#f15c80",
+ "#e4d354",
+ "#8085e8",
+ "#8d4653",
+ "#91e8e1",
+ "#f7a35c",
+ "#90ed7d",
+ "#54BF93",
+ "#3373CC",
+ "#CC9D12",
+ "#f15c80",
+ "#e4d354",
+ "#8085e8",
+ "#8d4653",
+ "#91e8e1",
+ "#f7a35c",
+ "#90ed7d",
+ ],
+ eventList: [],
+ showData: []
};
},
created() {
@@ -52,11 +76,42 @@ export default {
},
getData() {
let obj = Object.assign({}, this.getCtime2, this.form);
+ this.load = true;
getAffectionsC(obj).then((res) => {
let data = res.data || [];
- this.sourceData = data;
+ let eList = [];
+ let dList = [];
+ data.forEach(e => {
+ let subStr = e.Name;
+ if(subStr.length > 5){
+ eList.push(subStr.substr(0, 4))
+ } else {
+ eList.push(subStr)
+ }
+ dList.push(this.toArr(e.Data))
+ })
+ this.eventList = eList;
+ this.showData = dList;
+ this.opt = createOpt(this.showData[0],this.colors);
+ this.load = false;
});
},
+ // 将对象变成数组
+ toArr(obj) {
+ let arr = [];
+ for (let key in obj) {
+ let o = {
+ key: key,
+ value: obj[key],
+ };
+ arr.push(o);
+ }
+ return arr;
+ },
+ //切换数据
+ handlerTab(n) {
+ this.opt = createOpt(this.showData[n],this.colors);
+ },
},
};
diff --git a/src/views/EventComparison/wtcEc/opt.js b/src/views/EventComparison/wtcEc/opt.js
index 54f07f6..6ef365d 100644
--- a/src/views/EventComparison/wtcEc/opt.js
+++ b/src/views/EventComparison/wtcEc/opt.js
@@ -6,8 +6,33 @@
* @Description: In User Settings Edit
* @FilePath: /data-show/src/views/BrandInsight/weiboKol/opt.js
*/
+
+function createData(ds = [], colors) {
+ let arr = [];
+ ds.map((ele, index) => {
+ let obj = {
+ value: ele.value,
+ name: ele.key,
+ itemStyle: {
+ color: new echarts.graphic.LinearGradient(0, 1, 1, 0, [{
+ //给颜色设置渐变色 前面4个参数,给第一个设置1,第四个设置0 ,就是水平渐变
+ //给第一个设置0,第四个设置1,就是垂直渐变
+ offset: 0,
+ color: 'black'
+ }, {
+ offset: 1,
+ color: colors[index]
+ }])
+ }
+ }
+ arr.push(obj)
+ })
+ return arr;
+ }
+
import * as echarts from "echarts";
-export default function createOpt() {
+export default function createOpt(ds = [], color = []) {
+ const data = createData(ds, color);
return {
legend: {
textStyle: { //图例文字的样式
@@ -20,12 +45,12 @@ export default function createOpt() {
{
name: 'Access From0',
type: 'pie',
- radius: ['60%', '70%'],
+ radius: ['50%', '61%'],
avoidLabelOverlap: false,
label: {
show: false,
position: 'center',
- lineHeight: 40
+ lineHeight: 32
},
emphasis: {
label: {
@@ -34,48 +59,19 @@ export default function createOpt() {
color: "#ffff",
fontWeight: 'bold',
formatter: function(p) {
- return `${p.data.name}\n25%\n${p.data.value}`
+ return `${p.data.name}\n${p.percent}%\n${p.data.value}`
}
}
},
labelLine: {
show: false
},
- data: [
- { value: 2000, name: '正面', itemStyle: {color: new echarts.graphic.LinearGradient(0, 1, 1, 0, [{
- //给颜色设置渐变色 前面4个参数,给第一个设置1,第四个设置0 ,就是水平渐变
- //给第一个设置0,第四个设置1,就是垂直渐变
- offset: 0,
- color: 'black'
- }, {
- offset: 1,
- color: '#3373CC'
- }])} },
-
- { value: 1000, name: '中性', itemStyle: {color: new echarts.graphic.LinearGradient(0, 1, 1, 0, [{
- //给颜色设置渐变色 前面4个参数,给第一个设置1,第四个设置0 ,就是水平渐变
- //给第一个设置0,第四个设置1,就是垂直渐变
- offset: 0,
- color: 'black'
- }, {
- offset: 1,
- color: '#54BF93'
- }])} },
- { value: 1000, name: '负面', itemStyle: {color: new echarts.graphic.LinearGradient(0, 1, 1, 0, [{
- //给颜色设置渐变色 前面4个参数,给第一个设置1,第四个设置0 ,就是水平渐变
- //给第一个设置0,第四个设置1,就是垂直渐变
- offset: 0,
- color: 'black'
- }, {
- offset: 1,
- color: '#b38b14'
- }])} },
- ],
+ data: data
},
{
name: 'Access From1',
type: 'pie',
- radius: ['74%', '78%'],
+ radius: ['64%', '67%'],
avoidLabelOverlap: false,
label: {
show: false,
@@ -85,37 +81,7 @@ export default function createOpt() {
show: false
},
center: ['50%', '50%'],//边框位置
- data: [
- { value: 2000, name: '正面', itemStyle: {color: new echarts.graphic.LinearGradient(0, 1, 1, 0, [{
- //给颜色设置渐变色 前面4个参数,给第一个设置1,第四个设置0 ,就是水平渐变
- //给第一个设置0,第四个设置1,就是垂直渐变
- offset: 0,
- color: 'black'
- }, {
- offset: 1,
- color: '#3373CC'
- }])} },
-
- { value: 1000, name: '中性', itemStyle: {color: new echarts.graphic.LinearGradient(0, 1, 1, 0, [{
- //给颜色设置渐变色 前面4个参数,给第一个设置1,第四个设置0 ,就是水平渐变
- //给第一个设置0,第四个设置1,就是垂直渐变
- offset: 0,
- color: 'black'
- }, {
- offset: 1,
- color: '#54BF93'
- }])} },
- { value: 1000, name: '负面', itemStyle: {color: new echarts.graphic.LinearGradient(0, 1, 1, 0, [{
- //给颜色设置渐变色 前面4个参数,给第一个设置1,第四个设置0 ,就是水平渐变
- //给第一个设置0,第四个设置1,就是垂直渐变
- offset: 0,
- color: 'black'
- }, {
- offset: 1,
- color: '#b38b14'
- }])} },
-
- ],
+ data: data
}
]
}