首页 > 其他分享 >amCharts绘制堆叠面积图

amCharts绘制堆叠面积图

时间:2024-05-30 12:03:23浏览次数:21  
标签:绘制 chart new 堆叠 bicycles amCharts year root am5

  • 代码案例
<!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
        }));
        
        
        chart.set("colors", am5.ColorSet.new(root, {
          step: 2,
          colors: [
            am5.color(0x73556E),
            am5.color(0x9FA1A6),
            am5.color(0xF2AA6B),
            am5.color(0xF28F6B),
            am5.color(0xA95A52),
            am5.color(0xE35B5D),
            am5.color(0xFFA446)
          ]
        }))
        
        
        // Add cursor
        // https://www.amcharts.com/docs/v5/charts/xy-chart/cursor/
        var cursor = chart.set("cursor", am5xy.XYCursor.new(root, {
          behavior: "none"
        }));
        cursor.lineY.set("visible", false);
        
        
        // The data
        var data = [{
          "year": "2001",
          "cars": 1298,
          "motorcycles": 680,
          "bicycles": 101
        }, {
          "year": "2002",
          "cars": 1275,
          "motorcycles": 664,
          "bicycles": 97
        }, {
          "year": "2003",
          "cars": 1246,
          "motorcycles": 648,
          "bicycles": 93
        }, {
          "year": "2004",
          "cars": 1318,
          "motorcycles": 697,
          "bicycles": 111
        }, {
          "year": "2005",
          "cars": 1213,
          "motorcycles": 633,
          "bicycles": 87
        }, {
          "year": "2006",
          "cars": 1199,
          "motorcycles": 521,
          "bicycles": 145
        }, {
          "year": "2007",
          "cars": 1110,
          "motorcycles": 310,
          "bicycles": 91
        }, {
          "year": "2008",
          "cars": 1165,
          "motorcycles": 425,
          "bicycles": 120
        }, {
          "year": "2009",
          "cars": 1145,
          "motorcycles": 319,
          "bicycles": 102
        }, {
          "year": "2010",
          "cars": 1163,
          "motorcycles": 201,
          "bicycles": 145
        }, {
          "year": "2011",
          "cars": 1180,
          "motorcycles": 285,
          "bicycles": 100
        }, {
          "year": "2012",
          "cars": 1159,
          "motorcycles": 255,
          "bicycles": 122
        }];
        
        
        // Create axes
        // https://www.amcharts.com/docs/v5/charts/xy-chart/axes/
        var xAxis = chart.xAxes.push(am5xy.CategoryAxis.new(root, {
          categoryField: "year",
          startLocation: 0.5,
          endLocation: 0.5,
          renderer: am5xy.AxisRendererX.new(root, {
            minorGridEnabled: true,
            minGridDistance: 70
          }),
          tooltip: am5.Tooltip.new(root, {})
        }));
        
        xAxis.data.setAll(data);
        
        var yAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
          renderer: am5xy.AxisRendererY.new(root, {})
        }));
        
        // Add series
        // https://www.amcharts.com/docs/v5/charts/xy-chart/series/
        
        function createSeries(name, field) {
          var series = chart.series.push(am5xy.SmoothedXLineSeries.new(root, {
            name: name,
            xAxis: xAxis,
            yAxis: yAxis,
            valueYField: field,
            categoryXField: "year",
            stacked: true,
            stroke: am5.color(0xffffff),
            tooltip: am5.Tooltip.new(root, {
              pointerOrientation: "horizontal",
              labelText: "[bold]{name}[/]\n{categoryX}: {valueY}"
            })
          }));
        
          series.strokes.template.setAll({
            strokeWidth: 4,
            strokeOpacity: 1,
            shadowBlur: 2,
            shadowOffsetX: 2,
            shadowOffsetY: 2,
            shadowColor: am5.color(0x000000),
            shadowOpacity: 0.1
          })
        
          series.fills.template.setAll({
            fillOpacity: 1,
            visible: true,
        
            fillPattern: am5.GrainPattern.new(root, {
              maxOpacity: 0.15,
              density: 0.5,
              colors: [am5.color(0x000000), am5.color(0x000000), am5.color(0xffffff)]
            })
        
          });
        
          series.data.setAll(data);
          series.appear(1000);
        }
        
        createSeries("Cars", "cars");
        createSeries("Motorcycles", "motorcycles");
        createSeries("Bicycles", "bicycles");
        
        // Add scrollbar
        // https://www.amcharts.com/docs/v5/charts/xy-chart/scrollbars/
        chart.set("scrollbarX", am5.Scrollbar.new(root, {
          orientation: "horizontal"
        }));
        
        // Make stuff animate on load
        // https://www.amcharts.com/docs/v5/concepts/animations/
        chart.appear(1000, 100);
        
        }); // end am5.ready()
    </script>        
  </body>
