使用echarts實現(xiàn)3d柱狀圖+折線圖
效果圖

HTML
需要注意threeDchart一定要設(shè)置寬度高度,不然圖不顯示,然后echarts版本不要太低,不然也不顯示
<div id="threeDchart" class="threeDchart"></div>
js
set3DBarChart2(data) {
var myChart = echarts.init(document.getElementById('middle-right-top-chart'));
data = [2000, 1529, 2251, 1173];
const CubeLeft = echarts.graphic.extendShape({
shape: {
x: 0,
y: 0,
},
buildPath: function (ctx, shape) {
const xAxisPoint = shape.xAxisPoint;
const c0 = [shape.x, shape.y];
const c1 = [shape.x - 9, shape.y - 9];
const c2 = [xAxisPoint[0] - 9, xAxisPoint[1] - 9];
const c3 = [xAxisPoint[0], xAxisPoint[1]];
ctx.moveTo(c0[0], c0[1]).lineTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).closePath();
},
});
const CubeRight = echarts.graphic.extendShape({
shape: {
x: 0,
y: 0,
},
buildPath: function (ctx, shape) {
const xAxisPoint = shape.xAxisPoint;
const c1 = [shape.x, shape.y];
const c2 = [xAxisPoint[0], xAxisPoint[1]];
const c3 = [xAxisPoint[0] + 18, xAxisPoint[1] - 9];
const c4 = [shape.x + 18, shape.y - 9];
ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath();
},
});
const CubeTop = echarts.graphic.extendShape({
shape: {
x: 0,
y: 0,
},
buildPath: function (ctx, shape) {
const c1 = [shape.x, shape.y];
const c2 = [shape.x + 18, shape.y - 9];
const c3 = [shape.x + 9, shape.y - 18];
const c4 = [shape.x - 9, shape.y - 9];
ctx.moveTo(c1[0], c1[1]).lineTo(c2[0], c2[1]).lineTo(c3[0], c3[1]).lineTo(c4[0], c4[1]).closePath();
},
});
echarts.graphic.registerShape('CubeLeft', CubeLeft);
echarts.graphic.registerShape('CubeRight', CubeRight);
echarts.graphic.registerShape('CubeTop', CubeTop);
let option = {
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true,
},
tooltip: {
trigger: 'item',
formatter: (params) => {
let markerArr = params.marker.split('color:');
let marker = markerArr[0] + 'color:#1472FF;"></span>';
dataStr =
`<div style="color:#000A3A">
<div style="color:#666666">${params.name}</div>
<div>` +
marker +
`<span>合同金額</span>` +
`<span style="margin-left:15px">${params.data}萬元</span></div>` +
`</div>`;
return dataStr;
},
},
xAxis: {
type: 'category',
data: ['隆德礦業(yè)', '榆橫煤電', '錦興能源', '不連溝'],
axisTick: {
show: false, // 不顯示坐標(biāo)軸刻度線
},
axisPoint: {
type: 'shadow',
},
axisLabel: {
textStyle: {
color: '#666666',
fontSize: '14',
},
},
},
yAxis: [
{
type: 'value',
min: 0,
name: '萬元',
splitLine: {
show: true,
lineStyle: {
color: '#F0F0F0',
},
},
nameTextStyle: {
color: '#666666',
padding: [0, 30, 0, 0],
},
axisLabel: {
color: '#666666',
},
},
// 右側(cè)縱向坐標(biāo)軸
{
type: 'value',
name: '折線圖值',
position: 'right', // 右側(cè)顯示
splitLine: {
show: false, // 不顯示右側(cè)坐標(biāo)軸的分隔線
},
axisLabel: {
color: '#FF7F50',
},
nameTextStyle: {
color: '#FF7F50',
},
}
],
series: [
// 3D柱狀圖
{
type: 'custom',
renderItem: function (params, api) {
const location = api.coord([api.value(0), api.value(1)]);
return {
type: 'group',
children: [
{
type: 'CubeLeft',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: '#1D6CE2',
},
{
offset: 1,
color: 'rgba(51, 135, 234, 0.10)',
},
]),
},
},
{
type: 'CubeRight',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{
offset: 0,
color: 'rgba(51, 124, 234, 1)',
},
{
offset: 0.3,
color: 'rgba(51, 124, 234, 0.97)',
},
{
offset: 0.7,
color: 'rgba(51, 135, 234, 0.36)',
},
{
offset: 1,
color: 'rgba(51, 143, 234, 0.10)',
},
]),
},
},
{
type: 'CubeTop',
shape: {
api,
xValue: api.value(0),
yValue: api.value(1),
x: location[0],
y: location[1],
xAxisPoint: api.coord([api.value(0), 0]),
},
style: {
fill: '#1472FF',
},
},
],
};
},
data: data,
},
// 折線圖
{
type: 'line',
name: '折線圖',
smooth: true, // 平滑曲線
data: [2000, 1800, 2300, 1500], // 你可以根據(jù)實際數(shù)據(jù)修改這個數(shù)組
lineStyle: {
color: '#FF7F50',
width: 3,
},
symbol: 'circle', // 設(shè)置折線圖標(biāo)記為圓形
symbolSize: 8, // 設(shè)置圓形標(biāo)記的大小
yAxisIndex: 1, // 使用右側(cè)的 y 軸
},
],
};
myChart.setOption(option);
window.addEventListener('resize', function () {
myChart.resize();
});
},
到此這篇關(guān)于使用echarts實現(xiàn)3d柱狀圖+折線圖的文章就介紹到這了,更多相關(guān)echarts 3d柱狀圖和折線圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
從QQ網(wǎng)站中提取的純JS省市區(qū)三級聯(lián)動菜單
在瀏覽網(wǎng)頁過程中發(fā)現(xiàn)QQ自己的JS省市區(qū)三級聯(lián)動。所以研究了一下,就將其提取出來了。他的界面如下,喜歡的朋友可以學(xué)習(xí)下2013-12-12
js 顯示base64編碼的二進(jìn)制流網(wǎng)頁圖片
base64簡單地說,它把一些 8-bit 數(shù)據(jù)翻譯成標(biāo)準(zhǔn) ASCII 字符,我們把圖像文件的內(nèi)容直接寫在了HTML 文件中,這樣做的好處是,節(jié)省了一個HTTP 請求2014-04-04
Easyui Tree獲取當(dāng)前選擇節(jié)點的所有頂級父節(jié)點
這篇文章主要介紹了Easyui Tree獲取當(dāng)前選擇節(jié)點的所有頂級父節(jié)點,以及easyUI Tree顯示選中節(jié)點的所有父節(jié)點的實現(xiàn)代碼,需要的朋友可以參考下2017-02-02
基于JavaScript實現(xiàn)驚艷的打字機(jī)效果
這篇文章主要為大家詳細(xì)介紹了如何使用JavaScript打造驚艷打字機(jī)效果,讓你的文字生動躍動,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-03-03
Javascript實現(xiàn)的類似Google的Div拖動效果代碼
Javascript實現(xiàn)的類似Google的Div拖動效果代碼,需要的朋友可以參考下。2011-08-08
js日期相關(guān)函數(shù)dateAdd,dateDiff,dateFormat等介紹
這篇文章主要介紹了js日期相關(guān)函數(shù)dateAdd,dateDiff,dateFormat等介紹,需要的朋友可以參考下2016-09-09
javascript組合使用構(gòu)造函數(shù)模式和原型模式實例
這篇文章主要介紹了javascript組合使用構(gòu)造函數(shù)模式和原型模式的方法,通過一個簡單實例分析了javascript構(gòu)造函數(shù)模式與原型模式的使用方法,需要的朋友可以參考下2015-06-06

