|
@@ -1,13 +1,14 @@
|
|
|
import React from "react";
|
|
|
import * as echarts from "echarts";
|
|
|
import styles from "../styles/enquire_pie_chart.less";
|
|
|
-import "echarts-gl"; // 如果要用真正的3D图
|
|
|
|
|
|
class Pie3DChart extends React.Component {
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
this.chartRef = React.createRef();
|
|
|
this.chartInstance = null;
|
|
|
+ this.startColor = [126, 206, 244]; // RGB 起点
|
|
|
+ this.endColor = [64, 50, 166]; // RGB 终点
|
|
|
}
|
|
|
|
|
|
componentDidMount() {
|
|
@@ -24,30 +25,48 @@ class Pie3DChart extends React.Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ colorScale(index, total) {
|
|
|
+ const { startColor, endColor } = this;
|
|
|
+ return `rgb(${Math.round(
|
|
|
+ startColor[0] + ((endColor[0] - startColor[0]) * index) / (total - 1)
|
|
|
+ )},
|
|
|
+ ${Math.round(
|
|
|
+ startColor[1] +
|
|
|
+ ((endColor[1] - startColor[1]) * index) / (total - 1)
|
|
|
+ )},
|
|
|
+ ${Math.round(
|
|
|
+ startColor[2] +
|
|
|
+ ((endColor[2] - startColor[2]) * index) / (total - 1)
|
|
|
+ )})`;
|
|
|
+ }
|
|
|
+
|
|
|
initChart() {
|
|
|
if (!this.chartInstance) {
|
|
|
this.chartInstance = echarts.init(this.chartRef.current);
|
|
|
}
|
|
|
+
|
|
|
const option = {
|
|
|
- color: ["#7ECEF4", "#2EA7E0", "#036EB8", "#004E9D"], // 统一调色板
|
|
|
+ color: this.props.data.map((item, index) =>
|
|
|
+ this.colorScale(index, this.props.data.length)
|
|
|
+ ), // 自动生成渐变颜色
|
|
|
+ tooltip: {
|
|
|
+ trigger: "item",
|
|
|
+ },
|
|
|
legend: {
|
|
|
- itemGap: 30,
|
|
|
+ itemGap: 35,
|
|
|
bottom: 0,
|
|
|
textStyle: { color: "#fff" },
|
|
|
},
|
|
|
series: [
|
|
|
{
|
|
|
- // name: "访问来源",
|
|
|
+ // name: 'Access From',
|
|
|
type: "pie",
|
|
|
- radius: ["0", "60%"],
|
|
|
- center: ["50%", "45%"],
|
|
|
+ radius: ["40%", "70%"],
|
|
|
avoidLabelOverlap: false,
|
|
|
itemStyle: {
|
|
|
- borderRadius: 5,
|
|
|
- borderColor: "#0b0c1b",
|
|
|
- borderWidth: 3,
|
|
|
- // shadowBlur: 20,
|
|
|
- // shadowColor: "rgba(0, 0, 0, 0.5)",
|
|
|
+ borderRadius: 10,
|
|
|
+ // borderColor: "#fff",
|
|
|
+ borderWidth: 2,
|
|
|
},
|
|
|
label: {
|
|
|
show: false,
|
|
@@ -56,12 +75,14 @@ class Pie3DChart extends React.Component {
|
|
|
emphasis: {
|
|
|
label: {
|
|
|
show: true,
|
|
|
- fontSize: "16",
|
|
|
+ fontSize: 16,
|
|
|
fontWeight: "bold",
|
|
|
},
|
|
|
},
|
|
|
- // labelLine: { show: false },
|
|
|
- data: this.props.data
|
|
|
+ labelLine: {
|
|
|
+ show: false,
|
|
|
+ },
|
|
|
+ data: this.props.data,
|
|
|
},
|
|
|
],
|
|
|
};
|