</html>
  • 效果图

标签:绘制,chart,new,堆叠,bicycles,amCharts,year,root,am5
From: https://www.cnblogs.com/dogleftover/p/18222068

相关文章

  • 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......
  • 地质灾害风险地图:如何用GIS与Python绘制
    地质灾害是指全球地壳自然地质演化过程中,由于地球内动力、外动力或者人为地质动力作用下导致的自然地质和人类的自然灾害突发事件。由于降水、地震等自然作用下,地质灾害在世界范围内频繁发生。我国除滑坡灾害外,还包括崩塌、泥石流、地面沉降等各种地质灾害,具有类型多样、分......
  • Highcharts绘制饼图
    代码案例<html> <head> <metahttp-equiv="Content-Type"content="text/html;charset=utf-8"> <metaname="viewport"content="width=device-width,initial-scale=1"> <title>HighchartsExa......
  • 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......
  • 使用python绘制一个五颜六色的爱心
    使用python绘制一个五颜六色的爱心介绍效果代码介绍使用numpy与matplotlib绘制一个七彩爱心!效果代码importnumpyasnpimportmatplotlib.pyplotasplt#Heartshapefunctiondefheart_shape(t):x=16*np.sin(t)**3y=13*np.cos(t)-5*......
  • 统计不同文件夹中的文件数量,并绘制相应的柱状图。
    一、数据类型每个文件夹下都是这种文件,虽然可以通过手动数出来了解文件数量,但为了更直观地看到每个文件夹的文件数量,可以使用图表来表示,这样会更加清晰。效果展示:  二、代码实现 importosimportmatplotlib.pyplotaspltfolder_names=['0','1','2','3']......
  • Cesium4Unreal - # 002 线图元绘制
    文章目录基础点绘制1思路2步骤2.1创建一个自定义组件2.2重写CreateSceneProxy方法2.3实现自定义的场景代理类2.4在场景代理类中实现绘制逻辑2.5使用自定义组件3代码实现3.1c++代码3.1.1自定义组件代码MyPrimitivePointComponent.hMyPri......
  • 测试[C#]GDI+中使用BitBlt绘制图像到窗口
    安神颗粒的哈喽###2024-5-28WindowsFormPaintFormTES_ESEB测试[C#]GDI+中使用BitBlt绘制图像到窗口```#region测试[C#]GDI+中使用BitBlt绘制图像到窗口privatevoidpbx01_Paint(objectsender,PaintEventArgse){#regionMyRegion......
  • ZingChart绘制错误信息面积图
    代码案例<!doctypehtml><html><head><metacharset="utf-8"><title>ZingSoftDemo</title><scriptnonce="undefined"src="https://cdn.zingchart.com/zingchart.min.js"></script&g......
  • Vue+OpenLayers7入门到实战:OpenLayers实现在地图上拖拽编辑修改绘制图形
    返回《Vue+OpenLayers7》专栏目录:Vue+OpenLayers7入门到实战前言本章介绍如何使用OpenLayers7在地图上拖拽编辑修改绘制图形。在前面一章中,我们已经学会了如何绘制基础的三种图形线段、圆形和多边形:《Vue+OpenLayers7入门到实战:OpenLayers图形绘制功能,OpenLayers实现在地......