首页 > 其他分享 >amCharts绘制折线图尾部动画

amCharts绘制折线图尾部动画

时间:2024-05-30 14:46:53浏览次数:18  
标签:动画 am5 chart var amCharts series 折线图 new root

  • 代码案例
<!DOCTYPE html>
<html>
  <head>
    <script src="https://cdn.amcharts.com/lib/5/index.js"></script>
    <script src="https://cdn.amcharts.com/lib/5/xy.js"></script>
    <script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
    <style>
        #chartdiv {
          width: 650PX;
          height: 280px;
        }
    </style>
  </head>
  <body>
    <div id="chartdiv"></div>
    
    <script>
        am5.ready(function() {
        
        // Create root element
        // https://www.amcharts.com/docs/v5/getting-started/#Root_element
        var root = am5.Root.new("chartdiv");
        
        
        // Set themes
        // https://www.amcharts.com/docs/v5/concepts/themes/
        root.setThemes([
          am5themes_Animated.new(root)
        ]);
        
        
        // Create chart
        // https://www.amcharts.com/docs/v5/charts/xy-chart/
        var chart = root.container.children.push(am5xy.XYChart.new(root, {
          panX: true,
          panY: true,
          wheelX: "panX",
          wheelY: "zoomX",
          pinchZoomX:true,
          paddingLeft: 0
        }));
        
        chart.get("colors").set("step", 3);
        
        
        // Add cursor
        // https://www.amcharts.com/docs/v5/charts/xy-chart/cursor/
        var cursor = chart.set("cursor", am5xy.XYCursor.new(root, {}));
        cursor.lineY.set("visible", false);
        
        
        // Create axes
        // https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
        var xAxis = chart.xAxes.push(am5xy.DateAxis.new(root, {
          maxDeviation: 0.3,
          baseInterval: {
            timeUnit: "day",
            count: 1
          },
          renderer: am5xy.AxisRendererX.new(root, {
            minorGridEnabled: true,
            minGridDistance: 70
          }),
          tooltip: am5.Tooltip.new(root, {})
        }));
        
        var yAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
          maxDeviation: 0.3,
          renderer: am5xy.AxisRendererY.new(root, {})
        }));
        
        
        // Create series
        // https://www.amcharts.com/docs/v5/charts/xy-chart/series/
        var series = chart.series.push(am5xy.LineSeries.new(root, {
          name: "Series 1",
          xAxis: xAxis,
          yAxis: yAxis,
          valueYField: "value",
          valueXField: "date",
          tooltip: am5.Tooltip.new(root, {
            labelText: "{valueY}"
          })
        }));
        series.strokes.template.setAll({
          strokeWidth: 2,
          strokeDasharray: [3, 3]
        });
        
        // Create animating bullet by adding two circles in a bullet container and
        // animating radius and opacity of one of them.
        series.bullets.push(function(root, series, dataItem) {  
          if (dataItem.dataContext.bullet) {    
            var container = am5.Container.new(root, {});
            var circle0 = container.children.push(am5.Circle.new(root, {
              radius: 5,
              fill: am5.color(0xff0000)
            }));
            var circle1 = container.children.push(am5.Circle.new(root, {
              radius: 5,
              fill: am5.color(0xff0000)
            }));
        
            circle1.animate({
              key: "radius",
              to: 20,
              duration: 1000,
              easing: am5.ease.out(am5.ease.cubic),
              loops: Infinity
            });
            circle1.animate({
              key: "opacity",
              to: 0,
              from: 1,
              duration: 1000,
              easing: am5.ease.out(am5.ease.cubic),
              loops: Infinity
            });
        
            return am5.Bullet.new(root, {
              sprite: container
            })
          }
        })
        
        // Set data
        var data = [{
          date: new Date(2021, 5, 12).getTime(),
          value: 50
        }, {
          date: new Date(2021, 5, 13).getTime(),
          value: 53
        }, {
          date: new Date(2021, 5, 14).getTime(),
          value: 56
        }, {
          date: new Date(2021, 5, 15).getTime(),
          value: 52
        }, {
          date: new Date(2021, 5, 16).getTime(),
          value: 48
        }, {
          date: new Date(2021, 5, 17).getTime(),
          value: 47
        }, {
          date: new Date(2021, 5, 18).getTime(),
          value: 59,
          bullet: true
        }]
        
        series.data.setAll(data);
        
        
        // Make stuff animate on load
        // https://www.amcharts.com/docs/v5/concepts/animations/
        series.appear(1000);
        chart.appear(1000, 100);
        
        }); // end am5.ready()
    </script>     
  </body>
