|
@@ -30,13 +30,13 @@ export default {
|
|
|
type: Boolean,
|
|
|
default: false,
|
|
|
},
|
|
|
- height:{
|
|
|
+ height: {
|
|
|
type: Number,
|
|
|
- default: document.body.clientHeight / 3
|
|
|
+ default: document.body.clientHeight / 3,
|
|
|
},
|
|
|
- transposed:{
|
|
|
- type: Boolean,// 是否反转坐标轴
|
|
|
- default: false
|
|
|
+ transposed: {
|
|
|
+ type: Boolean, // 是否反转坐标轴
|
|
|
+ default: false,
|
|
|
},
|
|
|
className: {
|
|
|
// 多柱状图
|
|
@@ -85,12 +85,12 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
watch: {
|
|
|
- list:{
|
|
|
- deep:true,
|
|
|
- handler: function(){
|
|
|
+ list: {
|
|
|
+ deep: true,
|
|
|
+ handler: function() {
|
|
|
this.init();
|
|
|
- }
|
|
|
- }
|
|
|
+ },
|
|
|
+ },
|
|
|
},
|
|
|
methods: {
|
|
|
init() {
|
|
@@ -99,7 +99,7 @@ export default {
|
|
|
let count = list.length > 10 ? 10 : list.length;
|
|
|
let barWidth = (document.body.clientWidth - 100) / count;
|
|
|
barWidth > 40 && (barWidth = 40);
|
|
|
- this.transposed && (barWidth = 10)
|
|
|
+ this.transposed && (barWidth = 10);
|
|
|
list.sort((a, b) => {
|
|
|
return b[this.keyName] - a[this.keyName];
|
|
|
});
|
|
@@ -126,15 +126,15 @@ export default {
|
|
|
label: function label(text) {
|
|
|
// 只显示每一年的第一天
|
|
|
const textCfg = {};
|
|
|
- if(text >= 100000000){
|
|
|
- textCfg.text = text / 100000000 + "亿"
|
|
|
- }else if(text >= 10000){
|
|
|
- textCfg.text = text / 10000 + "万"
|
|
|
- } else{
|
|
|
- textCfg.text = text
|
|
|
+ if (text >= 100000000) {
|
|
|
+ textCfg.text = text / 100000000 + "亿";
|
|
|
+ } else if (text >= 10000) {
|
|
|
+ textCfg.text = text / 10000 + "万";
|
|
|
+ } else {
|
|
|
+ textCfg.text = text;
|
|
|
}
|
|
|
return textCfg;
|
|
|
- }
|
|
|
+ },
|
|
|
});
|
|
|
if (this.className) {
|
|
|
this.chart.scale("nickname", {
|
|
@@ -147,15 +147,15 @@ export default {
|
|
|
showCrosshairs: false,
|
|
|
layout: "vertical",
|
|
|
snap: true,
|
|
|
- onChange: (obj) => {
|
|
|
+ onChange: obj => {
|
|
|
const legend = this.chart.get("legendController").legends.top[0];
|
|
|
const tooltipItems = obj.items;
|
|
|
const legendItems = legend.items;
|
|
|
const map = {};
|
|
|
- legendItems.forEach(function (item) {
|
|
|
+ legendItems.forEach(function(item) {
|
|
|
map[item.name] = JSON.parse(JSON.stringify(item));
|
|
|
});
|
|
|
- tooltipItems.forEach(function (item) {
|
|
|
+ tooltipItems.forEach(function(item) {
|
|
|
const name = item.name;
|
|
|
const value = item.value;
|
|
|
if (map[name]) {
|
|
@@ -164,7 +164,7 @@ export default {
|
|
|
});
|
|
|
let keys = Object.keys(map);
|
|
|
let listVal = [];
|
|
|
- keys.map((v) => {
|
|
|
+ keys.map(v => {
|
|
|
listVal.push(map[v]);
|
|
|
});
|
|
|
legend.setItems(listVal);
|
|
@@ -177,7 +177,17 @@ export default {
|
|
|
this.chart
|
|
|
.interval()
|
|
|
.position("nickname*" + this.keyName)
|
|
|
- .color(x,["#4992ff", "#38f385", "#f45c64", "#58e0f4", "#0da17c", "#fc7b2e", "#8339df", "#f467f9", "#fddd60"])
|
|
|
+ .color(x, [
|
|
|
+ "#4992ff",
|
|
|
+ "#38f385",
|
|
|
+ "#f45c64",
|
|
|
+ "#58e0f4",
|
|
|
+ "#0da17c",
|
|
|
+ "#fc7b2e",
|
|
|
+ "#8339df",
|
|
|
+ "#f467f9",
|
|
|
+ "#fddd60",
|
|
|
+ ])
|
|
|
.size(barWidth);
|
|
|
} else {
|
|
|
this.chart.tooltip({
|
|
@@ -185,7 +195,7 @@ export default {
|
|
|
triggerOn: ["touchstart"],
|
|
|
showCrosshairs: false,
|
|
|
snap: true,
|
|
|
- onShow: (obj) => {
|
|
|
+ onShow: obj => {
|
|
|
const items = obj.items;
|
|
|
items[0].name = null;
|
|
|
},
|
|
@@ -194,14 +204,24 @@ export default {
|
|
|
});
|
|
|
this.chart
|
|
|
.interval()
|
|
|
- .size(barWidth)
|
|
|
.position(x + "*" + this.keyName)
|
|
|
- .color(x,["#4992ff", "#38f385", "#f45c64", "#58e0f4", "#0da17c", "#fc7b2e", "#8339df", "#f467f9", "#fddd60"]);
|
|
|
+ .size(barWidth)
|
|
|
+ .color(x, [
|
|
|
+ "#4992ff",
|
|
|
+ "#38f385",
|
|
|
+ "#f45c64",
|
|
|
+ "#58e0f4",
|
|
|
+ "#0da17c",
|
|
|
+ "#fc7b2e",
|
|
|
+ "#8339df",
|
|
|
+ "#f467f9",
|
|
|
+ "#fddd60",
|
|
|
+ ]);
|
|
|
}
|
|
|
// 反正坐标
|
|
|
- this.chart.coord({
|
|
|
- transposed: this.transposed
|
|
|
- })
|
|
|
+ this.chart.coord({
|
|
|
+ transposed: this.transposed,
|
|
|
+ });
|
|
|
// Step 4: 渲染图表
|
|
|
this.chart.render();
|
|
|
// 绘制柱状图文本
|