123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- <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";
- import $ from "jquery";
- export default {
- name: "dsah-pie",
- componentName: "dsah-pie",
- props: {
- // 宽度 默认9.722vh
- width: {
- type: String,
- default: "85%",
- },
- // 高度 默认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: $("#appBody").is(".dark")
- ? partten.getColor("gray")
- : "#000",
- fontSize: util.vh(12),
- 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: $("#appBody").is(".dark")
- ? partten.getColor(this.color) + "01"
- : "rgb(57, 54, 143)",
- },
- {
- offset: 1,
- color: $("#appBody").is(".dark")
- ? partten.getColor(this.color) + "ff"
- : "rgb(57, 54, 143)",
- },
- ]),
- ],
- [1, "transparent"],
- ],
- width: util.vh(12),
- },
- },
- 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: $("#appBody").is(".dark") ? "#fff" : "#000",
- },
- },
- pointer: {
- show: true,
- length: "35%",
- radius: "20%",
- width: 1, //指针粗细
- 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,
- $("#appBody").is(".dark")
- ? partten.getColor(this.color)
- : "rgb(57, 54, 143)",
- ],
- ],
- },
- },
- //仪表盘文字
- axisLabel: {
- show: false,
- },
- //刻度标签。
- axisTick: {
- show: true,
- distance: 6,
- splitNumber: 2,
- lineStyle: {
- color: $("#appBody").is(".dark")
- ? partten.getColor("green")
- : "rgb(57, 54, 143)", //用颜色渐变函数不起作用
- 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,
- animation: false,
- hoverAnimation: false,
- data: [
- {
- value: this.value,
- itemStyle: {
- normal: {
- color: "transition",
- },
- },
- label: {
- normal: {
- formatter: function (params) {
- return params.value;
- },
- color: $("#appBody").is(".dark")
- ? partten.getColor(this.color)
- : "rgb(57, 54, 143)",
- fontSize: util.vh(12),
- fontWeight: "bold",
- position: "center",
- show: true,
- },
- },
- labelLine: {
- show: false,
- },
- },
- ],
- },
- {
- name: "内部阴影",
- type: "gauge",
- radius: "90%",
- splitNumber: 10,
- axisLine: {
- lineStyle: {
- color: [
- // [
- // 1,
- // new echarts.graphic.LinearGradient(0, 1, 0, 0, [
- // {
- // offset: 0,
- // color: "rgba(45,230,150,0)",
- // },
- // {
- // offset: 0.5,
- // color: "rgba(45,230,150,0.2)",
- // },
- // {
- // offset: 1,
- // color: "rgba(45,230,150,1)",
- // },
- // ]),
- // ],
- [
- 1,
- $("#appBody").is(".dark")
- ? "rgba(45,230,150,0.1)"
- : "rgba(57, 54, 143, 0.1)",
- ],
- // [1, "rgba(45,230,150,0)"],
- ],
- width: 3,
- },
- },
- axisLabel: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- splitLine: {
- show: false,
- },
- itemStyle: {
- show: false,
- },
- },
- // 光环
- {
- type: "pie",
- radius: "40%",
- center: ["50%", "50%"],
- animationType: "scale",
- animation: false,
- label: {
- show: false,
- },
- labelLine: {
- show: false,
- },
- emphasis: {
- scale: false,
- },
- data: [
- {
- value: 1,
- itemStyle: {
- color: "transparent",
- borderColor: $("#appBody").is(".dark")
- ? partten.getColor(this.color)
- : "rgb(57, 54, 143)",
- opacity: 0.3,
- shadowColor: $("#appBody").is(".dark")
- ? partten.getColor(this.color)
- : "rgb(57, 54, 143)",
- 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);
- },
- watch: {
- "$store.state.themeName"() {
- this.initChart();
- },
- },
- };
- </script>
- <style lang="less" scoped>
- .chart {
- width: 100%;
- height: 100%;
- display: block;
- margin: auto;
- }
- </style>
|