最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Echarts?3D散點圖實戰(zhàn)案例

 更新時間:2023年11月06日 16:26:01   作者:博客zhu虎康  
這篇文章主要給大家介紹了關于Echarts?3D散點圖的相關資料, Echarts散點圖是一種常用的數(shù)據(jù)可視化圖表類型,用于展示兩個或多個維度的數(shù)據(jù)分布情況,需要的朋友可以參考下

1、以下是一個 html + echarts的案例

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ECharts 3D Scatter Plot Demo</title>
    <!-- 引入 ECharts -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.9.0/echarts.min.js"></script>
</head>
<body>
    <!-- 繪制 3D 散點圖的容器 -->
    <div id="scatter-chart" style="width: 720px; height: 480px;"></div>
    <script>
        // 3D 散點圖的數(shù)據(jù)格式,包含三個維度坐標信息和額外的數(shù)據(jù)
        var data = [
            [10, 20, 30, 'data1'],
            [20, 40, 10, 'data2'],
            [30, 60, 20, 'data3'],
            [40, 80, 40, 'data4'],
            [50, 100, 30, 'data5'],
            [60, 120, 50, 'data6']
        ];
        // 基于準備好的dom,初始化echarts實例
        var myChart = echarts.init(document.getElementById('scatter-chart'));
        // 繪制3D散點圖
        myChart.setOption({
            // 圖表標題
            title: {
                text: 'ECharts 3D Scatter Plot Demo'
            },
            // 圖表類型,3D散點圖
            series: [{
                type: 'scatter3D',
                // 數(shù)據(jù)
                data: data,
                // 點大小
                symbolSize: 20,
                // 控制點的透明度
                itemStyle: {
                    opacity: 0.8
                }
            }],
            // X軸的3D坐標系,相關設置
            xAxis3D: {
                type: 'value',
                scale: true
            },
            // Y軸的3D坐標系,相關設置
            yAxis3D: {
                type: 'value',
                scale: true
            },
            // Z軸的3D坐標系,相關設置
            zAxis3D: {
                type: 'value',
                scale: true
            },
            // 旋轉3D圖表
            grid3D: {
                viewControl: {
                    // 攝像機視角
                    alpha: 45,
                    beta: 30
                }
            }
        });
    </script>
</body>
</html>

2、以下是一個 vue+echarts 的案例

index.vue

<!--
 * @Description: file content
 * @Version: 2.0
 * @Autor: Hu Kang
 * @Date: 2023-04-04 18:49:29
 * @LastEditors: Hu Kang
 * @LastEditTime: 2023-05-10 15:24:28
 * @FilePath: \src\views\page\echarts\index.vue
-->
<template>
  <div class="content">
  <template #title> <icon-home /> 散點圖</template>
            <div>
              <input type="file" id="inputfile" />
              <button @click="readFile()">讀取文件</button>
            </div>
            <splashes v-if="activeKey === '7'" :chart-data="chartData" />
  </div>
</template>
<script setup lang="ts">
import {
  ref,
  reactive,
  watch,
  watchEffect,
  computed,
  getCurrentInstance,
  nextTick,
  defineComponent,
  toRefs,
} from 'vue';
import splashes from './components/splashes.vue';
const chartData = ref()
function readFile() {
  var file = document.getElementById('inputfile').files[0]; // 獲取選擇的文件
  if (!file) return;
  var reader = new FileReader();
  reader.readAsText(file, 'UTF-8'); // 以文本格式讀取文件
  reader.onload = function (event) {
    // 取到的文件內(nèi)容
    chartData.value = JSON.parse(event.target.result);
  }
}
</script>
<style scoped lang="less">
.box-card-component {
  padding: 0px 20px;
  .card-header {
    color: #409eff;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
    // height: 20px;
  }
}
</style>

splashes.vue

<!--
 * @Description: file content
 * @Version: 2.0
 * @Autor: Hu Kang
 * @Date: 2023-05-09 16:34:49
 * @LastEditors: Hu Kang
 * @LastEditTime: 2023-05-10 15:08:35
 * @FilePath: \src\views\page\echarts\components\splashes.vue
-->

<template>
  <div ref="echartsRef" class="content" id="my-div"> </div>
</template>

<script setup lang="ts">
import {
  ref,
  reactive,
  watch,
  watchEffect,
  computed,
  getCurrentInstance,
  nextTick,
  defineComponent,
  toRefs,
  onMounted,
} from 'vue';
import * as echarts from 'echarts';
import 'echarts-gl'
import { RequestType } from 'cesium';

const props = defineProps({
  // 數(shù)據(jù) chart-data
  chartData: {
    type: Object,
    require: true,
    default: () => {
      return {}
    }
  },
  width: {
    type: String,
    default: '98%'
  },
  height: {
    type: String,
    default: '67vh'
  },
  autoResize: {
    type: Boolean,
    default: true
  }
})
const { chartData } = toRefs(props)

