echart 3D柱状图
时间: 2023-05-20 14:06:23 浏览: 103
如何实现?
要实现 Echart 3D 柱状图,需要使用 Echart 的 3D 模块。首先,需要在 HTML 文件中引入 Echart 的 JS 文件和 3D 模块文件。然后,在 JS 文件中定义一个 Echart 实例,并设置其类型为 3D 柱状图。接着,需要设置数据和样式,包括柱状图的颜色、高度、宽度等。最后,将 Echart 实例渲染到 HTML 页面中即可。以下是一个简单的示例代码:
```javascript
// 引入 Echart JS 文件和 3D 模块文件
<script src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts-gl/dist/echarts-gl.min.js"></script>
// 定义 Echart 实例
var myChart = echarts.init(document.getElementById('myChart'));
// 设置类型为 3D 柱状图
myChart.setOption({
tooltip: {},
visualMap: {
max: 20,
inRange: {
color: ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']
}
},
xAxis3D: {
type: 'category',
data: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I']
},
yAxis3D: {
type: 'category',
data: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
},
zAxis3D: {
type: 'value'
},
grid3D: {
boxWidth: 200,
boxDepth: 80,
viewControl: {
// projection: 'orthographic'
},
light: {
main: {
intensity: 1.2,
shadow: true
},
ambient: {
intensity: 0.3
}
}
},
series: [{
type: 'bar3D',
data: [
['A', 'Monday', 10],
['B', 'Monday', 8],
['C', 'Monday', 7],
['D', 'Monday', 6],
['E', 'Monday', 5],
['F', 'Monday', 4],
['G', 'Monday', 3],
['H', 'Monday', 2],
['I', 'Monday', 1],
['A', 'Tuesday', 2],
['B', 'Tuesday', 3],
['C', 'Tuesday', 3],
['D', 'Tuesday', 4],
['E', 'Tuesday', 5],
['F', 'Tuesday', 6],
['G', 'Tuesday', 7],
['H', 'Tuesday', 8],
['I', 'Tuesday', 9],
['A', 'Wednesday', 10],
['B', 'Wednesday', 9],
['C', 'Wednesday', 8],
['D', 'Wednesday', 7],
['E', 'Wednesday', 6],
['F', 'Wednesday', 5],
['G', 'Wednesday', 4],
['H', 'Wednesday', 3],
['I', 'Wednesday', 2],
['A', 'Thursday', 1],
['B', 'Thursday', 2],
['C', 'Thursday', 3],
['D', 'Thursday', 4],
['E', 'Thursday', 5],
['F', 'Thursday', 6],
['G', 'Thursday', 7],
['H', 'Thursday', 8],
['I', 'Thursday', 9],
['A', 'Friday', 10],
['B', 'Friday', 9],
['C', 'Friday', 8],
['D', 'Friday', 7],
['E', 'Friday', 6],
['F', 'Friday', 5],
['G', 'Friday', 4],
['H', 'Friday', 3],
['I', 'Friday', 2],
['A', 'Saturday', 1],
['B', 'Saturday', 2],
['C', 'Saturday', 3],
['D', 'Saturday', 4],
['E', 'Saturday', 5],
['F', 'Saturday', 6],
['G', 'Saturday', 7],
['H', 'Saturday', 8],
['I', 'Saturday', 9],
['A', 'Sunday', 10],
['B', 'Sunday', 9],
['C', 'Sunday', 8],
['D', 'Sunday', 7],
['E', 'Sunday', 6],
['F', 'Sunday', 5],
['G', 'Sunday', 4],
['H', 'Sunday', 3],
['I', 'Sunday', 2]
],
shading: 'lambert',
label: {
textStyle: {
fontSize: 16,
borderWidth: 1
}
},
emphasis: {
label: {
textStyle: {
fontSize: 20,
color: '#900'
}
},
itemStyle: {
color: '#900'
}
}
}]
});
// 渲染 Echart 实例到 HTML 页面中
myChart.render();
```
阅读全文