mkl_power_box/components/time-study-chart.js

166 lines
5.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 顶部header
*/
Vue.component("time-study-chart", {
template: `
<div :style="{'height': height+'px'}" ref="chart"> </div>
`,
props: {
height:{
type:Number
},
data:{
type:Object
}
},
data() {
return {
option:{}
}
},
mounted(){
this.init()
},
methods: {
init(){
this.getChartData()
},
//分类及工时情况
getChartData(){
var chChartBar = echarts.init(this.$refs.chart);
this.echartBar(chChartBar,this.data)
},
echartBar(chChart,data){
let newPromise = new Promise((resolve) => {
resolve()
})
//然后异步执行echarts的初始化函数
newPromise.then(() => {
this.option = {
grid: {
top:'10%',
left: "2%",
right: "0%",
bottom: "0%",
containLabel: true,
},
tooltip: {
trigger: "axis",
formatter: function (params) {
return (params[0].seriesName+"<br/>"
+params[0].name +""+ params[0].data + "%")
},
},
xAxis: {
type: "category",
data: data.xAxis,
axisLine: {
//坐标轴轴线相关设置。数学上的x轴
show: true,
lineStyle: {
color: "#25597e",
type: "dashed",
},
},
axisTick: {
show: false
},
axisLabel: {
//坐标轴刻度标签的相关设置
textStyle: {
color: "#c5d9fc",
margin: 20,
fontSize:12
},
},
},
yAxis: {
type: "value",
axisLine: {
//坐标轴轴线相关设置。数学上的x轴
show: false,
lineStyle: {
color: "#c5d9fc",
type: "dashed",
},
},
axisTick: {
show: false
},
axisLabel: {
show: true,
//坐标轴刻度标签的相关设置
textStyle: {
color: "#c5d9fc",
margin: 20,
fontSize:12
},
},
splitLine: {
show: true,
lineStyle: {
color: "#25597e",
type: "dashed",
},
},
},
series: [
{
name: data.seriesName,
type: "pictorialBar",
barCategoryGap: "0%",
label: {
normal: {
show: true,
position: "top",
color:"#fff"
},
},
//symbol: 'path://M0,10 L10,10 L5,0 L0,10 z',
symbol: "path://M0,10 L10,10 C5.5,10 5.5,5 5,0 C4.5,5 4.5,10 0,10 z",
itemStyle: {
normal: {
color: {
type: "linear",
x: 0,
y: 0,
x2: 0,
y2: 1,
colorStops: [
{
offset: 0,
color: "rgba(15,133,224,0.2)", // 0% 处的颜色
},
{
offset: 0.9,
color: "rgba(15,133,224,0.8)", // 100% 处的颜色
},
],
global: false, // 缺省为 false
},
},
emphasis: {
opacity: 1,
},
},
data: data.data,
z: 10,
},
],
};
chChart.setOption(this.option);
window.onresize = chChart.resize;
})
},
},
watch:{
data: function (n,o) {
this.init()
}
}
})