// 3D 散點圖的數(shù)據(jù)格式,包含三個維度坐標信息和額外的數(shù)據(jù)
var data = [
  [10, 20, 30, 'data1'],
  [20, 40, 10, 'data2'],
  [30, 60, 20, 'data3'],
  [40, 80, 40, 'data4'],
  [50, 100, 30, 'data5'],
  [60, 120, 50, 'data6']
];

var sizeValue = '57%';
var symbolSize = 2.5;
const echartsData = reactive({
  option: {
    // 圖表標題
    title: {
      text: 'ECharts 3D Scatter Plot Demo',
      subtext: '3D散點圖繪制情況',
      left: 'center'
    },
    // 圖表類型,3D散點圖
    series: [{
      type: 'scatter3D',
      // 數(shù)據(jù)
      data: data,
      // 點大小
      symbolSize: 10,
      // 控制點的透明度
      itemStyle: {
        opacity: 0.8
      }
    },
    {
      type: 'scatter',
      symbolSize: symbolSize,
      xAxisIndex: 0,
      yAxisIndex: 0,
      encode: {
        x: 'Income',
        y: 'Life Expectancy',
        tooltip: [0, 1, 2, 3, 4]
      }
    },
    {
      type: 'scatter',
      symbolSize: symbolSize,
      xAxisIndex: 1,
      yAxisIndex: 1,
      encode: {
        x: 'Country',
        y: 'Income',
        tooltip: [0, 1, 2, 3, 4]
      }
    },
    {
      type: 'scatter',
      symbolSize: symbolSize,
      xAxisIndex: 2,
      yAxisIndex: 2,
      encode: {
        x: 'Income',
        y: 'Population',
        tooltip: [0, 1, 2, 3, 4]
      }
    },
    {
      type: 'scatter',
      symbolSize: symbolSize,
      xAxisIndex: 3,
      yAxisIndex: 3,
      encode: {
        x: 'Life Expectancy',
        y: 'Population',
        tooltip: [0, 1, 2, 3, 4]
      }
    }],
    // X軸的3D坐標系,相關設置
    xAxis3D: {
      type: 'value',
      scale: true
    },
    // Y軸的3D坐標系,相關設置
    yAxis3D: {
      type: 'value',
      scale: true
    },
    // Z軸的3D坐標系,相關設置
    zAxis3D: {
      type: 'value',
      scale: true
    },
    // 旋轉3D圖表
    grid3D: {
      viewControl: {
        // 攝像機視角
        alpha: 45,
        beta: 30
      }
    },
    grid: [
      { left: '2%', width: '20%', bottom: sizeValue },
      { left: '80%', width: '20%', bottom: sizeValue },
      { left: '2%', width: '20%', top: sizeValue },
      { left: '80%', width: '20%', top: sizeValue }
    ],
    xAxis: [
      {
        type: 'value',
        gridIndex: 0,
        name: 'Income',
        axisLabel: { rotate: 50, interval: 0 }
      },
      {
        type: 'category',
        gridIndex: 1,
        name: 'Country',
        boundaryGap: false,
        axisLabel: { rotate: 50, interval: 0 }
      },
      {
        type: 'value',
        gridIndex: 2,
        name: 'Income',
        axisLabel: { rotate: 50, interval: 0 }
      },
      {
        type: 'value',
        gridIndex: 3,
        name: 'Life Expectancy',
        axisLabel: { rotate: 50, interval: 0 }
      }
    ],
    yAxis: [
      { type: 'value', gridIndex: 0, name: 'Life Expectancy' },
      { type: 'value', gridIndex: 1, name: 'Income' },
      { type: 'value', gridIndex: 2, name: 'Population' },
      { type: 'value', gridIndex: 3, name: 'Population' }
    ],
    dataset: {
      dimensions: [
        'Income',
        'Life Expectancy',
        'Population',
        'Country',
        { name: 'Year', type: 'ordinal' }
      ],
      source: []
    },

  }
})
const { option } = toRefs(echartsData);
const echartsRef = ref<string>();
let echartInstance;


watch(
  chartData,
  (newValue) => {
    if (newValue && newValue.data?.length) {
      option.value.dataset.source = newValue.data
    }

  },
  { deep: true, immediate: true }
)

watch(
  option,
  (newValue) => {
    echartInstance.setOption(newValue);
  },
  { deep: true }
)

onMounted(() => {
  echartInstance = echarts.init(echartsRef.value, 'macarons', { renderer: 'webgl' });
  echartInstance.setOption(option.value);
});
</script>

<style lang="less" scoped>
.content {
  width: 100%;
  height: 90vh;
}
</style>

使用前需要先安裝一下依賴

npm install echarts-gl --saveyarn add echarts-gl

安裝完成后,在代碼中引入 echarts-gl 包:

import echarts from 'echarts';
import 'echarts-gl';

接下來,你就可以在代碼中使用 scatter3D 組件了,具體的使用方法可以參考官方文檔。