</html>
  • 效果图

标签:动画,am5,chart,var,amCharts,series,折线图,new,root
From: https://www.cnblogs.com/dogleftover/p/18222290

相关文章

  • 添加带有共享元素过渡的合成动画库时,合成项目会崩溃
    我使用的是compose-bom2023.03.00版本,当我尝试添加最新的带有共享元素更新的编译动画模块时,应用程序会在启动时崩溃并显示错误......
  • amCharts绘制折线图和柱状图混合
    代码案例<!DOCTYPEhtml><html><head><scriptsrc="https://cdn.amcharts.com/lib/5/index.js"></script><scriptsrc="https://cdn.amcharts.com/lib/5/xy.js"></script><scriptsrc=&qu......
  • amCharts绘制堆叠面积图
    代码案例<!DOCTYPEhtml><html><head><scriptsrc="https://cdn.amcharts.com/lib/5/index.js"></script><scriptsrc="https://cdn.amcharts.com/lib/5/xy.js"></script><scriptsrc=&qu......
  • amCharts绘制折线图比较
    代码案例<!DOCTYPEhtml><html><head><scriptsrc="https://cdn.amcharts.com/lib/5/index.js"></script><scriptsrc="https://cdn.amcharts.com/lib/5/xy.js"></script><scriptsrc=&qu......
  • AnyChart绘制折线图
    代码案例<html><head><scriptsrc="https://cdn.anychart.com/releases/v8/js/anychart-base.min.js"></script><scriptsrc="https://cdn.anychart.com/releases/v8/js/anychart-ui.min.js"></script......
  • 第三方css动画库
    https://animate.style///安装npminstallanimate.css--save//引入import'animate.css';//使用<h1class="animate__animatedanimate__bounce">Ananimatedelement</h1>//样式名称必须加animate__animated之后    ......
  • Qt 动画类(QPropertyAnimation)
    前言QPropertyAnimation是QT中的一个动画类,用于对目标对象的属性进行动画效果展示。该类继承自QAbstractAnimation类,使用起来非常方便和灵活。一、QPropertyAnimation类介绍QPropertyAnimation可以对任何QObject的子类的属性进行动画的展示,只要该属性是可写的,即存在set方......
  • Adorner实现边框线条动画
    在WPF中,Adorner是一种特殊的装饰层,能够在UI元素之上绘制视觉效果。常用于提供视觉反馈或装饰功能,例如焦点指示、拖放效果等。自定义Adorne类要创建自定义Adorner,需要继承Adorner类并重写OnRender方法。在OnRender方法中,您可以使用DrawingContext绘制自定义图......
  • vue首屏加载动画打包后失效
    本地环境运行时,没有问题,打包后,加载动画没有效果,尝试修改:extract:false后成功。 加载动画示例:index.html中<linkrel="stylesheet"href="static/css/loading.css"/><body><divid="app"><divid="appLoading"><d......
  • matplotlib-折线图的常用操作合集
    序言:感悟:复杂的折线图,都是由基础的折线图慢慢加工绘制而成,我们通过绘制出基本折线图,然后分析需要添加的功能,慢慢润色图形即可完成复杂的图形绘制。折线图:以折线的上升或下降来表示统计数量的增减变化的统计图特点:能够显示数据的变化趋势,反映事物的变化情况。(变化)我们以一个......