echarts 3D示例 echart, echarts-gl

echarts官网有很多的炫酷的3D模型

来尝试实现下,使用原本的柱状图或者折线图代码创建echarts示例,使用cdn的方式引入echarts

复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.3.0/dist/echarts.min.js"></script>
    <title>ECharts Pie Chart with Click Event</title>
  </head>
  <body>
    <div id="pieChart" style="width: 600px; height: 400px"></div>
    <script>
      const data = [
        { value: 335, name: "Category 1" },
        { value: 310, name: "Category 2" },
        { value: 234, name: "Category 3" },
        { value: 135, name: "Category 4" },
        { value: 1548, name: "Category 5" },
      ];
      // 初始化 ECharts 实例
      const myChart = echarts.init(document.getElementById("pieChart"));
      // 配置饼图
      const option = {
        series: [
          {
            name: "Pie Chart",
            type: "pie",
            radius: "55%",
            center: ["50%", "60%"],
            data: data,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      // 将配置设置到 ECharts 实例中
      myChart.setOption(option);
    </script>
  </body>
</html>

就会得到一个饼图

使用这个案例:Examples - Apache ECharts

在官网案例添加代码查看模型的数据

还需要引入echarts-gl的cdn, 应用中安装echarts-gl,只引入就好,不需要做额外的操作,会自动扩展echarts的功能

复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.2/dist/echarts.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/echarts-gl@2.0.9/dist/echarts-gl.min.js"></script>

    <title>ECharts Pie Chart with Click Event</title>
  </head>
  <body>
    <div
      id="pieChart"
      style="width: 600px; height: 600px; border: 5px solid red"
    ></div>
    <script>
      const list = 这里放从官网复制过来的数组
// 初始化 ECharts 实例
      const myChart = echarts.init(document.getElementById("pieChart"));
      // 将配置设置到 ECharts 实例中
      let option = {
        grid3D: {},
        tooltip: {},
        xAxis3D: {
          type: "category",
        },
        yAxis3D: {
          type: "category",
        },
        zAxis3D: {},
        visualMap: {
          max: 1e8,
          dimension: "Population",
        },
        dataset: {
          dimensions: [
            "Income",
            "Life Expectancy",
            "Population",
            "Country",
            { name: "Year", type: "ordinal" },
          ],
          source: list,
        },
        series: [
          {
            type: "bar3D",
            // symbolSize: symbolSize,
            shading: "lambert",
            encode: {
              x: "Year",
              y: "Country",
              z: "Life Expectancy",
              tooltip: [0, 1, 2, 3, 4],
            },
          },
        ],
      };
      // 将配置设置到 ECharts 实例中
      myChart.setOption(option);
    </script>
  </body>
</html>

看下是很大的

看下效果

相关推荐
奋飛3 分钟前
TypeScript系列:第六篇 - 编写高质量的TS类型
javascript·typescript·ts·declare·.d.ts
老A技术联盟4 分钟前
从小白入门,基于Cursor开发一个前端小程序之Cursor 编程实践与案例分析
前端·小程序
风铃喵游7 分钟前
构建引擎: 打造小程序编译器
前端·小程序·架构
sunbyte12 分钟前
50天50个小项目 (Vue3 + Tailwindcss V4) ✨ | ThemeClock(主题时钟)
前端·javascript·css·vue.js·前端框架·tailwindcss
小飞悟20 分钟前
🎯 什么是模块化?CommonJS 和 ES6 Modules 到底有什么区别?小白也能看懂
前端·javascript·设计
浏览器API调用工程师_Taylor21 分钟前
AOP魔法:一招实现登录弹窗的全局拦截与动态处理
前端·javascript·vue.js
FogLetter22 分钟前
初识图片懒加载:让网页像"懒人"一样聪明加载
前端·javascript
微客鸟窝23 分钟前
一文搞懂NVM管理Node.js:从安装到实战全攻略
前端
归于尽24 分钟前
Cookie、Session、JWT 的前世今生
前端
程序员辉哥25 分钟前
学会在Cursor中使用Rules生成代码后可以躺平了吗?
前端·后端