首页 > 其他分享 >动态柱状图

动态柱状图

时间:2024-02-09 17:11:26浏览次数:26  
标签:option -- data 柱状图 var 动态 true Math

案例1

<!--
	此示例下载自 https://echarts.apache.org/examples/zh/editor.html?c=bar-race
-->
<!DOCTYPE html>
<html lang="en" style="height: 100%">
<head>
  <meta charset="utf-8">
</head>
<body style="height: 100%; margin: 0">
  <div id="container" style="width: 400px;height: 350px"></div>

  <script type="text/javascript" src="https://registry.npmmirror.com/echarts/5.4.3/files/dist/echarts.min.js"></script>
  <!-- Uncomment this line if you want to dataTool extension
  <script type="text/javascript" src="https://registry.npmmirror.com/echarts/5.4.3/files/dist/extension/dataTool.min.js"></script>
  -->
  <!-- Uncomment this line if you want to use gl extension
  <script type="text/javascript" src="https://registry.npmmirror.com/echarts-gl/2/files/dist/echarts-gl.min.js"></script>
  -->
  <!-- Uncomment this line if you want to echarts-stat extension
  <script type="text/javascript" src="https://registry.npmmirror.com/echarts-stat/latest/files/dist/ecStat.min.js"></script>
  -->
  <!-- Uncomment this line if you want to use map
  <script type="text/javascript" src="https://registry.npmmirror.com/echarts/4.9.0/files/map/js/china.js"></script>
  <script type="text/javascript" src="https://registry.npmmirror.com/echarts/4.9.0/files/map/js/world.js"></script>
  -->
  <!-- Uncomment these two lines if you want to use bmap extension
  <script type="text/javascript" src="https://api.map.baidu.com/api?v=3.0&ak=YOUR_API_KEY"></script>
  <script type="text/javascript" src="https://registry.npmmirror.com/echarts/5.4.3/files/dist/extension/bmap.min.js"></script>
  -->

  <script type="text/javascript">
    var dom = document.getElementById('container');
    var myChart = echarts.init(dom, null, {
      renderer: 'canvas',
      useDirtyRect: false
    });
    var app = {};
    
    var option;

    const data = [30,9,28,16,61];
// for (let i = 0; i < 5; ++i) {
//   data.push(Math.round(Math.random() * 200));
// }
option = {
  xAxis: {
    max: 'dataMax'
  },
  yAxis: {
    type: 'category',
    data: ['A', 'B', 'C', 'D', 'E'],
    inverse: true,
    animationDuration: 300,
    animationDurationUpdate: 300,
    max: 4 // only the largest 3 bars will be displayed
  },
  series: [
    {
      realtimeSort: true,
      name: 'X',
      type: 'bar',
      data: data,
      label: {
        show: true,
        position: 'right',
        valueAnimation: true
      }
    }
  ],
  legend: {
    show: true
  },
  animationDuration: 0,
  animationDurationUpdate: 3000,
  animationEasing: 'linear',
  animationEasingUpdate: 'linear'
};
const data1 = [3,9,8,6,1
              ,6,9,5,8,7
              ,9,8,2,8,6
              ,8,5,8,9,7
              ,6,2,5,8,7];
var d = 0;
var s = 25
function run() {
  for (var i = 0; i < data.length; ++i) {
    if(d<25){
      data[i] += data1[d];
      console.log(i + "----" + d + "---" + data1[d])
    }else{
      data[i] += 0;
      console.log("data[" + d + "]为null,请刷新");
    }
    d++;
    // if (Math.random() > 0.9) {
    //   data[i] += Math.round(Math.random() * 2000);
    // } else {
    //   data[i] += Math.round(Math.random() * 200);
    // }
  }
  myChart.setOption({
    series: [
      {
        type: 'bar',
        data
      }
    ]
  });
}
setTimeout(function () {
  run();
}, 0);
setInterval(function () {
  run();
}, 3000);

    if (option && typeof option === 'object') {
      myChart.setOption(option);
    }

    window.addEventListener('resize', myChart.resize);
  </script>
</body>
</html>
  • 效果图

标签:option,--,data,柱状图,var,动态,true,Math
From: https://www.cnblogs.com/dogleftover/p/18012534

相关文章

  • 【Python】基于动态残差学习的堆叠式LSTM模型和传统BP在股票预测中的应用
    1.前言本论文探讨了长短时记忆网络(LSTM)和反向传播神经网络(BP)在股票价格预测中的应用。首先,我们介绍了LSTM和BP在时间序列预测中的基本原理和应用背景。通过对比分析两者的优缺点,我们选择了LSTM作为基础模型,因其能够有效处理时间序列数据中的长期依赖关系,在基础LSTM模型的基础上,......
  • 【实用技巧】【Mybatis】自定义的动态 SQL
    1 前言平时我们可能会拼接SQL,尤其是做一些报表的开发或者连表查询的时候,当条件发生变更或者关联关系需要改变的时候,就需要更改代码里的SQL,所以我这里弄了一个简易版的基于Mybatis的动态SQL调用。2 实现主要是Mybatis的动态SQL://controller层@Override@PostMapp......
  • 柱状图(5)
    案例1参考代码如下<!-- 此示例下载自https://echarts.apache.org/examples/zh/editor.html?c=bar-polar-real-estate--><!DOCTYPEhtml><htmllang="en"style="height:100%"><head><metacharset="utf-8"><......
  • 柱状图(4)
    案例1参考代码如下<!-- 此示例下载自https://echarts.apache.org/examples/zh/editor.html?c=dataset-encode0--><!DOCTYPEhtml><htmllang="en"style="height:100%"><head><metacharset="utf-8"></head......
  • 阿里云参编业内首个代码大模型标准丨云原生 2024 年 1 月产品技术动态
    云原生月度动态云原生是企业数字创新的最短路径。《阿里云云原生每月动态》,从趋势热点、产品新功能、服务客户、开源与开发者动态等方面,为企业提供数字化的路径与指南。趋势热点......
  • 柱状图(3)
    案例1参考代码如下<!-- 此示例下载自https://echarts.apache.org/examples/zh/editor.html?c=bar1--><!DOCTYPEhtml><htmllang="en"style="height:100%"><head><metacharset="utf-8"></head><bo......
  • 解析Sermant热插拔能力:服务运行时动态挂载JavaAgent和插件
    本文分享自华为云社区《服务运行时动态挂载JavaAgent和插件——Sermant热插拔能力解析》,作者:华为云高级软件工程师栾文飞一、概述Sermant是基于Java字节码增强技术的无代理服务网格,其利用Java字节码增强技术,为宿主应用程序提供服务治理功能,以解决大规模微服务场景中的服务治理......
  • 柱状图(2)
    案例1参考代码如下<!-- 此示例下载自https://echarts.apache.org/examples/zh/editor.html?c=bar-y-category--><!DOCTYPEhtml><htmllang="en"style="height:100%"><head><metacharset="utf-8"></head&......
  • 柱状图(1)
    案例1参考代码如下<!-- 此示例下载自https://echarts.apache.org/examples/zh/editor.html?c=bar-simple--><!DOCTYPEhtml><htmllang="en"style="height:100%"><head><metacharset="utf-8"></head>......
  • VUE框架CLI组件调用天气接口实现天气界面动态实现和完整工程------VUE框架
    //这句话就等同于我们写的<scriptsrc="vue.js">//这就是在引入vueimportVuefrom'vue';//然后下一步是导入我们的根组件importAppfrom'./App.vue';//导入混入import{mix1}from'./mixin.js';import{mix2}from'./mixin.js';import......