You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
5.3 KiB

3 years ago
// 调性分布
export default function negaposiOption(dName = [], data = {}) {
// let newValue = [];
// dValue.forEach(ele => {
// newValue.push(ele*1-100);
// })
3 years ago
Array.prototype.sum = function () {
let x = 0
this.forEach(ele => {
x += Number(ele)
})
return x
}
3 years ago
const totalData = []
const msg = []
3 years ago
//切换成百分比
let newArr = []
for (let [index, i] of Object.keys(data).entries()) {
for (let j = 0; j < data[i].length; j++) {
if (newArr[j] == undefined) newArr[j] = []
newArr[j].push(data[i][j])
}
}
for (let [index,i] of newArr.entries()) {
let sum = i.sum()
newArr[index] = i.map(ele => {
return ((Number(ele) / sum) * 100).toFixed(2)
})
}
let newArr2 = []
for(let i of newArr ){
for(let j=0;j<i.length;j++){
if(newArr2[j]==undefined) newArr2[j]=[]
newArr2[j].push(i[j])
}
}
for(let [index,i] of Object.keys(data).entries()){
data[i] = newArr2[index]
}
3 years ago
for (let [index, i] of Object.keys(data).entries()) {
msg.push(i)
let obj = {
name: i,
type: 'bar',
barWidth: 12,
stack: 'Total',
label: {
show: false,
position: 'right',
formatter: function (params) {
return (params.data) + '%';
},
},
itemStyle: {
normal: {
barBorderRadius: '',
color: '#20cd61'
},
},
emphasis: {
focus: 'series'
},
data: data[i]
}
if (index == 0) {
obj.itemStyle.normal.barBorderRadius = [12, 0, 0, 12]
obj.itemStyle.normal.color = '#0283ff'
} else if (index == Object.keys(data).length - 1) {
obj.itemStyle.normal.barBorderRadius = [0, 12, 12, 0]
obj.itemStyle.normal.color = '#fec000'
}
totalData.push(obj)
}
return {
tooltip: {
trigger: 'axis',
3 years ago
backgroundColor: "#08182F",
color: "#fff",
borderColor: "#3373CC",
textStyle: {
color: "#fff", //设置文字颜色
fontSize: 9
},
extraCssText: "box-shadow: 0px 0px 10px 0px #3373CC;",
confine: true
3 years ago
},
legend: {
data: msg,
3 years ago
left: 15,
icon: 'rectangle', //data图标样式
3 years ago
// data:[{name:'正面'},{name:'中性'},{name:'负面'},]
textStyle: { //图例文字的样式
color: 'black',
fontSize: 8
},
3 years ago
itemWidth: 10,
itemHeight: 10,
3 years ago
},
grid: {
3 years ago
bottom: 20,
height: 140,
3 years ago
left: 20,
3 years ago
containLabel: true
},
xAxis: [{
type: 'value',
show: false
}],
yAxis: [{
type: 'category',
inverse: true,
axisTick: {
show: false
},
axisLine: {
show: false
},
axisLabel: {
margin: 10,
fontSize: 12
},
data: dName
}],
series: totalData
// [
// {
// name: '男',
// type: 'bar',
// barWidth:12,
// stack: 'Total',
// label: {
// show: false,
// position: 'right',
// formatter: function (params) {
// return (params.data)+'%';
// },
// },
// itemStyle:{
// normal:{
// barBorderRadius:[12,0,0,12],
// color: '#0084FF'
// },
// },
// emphasis: {
// focus: 'series'
// },
// data: dMan
// },
// {
// name: '女',
// type: 'bar',
// barWidth:12,
// stack: 'Total',
// label: {
// show: false,
// position: 'right',
// formatter: function (params) {
// return (params.data)+'%';
// },
// },
// itemStyle:{
// normal:{
// color: '#20cb65'
// },
// },
// emphasis: {
// focus: 'series'
// },
// data: dLady
// },
// {
// name: '未设置性别',
// type: 'bar',
// barWidth:12,
// stack: 'Total',
// label: {
// show: false,
// position: 'left',
// formatter: function (params) {
// return (params.data) +'%';
// },
// },
// itemStyle:{
// normal:{
// barBorderRadius:[0,12,12,0],
// color: '#FFBF00',
// },
// },
// emphasis: {
// focus: 'series'
// },
// data: noGender
// }
// ]
};
}