123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313 |
- <template>
- <div class="chart" :id="id"></div>
- </template>
- <script>
- import util from "@/helper/util.js";
- import partten from "@/helper/partten.js";
- import * as echarts from "echarts";
- export default {
- name: "dsah-pie",
- componentName: "dsah-pie",
- props: {
- // 宽度 默认9.722vh
- width: {
- type: String,
- default: "70%",
- },
- // 高度 默认9.722vh
- height: {
- type: String,
- default: "7.4074vh",
- },
- // 标题
- title: {
- type: String,
- default: "标题",
- },
- // 值
- value: {
- type: Number,
- default: 42.1,
- },
- // 最小值
- min: {
- type: Number,
- default: 0,
- },
- // 最大值
- max: {
- type: Number,
- default: 100,
- },
- // 颜色 传入 green yellow等 (partten中支持的颜色)
- color: {
- type: String,
- default: "green",
- },
- },
- data() {
- return {
- id: "",
- chart: null,
- };
- },
- computed: {
- colorValue() {
- return partten.getColor(this.color);
- },
- },
- methods: {
- resize() {},
- initChart() {
- let chart = echarts.init(this.$el);
- let option = {
- title: {
- show: true,
- text: this.title,
- x: "45%",
- y: "80%",
- z: 8,
- textAlign: "center",
- textStyle: {
- color: partten.getColor("gray"),
- fontSize: util.vh(14),
- fontWeight: "normal",
- },
- },
- series: [
- // 进度条
- {
- z: 1,
- name: "内部(环形)进度条",
- type: "gauge",
- radius: "100%",
- splitNumber: 5,
- axisLine: {
- lineStyle: {
- color: [
- [
- this.value / this.max,
- new echarts.graphic.LinearGradient(0, 0, 1, 0, [
- {
- offset: 0,
- color: partten.getColor(this.color) + "01",
- },
- {
- offset: 1,
- color: partten.getColor(this.color) + "ff",
- },
- ]),
- ],
- [1, "transparent"],
- ],
- width: util.vh(16),
- },
- },
- axisLabel: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- splitLine: {
- show: false,
- },
- pointer: {
- show: false,
- },
- },
- // 指针
- {
- name: "指针",
- type: "gauge",
- z: 2,
- min: this.min,
- max: this.max,
- radius: "100%",
- axisLine: {
- show: false,
- },
- tooltip: {
- show: false,
- },
- axisLabel: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- splitLine: {
- show: false,
- },
- detail: {
- show: false,
- },
- title: {
- //标题
- show: false,
- },
- data: [
- {
- value: this.value,
- },
- ],
- itemStyle: {
- normal: {
- color: "#fff",
- },
- },
- pointer: {
- show: true,
- length: "35%",
- radius: "20%",
- width: util.vh(2), //指针粗细
- offsetCenter: ["0%", "-40%"],
- },
- animationDuration: 0,
- },
- // 刻度
- {
- name: "外部刻度",
- type: "gauge",
- // center: ['20%', '50%'],
- radius: "100%",
- min: this.min, //最小刻度
- max: this.max, //最大刻度
- splitNumber: 10, //刻度数量
- startAngle: 225,
- endAngle: -45,
- axisLine: {
- show: true,
- // 仪表盘刻度线
- lineStyle: {
- width: util.vh(1),
- color: [[1, partten.getColor(this.color)]],
- },
- },
- //仪表盘文字
- axisLabel: {
- show: false,
- },
- //刻度标签。
- axisTick: {
- show: true,
- distance: 6,
- splitNumber: 2,
- lineStyle: {
- color: "#fff", //用颜色渐变函数不起作用
- width: util.vh(1),
- },
- length: util.vh(4),
- }, //刻度样式
- splitLine: {
- show: false,
- }, //分隔线样式
- detail: {
- show: false,
- },
- pointer: {
- show: false,
- },
- },
- // 显示数字
- {
- type: "pie",
- radius: ["0", "40%"],
- center: ["50%", "50%"],
- z: 8,
- hoverAnimation: false,
- data: [
- {
- value: this.value,
- itemStyle: {
- normal: {
- color: "transition",
- },
- },
- label: {
- normal: {
- formatter: function(params) {
- return params.value;
- },
- color: partten.getColor(this.color),
- fontSize: util.vh(16),
- fontWeight: "bold",
- position: "center",
- show: true,
- },
- },
- labelLine: {
- show: false,
- },
- },
- ],
- },
- // 光环
- {
- type: "pie",
- radius: "40%",
- center: ["50%", "50%"],
- animationType: "scale",
- animation: false,
- label: {
- show: false,
- },
- labelLine: {
- show: false,
- },
- data: [
- {
- value: 1,
- itemStyle: {
- normal: {
- color: "transparent",
- borderColor: partten.getColor(this.color),
- opacity: 0.3,
- shadowColor: partten.getColor(this.color),
- shadowBlur: util.vh(20),
- },
- },
- },
- ],
- },
- ],
- };
- chart.clear();
- chart.setOption(option);
- this.resize = function() {
- chart.resize();
- };
- window.removeEventListener("resize", this.resize);
- window.addEventListener("resize", this.resize);
- },
- },
- created() {
- this.id = "pie-chart-" + util.newGUID();
- },
- mounted() {
- this.$el.style.width = this.width;
- this.$el.style.height = this.height;
- this.initChart();
- },
- updated() {
- this.initChart();
- },
- unmounted() {
- window.removeEventListener("resize", this.resize);
- },
- };
- </script>
- <style lang="less" scoped>
- .chart {
- width: 100%;
- height: 100%;
- display: block;
- margin: auto;
- }
- </style>
|