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

299 lines
7.6 KiB
Vue

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.

<template>
<div class="chart-container">
<div class="chart" :class="{ activehide: isActive }" ref="chart"></div>
<!-- 底座背景 -->
</div>
</template>
<script>
import { getPie3D, getParametricEquation } from "../../../utils/echart.js"; //工具类js页面路径自己修改
const color = ["#005aff", "#f8b551"];
import * as echarts from "echarts";
export default {
name: "chart",
props: ["xAxis1data", "yAxis1seriesMAX1", "yAxis1seriesMAX2", "series1data1", "series1data2", "series1data3"],
data() {
return {
optionData: [],
statusChart: null,
option: {},
isActive: false,
// color:["#005aff", "#f8b551",'#7CDCAC'],
};
},
watch: {
xAxis1data: function (newVal, oldVal) {
this.initChart();
},
colorlist: function (newVal, oldVal) {},
},
created() {
// console.log(this.list);
// this.color = this.colorlist
},
mounted() {
// this.setLabel();
// this.initChart();
//根据窗口变化自动调节图表大小
const that = this;
window.onresize = function () {
that.changeSize();
};
},
methods: {
// 初始化label样式
setLabel() {
const that = this;
this.optionData = this.list;
this.optionData.forEach((item, index) => {
// item.itemStyle = {
// color: that.color[index],
// };
item.label = {
normal: {
show: true,
// color: that.color[index],
formatter: ["{b|{b}}:", "{d|{d}%}"].join(""), // 用\n来换行
rich: {
b: {
color: "#fff",
lineHeight: 25,
align: "left",
},
c: {
fontSize: 22,
color: "#fff",
textShadowColor: "#1c90a6",
textShadowOffsetX: 0,
textShadowOffsetY: 2,
textShadowBlur: 5,
},
d: {
color: "#fff",
align: "left",
textShadowOffsetX: 0,
textShadowOffsetY: 2,
textShadowBlur: 5,
},
},
},
};
item.labelLine = {
normal: {
lineStyle: {
width: 1,
color: "rgba(255,255,255,0.7)",
},
},
};
});
},
// 图表初始化
initChart() {
console.log(this.xAxisdata1,'w222111')
this.statusChart = echarts.init(this.$refs.chart);
// 传入数据生成 option, 构建3d饼状图, 参数工具文件已经备注的很详细
this.option = {
tooltip: {
trigger: "item",
axisPointer: {
// 坐标轴指示器,坐标轴触发有效
type: "shadow", // 默认为直线,可选为:'line' | 'shadow'
},
},
grid: {
left: "4%",
right: "4%",
bottom: "2%",
top: "6%",
containLabel: true,
},
legend: {
// data: ["调解成功", "调解失败", "调解终止", "调解成功率"],
// left: "7%",
// top: "5%",
// textStyle: {
// color: "#ffffff",
// },
// itemWidth: 15,
// itemHeight: 10,
// itemGap: 25,
},
xAxis: {
type: "category",
data: this.xAxis1data,
axisLine: {
lineStyle: {
color: "#cdd5e2",
},
},
axisLabel: {
textStyle: {
color: "#666666",
},
},
axisLabel: {
//show:false,
color: "#7785D9",
fontSize: 12,
rotate: "45",
},
},
yAxis: [
{
type: "value",
splitLine: {
show: false,
},
axisLabel: {
textStyle: {
color: "#ffffff",
},
},
axisLine: {
lineStyle: {
color: "#cdd5e2",
},
},
axisLine: {
show: false,
lineStyle: {
color: "#e0e7ff",
},
},
max: this.yAxis1seriesMAX1,
},
{
type: "value",
name: "百分比",
nameTextStyle: {
color: "#ffffff",
},
position: "right",
axisLine: {
lineStyle: {
color: "#cdd5e2",
},
},
splitLine: {
show: false,
},
axisLabel: {
show: true,
formatter: "{value} %", //右侧Y轴文字显示
textStyle: {
color: "#ffffff",
},
},
max: this.yAxis1seriesMAX2,
},
],
series: [
{
//name: "理论数量",
type: "bar",
barWidth: "12px",
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: "#29acff",
},
{
offset: 1,
color: "#4bdfff",
},
]),
barBorderRadius: 6,
},
},
data: this.series1data1,
},
{
//name: "实际产量",
type: "bar",
barWidth: "12px",
itemStyle: {
normal: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: "#3d93f2",
},
{
offset: 1,
color: "#5dc1fd",
},
]),
barBorderRadius: 6,
},
},
data: this.series1data2,
},
{
//name: "达成率",
type: "line",
yAxisIndex: 1, //使用的 y 轴的 index在单个图表实例中存在多个 y轴的时候有用
smooth: false, //平滑曲线显示
symbol: "circle", //标记的图形为实心圆
symbolSize: 8, //标记的大小
itemStyle: {
normal: {
color: "#ffa43a",
borderColor: "rgba(255, 234, 0, 0.5)", //圆点透明 边框
borderWidth: 5,
},
},
lineStyle: {
color: "#ffa43a",
},
data: this.series1data3,
},
],
};
this.statusChart.setOption(this.option);
},
// 监听鼠标事件,实现饼图选中效果(单选),近似实现高亮(放大)效果。
// optionName是防止有多个图表进行定向option传递单个图表可以不传默认是opiton
// 自适应宽高
changeSize() {
this.statusChart.resize();
},
},
};
</script>
<style lang='scss' scoped>
.chart-container {
position: relative;
width: 100%;
height: 100%;
.chart,
.bg {
width: 100%;
height: 100%;
}
.bg {
position: absolute;
bottom: 50px;
left: 50%;
z-index: -1;
width: 180px;
height: 73px;
background: no-repeat center;
background-image: url("https://ks3-cn-beijing.ksyun.com/sxjg-elevator/datav-platform-2.0/images/chart_opacity_bg.png");
background-size: 100% 100%;
transform: translateX(-50%);
}
}
.activehide {
display: none;
}
</style>