123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <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: {
- width: {
- type: String,
- default: "7.407vh",
- },
- height: {
- type: String,
- default: "7.407vh",
- },
- // 传入数据
- value: {
- type: Number,
- default: 25,
- },
- // 颜色 green yellow (partten中支持的颜色)
- color: {
- type: String,
- default: "green",
- },
- },
- data() {
- return {
- id: "",
- chart: null,
- };
- },
- computed: {
- colorValue() {
- return partten.getColor(this.color);
- },
- text() {
- return this.value + "%";
- },
- },
- created() {
- this.id = "pie-chart-" + util.newGUID();
- },
- methods: {
- initChart() {
- let chart = echarts.init(this.$el);
- let option = {
- title: [
- {
- text: this.text,
- x: "45%",
- y: "32%",
- textAlign: "center",
- textStyle: {
- fontSize: 14,
- fontFamily: "Bicubik",
- fontWeight: "600",
- color: partten.getColor(this.colors),
- textAlign: "center",
- },
- },
- ],
- polar: {
- radius: ["100%", "85%"],
- center: ["50%", "50%"],
- },
- angleAxis: {
- max: 100,
- show: false,
- startAngle: 180,
- },
- radiusAxis: {
- type: "category",
- show: true,
- axisLabel: {
- show: false,
- },
- axisLine: {
- show: false,
- },
- axisTick: {
- show: false,
- },
- },
- series: [
- {
- name: "",
- z: "3",
- type: "bar",
- roundCap: true,
- barWidth: 60,
- showBackground: true,
- backgroundStyle: {
- color: partten.getColor(this.colors) + "30",
- },
- data: [this.value],
- coordinateSystem: "polar",
- itemStyle: {
- normal: {
- color: partten.getColor(this.colors),
- // new echarts.graphic.LinearGradient(1, 0, 0, 0, [
- // {
- // offset: 0,
- // color: "#0ff",
- // },
- // {
- // offset: 1,
- // color: "#02aeff",
- // },
- // ]),
- },
- },
- },
- {
- type: "pie",
- radius: ["100%", "97%"],
- startAngle: 180,
- center: ["50%", "50%"],
- data: [
- {
- hoverOffset: 1,
- value: 100,
- name: "",
- itemStyle: {
- color: partten.getColor(this.colors),
- },
- label: {
- show: false,
- },
- labelLine: {
- normal: {
- smooth: true,
- lineStyle: {
- width: 0,
- },
- },
- },
- hoverAnimation: false,
- },
- {
- label: {
- show: false,
- },
- labelLine: {
- normal: {
- smooth: true,
- lineStyle: {
- width: 0,
- },
- },
- },
- value: 0,
- hoverAnimation: false,
- itemStyle: {
- color: "transparent",
- },
- },
- ],
- },
- ],
- };
- chart.setOption(option);
- },
- },
- mounted() {
- this.$nextTick(() => {
- this.$el.style.width = this.width;
- this.$el.style.height = this.height;
- this.initChart();
- });
- },
- updated() {
- this.$nextTick(() => {
- this.initChart();
- });
- },
- };
- </script>
- <style lang="less" scoped>
- .chart {
- width: 100%;
- height: 100%;
- display: block;
- margin: auto;
- }
- </style>
|