控制臺如果有提示: geo3D exists,是因為你的版本太低了,可以升級一下

升級

npm update echarts-glyarn upgrade echarts-gl

如果你是通過 CDN 引入 echarts 和 echarts-gl,可以嘗試使用最新的鏈接,如:

<script src="https://cdn.jsdelivr.net/npm/echarts@latest/dist/echarts.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/echarts-gl@latest/dist/echarts-gl.min.js"></script>

如果以上方法無效,你還可以嘗試手動清空瀏覽器緩存并重新加載頁面,或者刪除舊版本 echarts-gl,重新安裝最新版本。

總結

到此這篇關于Echarts 3D散點圖的文章就介紹到這了,更多相關Echarts 3D散點圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • js編寫三級聯(lián)動簡單案例

    js編寫三級聯(lián)動簡單案例

    這篇文章主要為大家分享了JavaScript編寫三級聯(lián)動簡單案例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • bootstrap 通過加減按鈕實現(xiàn)輸入框組功能

    bootstrap 通過加減按鈕實現(xiàn)輸入框組功能

    這篇文章主要介紹了bootstrap 輸入框組 通過加減按鈕來增加刪除內(nèi)嵌輸入框組,當我點擊 + 按鈕時,會添加一行輸入框組;當點擊 - 按鈕時,會刪除這一行輸入框組。具體實現(xiàn)代碼大家參考下本文
    2017-11-11
  • js處理自己不能定義二維數(shù)組的方法詳解

    js處理自己不能定義二維數(shù)組的方法詳解

    本篇文章主要是對js處理自己不能定義二維數(shù)組的方法進行了介紹,需要的朋友可以過來參考下,希望讀大家有所幫助
    2014-03-03
  • 淺析JavaScript中五種模塊系統(tǒng)的使用

    淺析JavaScript中五種模塊系統(tǒng)的使用

    模塊系統(tǒng)是什么?簡單來說,其實就是我們在一個文件里寫代碼,聲明一些可以導出的字段,然后另一個文件可以將其導入并使用。今天我們來聊聊?JavaScript?的模塊系統(tǒng),感興趣的可以了解一下
    2022-11-11
  • JS DOM 操作實現(xiàn)代碼

    JS DOM 操作實現(xiàn)代碼

    JS DOM 操作實現(xiàn)代碼,學習dom操作的朋友可以參考下。
    2010-08-08
  • 二叉樹先序遍歷的非遞歸算法具體實現(xiàn)

    二叉樹先序遍歷的非遞歸算法具體實現(xiàn)

    這篇文章主要介紹了二叉樹先序遍歷的非遞歸算法,有需要的朋友可以參考一下
    2014-01-01
  • JS實現(xiàn)的另類手風琴效果網(wǎng)頁內(nèi)容切換代碼

    JS實現(xiàn)的另類手風琴效果網(wǎng)頁內(nèi)容切換代碼

    這篇文章主要介紹了JS實現(xiàn)的另類手風琴效果網(wǎng)頁內(nèi)容切換代碼,通過JavaScript響應鼠標事件動態(tài)操作頁面元素樣式屬性實現(xiàn)手風琴效果,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-09-09
  • JavaScript設計模式策略模式案例分享

    JavaScript設計模式策略模式案例分享

    這篇文章主要介紹了JavaScript設計模式策略模式案例分享,策略設計模式就是指一個問題匹配多個解決方法,不一定要用到哪一個,而且有可能隨時增加多個方案
    2022-06-06
  • Javascript雙重否定運算的具體使用

    Javascript雙重否定運算的具體使用

    本文介紹了JavaScript中的雙位NOT運算符,將非數(shù)字類型轉換為0,以及整數(shù)參數(shù)和Array.prototype.indexOf方法中的應用,感興趣的可以了解一下
    2025-07-07
  • js點擊圖片實現(xiàn)查看大圖簡單方法

    js點擊圖片實現(xiàn)查看大圖簡單方法

    今天開發(fā)的時候,遇到要點擊縮略圖之后顯示圖片的大圖查看,所以本文給大家分享下,這篇文章主要給大家介紹了關于js點擊圖片實現(xiàn)查看大圖的簡單方法,需要的朋友可以參考下
    2023-06-06

最新評論

玉环县| 阿拉尔市| 广宗县| 怀仁县| 黄平县| 乐东| 安溪县| 霞浦县| 鲁甸县| 廉江市| 灌南县| 信宜市| 余姚市| 开封县| 沈丘县| 水富县| 无棣县| 张家港市| 威海市| 巨鹿县| 紫阳县| 永平县| 兰西县| 英山县| 河南省| 东明县| 溧水县| 南京市| 松溪县| 寻乌县| 葵青区| 辰溪县| 许昌县| 新兴县| 珲春市| 望都县| 江川县| 博爱县| 阆中市| 娄烦县| 罗江县|