vue3+Echarts實(shí)現(xiàn)立體柱狀圖的示例代碼
Echarts柱狀圖中文網(wǎng):https://echarts.apache.org/examples/zh/index.html#chart-type-bar
效果展示:

主要實(shí)現(xiàn)過(guò)程是三部分的組合,最上面是一個(gè)橢圓,中間是正常的柱子,下方再加上一個(gè)橢圓,就出來(lái)立體的效果。
分別展示三段組合代碼:
頂部的橢圓形(象形柱圖):pictorialBar
{
type: "pictorialBar", // pictorialBar(象形柱圖)
symbolSize: [20, 5], // 圖形的大小用數(shù)組分別比表示寬和高,也樂(lè)意設(shè)置成10相當(dāng)于[10,10]
symbolOffset: [0, 3], // 圖形相對(duì)于原本位置的偏移
z: 12, // 象形柱狀圖組件的所有圖形的 z 值.控制圖形的前后順序.z 值小的圖形會(huì)被 z 值大的圖形覆蓋.
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: "#17A8A0",
},
{
offset: 1,
color: "#5AEA80",
},
]),
},
data: columnData.value,
},
中間的柱子:bar
{
name: "發(fā)電量",
type: "bar",
barWidth: 20,
itemStyle: {
color: {
x: 0,
y: 0,
x2: 0,
y2: 1,
type: "linear",
global: false,
colorStops: [
{
offset: 0,
color: "#17A8A0",
},
{
offset: 1,
color: "#5AEA80",
},
],
},
},
data: columnData.value,
label: {
show: true,
position: "top",
color: "#FFFFFF",
fontSize: 14,
},
},
底部的橢圓形(象形柱圖):pictorialBar
{
type: "pictorialBar",
symbolSize: [20, 10],
symbolOffset: [0, -5],
z: 12,
symbolPosition: "end",
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: "#17A8A0",
},
{
offset: 1,
color: "#5AEA80",
},
]),
},
data: columnData.value,
},
整體代碼如下:
<template>
<div
id="stereoscopicChart"
style="width: 100%; height: 270px"
></div>
</template>
<script setup lang="ts">
import { onMounted, ref } from "vue";
import * as echarts from "echarts";
// 橫坐標(biāo)data數(shù)據(jù)
const xData = ref([
"1月",
"2月",
"3月",
"4月",
"5月",
"6月",
"7月",
"8月",
"9月",
"10月",
"11月",
"12月",
]);
// 柱狀data數(shù)據(jù)
const columnData = ref([
394, 194, 287, 189, 139, 420, 385, 239, 279, 379, 277, 237,
]);
let myStereoscopicChart: echarts.ECharts | null = null;
const showStereoscopicEcharts = () => {
if (!myStereoscopicChart) {
const stereoscopicChartDom = document.getElementById("stereoscopicChart");
myStereoscopicChart = echarts.init(stereoscopicChartDom);
}
const stereoscopicOption = {
tooltip: {
trigger: "axis",
formatter: "
發(fā)電量 {c}kWh",
type: "line",
axisPointer: {
lineStyle: {
color: "#17A8A0",
},
},
backgroundColor: "rgba(7,18,26, 1)",
borderWidth: 0,
textStyle: {
color: "#fff",
fontSize: 14,
align: "left",
},
},
// 圖例
legend: {
show: false,
},
// 圖表位置
grid: {
left: "5%",
right: "5%",
top: "18%",
bottom: "0%",
containLabel: true,
},
xAxis: [
{
type: "category",
axisLine: {
lineStyle: {
color: "#415264",
width: 1,
type: "solid",
},
},
axisLabel: {
color: "rgba(255,255,255,0.6)",
fontSize: 12,
},
axisTick: {
show: false,
},
data: xData.value,
},
],
yAxis: [
{
name: "發(fā)電量(kWh)",
type: "value",
axisTick: {
show: false,
},
axisLine: {
lineStyle: {
color: "rgba(255,255,255,0.2)",
},
},
axisLabel: {
color: "rgba(255,255,255,0.2)",
fontSize: 12,
},
splitLine: {
lineStyle: {
color: "rgba(255,255,255,0.2)",
type: "dashed",
},
},
},
],
series: [
// 底部的橢圓形(象形柱圖):pictorialBar
{
type: "pictorialBar", // pictorialBar(象形柱圖)
symbolSize: [20, 5], // 圖形的大小用數(shù)組分別比表示寬和高,也樂(lè)意設(shè)置成10相當(dāng)于[10,10]
symbolOffset: [0, 3], // 圖形相對(duì)于原本位置的偏移
z: 12, // 象形柱狀圖組件的所有圖形的 z 值.控制圖形的前后順序.z 值小的圖形會(huì)被 z 值大的圖形覆蓋.
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: "#17A8A0",
},
{
offset: 1,
color: "#5AEA80",
},
]),
},
data: columnData.value,
},
{
name: "發(fā)電量",
type: "bar",
barWidth: 20,
itemStyle: {
color: {
x: 0,
y: 0,
x2: 0,
y2: 1,
type: "linear",
global: false,
colorStops: [
{
offset: 0,
color: "#17A8A0",
},
{
offset: 1,
color: "#5AEA80",
},
],
},
},
data: columnData.value,
label: {
show: true,
position: "top",
color: "#FFFFFF",
fontSize: 14,
},
},
{
type: "pictorialBar",
symbolSize: [20, 10],
symbolOffset: [0, -5],
z: 12,
symbolPosition: "end",
itemStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: "#17A8A0",
},
{
offset: 1,
color: "#5AEA80",
},
]),
},
data: columnData.value,
},
],
};
stereoscopicOption && myStereoscopicChart.setOption(stereoscopicOption);
};
const resizeChart = () => {
if (myStereoscopicChart) {
myStereoscopicChart.resize();
}
};
onMounted(() => {
showStereoscopicEcharts();
window.addEventListener("resize", resizeChart);
});
</script>
到此這篇關(guān)于vue3+Echarts實(shí)現(xiàn)立體柱狀圖的示例代碼的文章就介紹到這了,更多相關(guān)vue3 Echarts 立體柱狀圖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue循環(huán)el-button實(shí)現(xiàn)點(diǎn)擊哪個(gè)按鈕,那個(gè)按鈕就變色
這篇文章主要介紹了vue循環(huán)el-button實(shí)現(xiàn)點(diǎn)擊哪個(gè)按鈕,那個(gè)按鈕就變色問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10
vue quill editor 使用富文本添加上傳音頻功能
vue-quill-editor 是vue項(xiàng)目中常用的富文本插件,其功能能滿足大部分的項(xiàng)目需求。這篇文章主要介紹了vue-quill-editor 富文本添加上傳音頻功能,需要的朋友可以參考下2020-01-01
vue + elementUI實(shí)現(xiàn)省市縣三級(jí)聯(lián)動(dòng)的方法示例
這篇文章主要介紹了vue + elementUI實(shí)現(xiàn)省市縣三級(jí)聯(lián)動(dòng)的方法示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
Vue同一路由強(qiáng)制刷新頁(yè)面的實(shí)現(xiàn)過(guò)程
這篇文章主要介紹了解決VUE同一路由強(qiáng)制刷新頁(yè)面的問(wèn)題,本文給大家分享實(shí)現(xiàn)過(guò)程,通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-08-08
Vue應(yīng)用中504錯(cuò)誤(Gateway timeout)的原因與解決方法
在Vue前端應(yīng)用中遇到504代理錯(cuò)誤通常是由于請(qǐng)求在到達(dá)服務(wù)器之前超時(shí),504錯(cuò)誤表示網(wǎng)關(guān)超時(shí),可能由后端服務(wù)響應(yīng)慢、網(wǎng)絡(luò)問(wèn)題、代理配置錯(cuò)誤、請(qǐng)求負(fù)載過(guò)大、前端請(qǐng)求超時(shí)設(shè)置不當(dāng)、服務(wù)器資源不足或第三方服務(wù)問(wèn)題引起2024-09-09
某些場(chǎng)景下建議vue query代替pinia原理解析
這篇文章主要為大家介紹了某些場(chǎng)景下建議vue-query代替pinia原理解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
Vue.js原理分析之nextTick實(shí)現(xiàn)詳解
這篇文章主要給大家介紹了關(guān)于Vue.js原理分析之nextTick實(shí)現(xiàn)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09
vue使用axios跨域請(qǐng)求數(shù)據(jù)問(wèn)題詳解
這篇文章主要為大家詳細(xì)介紹了vue使用axios跨域請(qǐng)求數(shù)據(jù)的問(wèn)題,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10

