This commit is contained in:
lnn19986213 2024-04-12 17:30:18 +08:00
parent d00beeec98
commit eba9d53f45
1 changed files with 142 additions and 137 deletions

View File

@ -1,5 +1,5 @@
<template>
<div ref="chart" style="width:100%;height:100%;"></div>
<div ref="chart" style="width:100%;height:200px;"></div>
</template>
<script setup>
@ -8,89 +8,74 @@ import { onMounted, reactive, ref } from "vue";
import * as echarts from 'echarts'
import 'echarts-gl';
const chart =ref(); // DOM
const chart = ref(); // DOM
const colorList = ['#FFE35F','#0081FF','#8ABEDB','#25B9C8','#30EB92','rgba(69, 244, 245)', 'rgba(7, 166, 255)', 'rgba(255, 208, 118)', 'rgba(109, 148, 198)', 'rgba(255, 255, 255)']
const pieData = [
{
name: "A", //
value: 10, //
itemStyle: {
color: "#8fd7fce8",//
},
},
{
name: "B",
value: 8,
itemStyle: {
color: "#466BE7e8",
},
},
{
name: "C",
value: 2,
itemStyle: {
color: "#F4BB29e8",
},
},
{
name: "D",
value: 6,
itemStyle: {
color: "#FF8329",
},
},
{
name: "E",
value: 5,
itemStyle: {
color: "#11EFC7",
},
},
{
name: "F",
value: 1,
itemStyle: {
color: "#006EF5",
},
},
{
name: "G",
value: 5,
itemStyle: {
color: "#846BCE",
},
value: 5
},
]
//
const option = getPie3D(pieData, 0.8)
const serData = pieData.map((dItem, index) => {
return {
...dItem,
value: Number(dItem.value),
itemStyle: {
color: colorList[index]
},
}
})
//
//
const option = getPie3D(serData, 0.8)
// 3D
function getPie3D(pieData, internalDiameterRatio) {
let series = [];
let sumValue = 0;
let startValue = 0;
let endValue = 0;
let legendData = [];
let legendBfb = [];
let k = 1 - internalDiameterRatio;
pieData.sort((a, b) => {
return b.value - a.value;
});
// series-surface()
let k =
typeof internalDiameterRatio !== 'undefined'
? (1 - internalDiameterRatio) / (1 + internalDiameterRatio)
: 1 / 3;
// series-surface
for (let i = 0; i < pieData.length; i++) {
sumValue += pieData[i].value;
let seriesItem = {
//
name:
typeof pieData[i].name === "undefined"
? `series${i}`
: pieData[i].name,
type: "surface",
//
name: typeof pieData[i].name === 'undefined' ? `series${i}` : pieData[i].name,
type: 'surface',
parametric: true,
//线
wireframe: {
show: false,
},
@ -98,22 +83,18 @@ function getPie3D(pieData, internalDiameterRatio) {
pieStatus: {
selected: false,
hovered: false,
k: k,
k: 1 / 10,
},
//()
// center: ['50%', '100%']
};
//
if (typeof pieData[i].itemStyle != "undefined") {
if (typeof pieData[i].itemStyle != 'undefined') {
let itemStyle = {};
typeof pieData[i].itemStyle.color != "undefined"
? (itemStyle.color = pieData[i].itemStyle.color)
: null;
typeof pieData[i].itemStyle.opacity != "undefined"
typeof pieData[i].itemStyle.color != 'undefined' ? (itemStyle.color = pieData[i].itemStyle.color) : null;
typeof pieData[i].itemStyle.opacity != 'undefined'
? (itemStyle.opacity = pieData[i].itemStyle.opacity)
: null;
seriesItem.itemStyle = itemStyle;
}
series.push(seriesItem);
@ -121,10 +102,9 @@ function getPie3D(pieData, internalDiameterRatio) {
// 使 sumValue getParametricEquation
// series-surface series-surface.parametricEquation
legendData = [];
legendBfb = [];
for (let i = 0; i < series.length; i++) {
endValue = startValue + series[i].pieData.value * 1;
endValue = startValue + series[i].pieData.value;
series[i].pieData.startRatio = startValue / sumValue;
series[i].pieData.endRatio = endValue / sumValue;
series[i].parametricEquation = getParametricEquation(
@ -135,23 +115,84 @@ function getPie3D(pieData, internalDiameterRatio) {
k,
series[i].pieData.value
);
startValue = endValue;
let bfb = fomatFloat(series[i].pieData.value / sumValue, 4);
legendData.push({
name: series[i].name,
value: bfb,
});
legendBfb.push({
name: series[i].name,
value: bfb,
});
}
//()
let boxHeight = getHeight3D(series, 15); //3d/
// legendDataseries
startValue = endValue;
legendData.push(series[i].name);
}
// //
// series.push({
// name: 'mouseoutSeries',
// type: 'surface',
// parametric: true,
// wireframe: {
// show: false,
// },
// width: '30px',
// itemStyle: {
// opacity: 0.7,
// color: '#fff',
// },
// parametricEquation: {
// u: {
// min: 0,
// max: Math.PI * 2,
// step: Math.PI / 20,
// },
// v: {
// min: 0,
// max: Math.PI ,
// step: Math.PI / 20,
// },
// x: function (u, v) {
// return ((Math.sin(v) * Math.sin(u) + Math.sin(u)) / Math.PI);
// },
// y: function (u, v) {
// return ((Math.sin(v) * Math.cos(u) + Math.cos(u)) / Math.PI) ;
// },
// z: function (u, v) {
// return Math.cos(v) > 0 ? -4 : -4;
// },
// },
// });
// series.push({
// name: 'mouseoutSeries',
// type: 'surface',
// parametric: true,
// wireframe: {
// show: false,
// },
// itemStyle: {
// opacity: 0.5,
// color: '#fff',
// },
// parametricEquation: {
// u: {
// min: 0,
// max: Math.PI * 2,
// step: Math.PI / 20,
// },
// v: {
// min: 1.5,
// max: 3,
// step: Math.PI / 20,
// },
// x: function (u, v) {
// return ((Math.sin(v) * Math.sin(u) + Math.sin(u)) / Math.PI) *1;
// },
// y: function (u, v) {
// return ((Math.sin(v) * Math.cos(u) + Math.cos(u)) / Math.PI)*1;
// },
// z: function (u, v) {
// return Math.cos(v) > 0 ? -4 : -4;
// },
// },
// });
// legendDataseries
let option = {
// backgroundColor: '#000',
//animation: false,
//
legend: {
data: legendData,
@ -165,35 +206,36 @@ function getPie3D(pieData, internalDiameterRatio) {
"#F4BB29",
"#49C384",
],
width: '30%',
//
// orient: "vertical",
// right: 20,
right: 0,
// bottom: 20,
bottom: '5%',
left: 'center',
top: 'center',
// left: '10px',
//
itemGap: 5,
itemGap: 20,
show: true,
icon: "rect",
itemHeight: 10,
itemWidth: 10,
textStyle: {
//
fontSize: 12,
fontSize: 14,
color: "#B8DDFF",
lineHeight: 20,
},
//
formatter: function (name) {
var target;
for (var i = 0, l = pieData.length; i < l; i++) {
if (pieData[i].name == name) {
target = pieData[i].value;
}
}
return `${name} ${target}`;
},
// formatter: function (name) {
// var target;
// for (var i = 0, l = pieData.length; i < l; i++) {
// if (pieData[i].name == name) {
// target = pieData[i].value;
// }
// }
// return `${name} ${target}`;
// },
},
//
tooltip: {
@ -221,40 +263,28 @@ function getPie3D(pieData, internalDiameterRatio) {
}
},
},
//
xAxis3D: {
min: -1,
max: 1,
},
yAxis3D: {
min: -1,
max: 1,
},
zAxis3D: {
min: -1,
max: 1,
},
//
xAxis3D: {},
yAxis3D: {},
zAxis3D: {},
grid3D: {
show: false,
boxHeight: boxHeight, //
//
left: 0,
top: 0,
viewControl: {
//3d
alpha: 30, //( )
distance: 200, //zoom()
rotateSensitivity: 0, //0
zoomSensitivity: 0, //0
autoRotate: true,
rotateSensitivity: 1, //0
zoomSensitivity: 1, //0
panSensitivity: 0, //0
autoRotate: true, //
alpha: 25, //( )
distance: 120, //zoom()
},
top: '0',
left: '-100',
width: '100%',
show: false,
boxHeight: 20,
},
series: series,
};
return option;
};
}
// series-surface.parametricEquation
function getParametricEquation(startRatio, endRatio, isSelected, isHovered, k, h) {
@ -325,32 +355,7 @@ function getParametricEquation(startRatio, endRatio, isSelected, isHovered, k, h
},
};
};
//
function fomatFloat(num, n) {
var f = parseFloat(num);
if (isNaN(f)) {
return false;
}
f = Math.round(num * Math.pow(10, n)) / Math.pow(10, n); // n
var s = f.toString();
var rs = s.indexOf(".");
//0
if (rs < 0) {
rs = s.length;
s += ".";
}
while (s.length <= rs + n) {
s += "0";
}
return s;
};
//3d
function getHeight3D(series, height) {
series.sort((a, b) => {
return b.pieData.value - a.pieData.value;
});
return (height * 20) / series[0].pieData.value;
}
//
function bindListen(myChart) {
let selectedIndex = "";
@ -505,7 +510,7 @@ onMounted(() => {
// Vue3
var myChart = echarts.init(chart.value)
//
bindListen(myChart)
// bindListen(myChart)
// init(); // vue3.2this
// 使
myChart.setOption(option);