首页 > 其他分享 >amCharts绘制折线图比较

amCharts绘制折线图比较

时间:2024-05-30 12:01:44浏览次数:19  
标签:root chart date 2019 amCharts series 折线图 new 绘制

  • 代码案例
<!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.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 }),
          tooltip: am5.Tooltip.new(root, {})
        }));
        
        var yAxis = chart.yAxes.push(am5xy.ValueAxis.new(root, {
          maxDeviation: 0.3,
          renderer: am5xy.AxisRendererY.new(root, {})
        }));
        
        
        // Add 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: "value1",
          valueXField: "date",
          tooltip: am5.Tooltip.new(root, {
            labelText: "{valueX}: {valueY}\n{previousDate}: {value2}"
          })
        }));
        
        series.strokes.template.setAll({
          strokeWidth: 2
        });
        
        series.get("tooltip").get("background").set("fillOpacity", 0.5);
        
        var series2 = chart.series.push(am5xy.LineSeries.new(root, {
          name: "Series 2",
          xAxis: xAxis,
          yAxis: yAxis,
          valueYField: "value2",
          valueXField: "date"
        }));
        series2.strokes.template.setAll({
          strokeDasharray: [2, 2],
          strokeWidth: 2
        });
        
        // Set date fields
        // https://www.amcharts.com/docs/v5/concepts/data/#Parsing_dates
        root.dateFormatter.setAll({
          dateFormat: "yyyy-MM-dd",
          dateFields: ["valueX"]
        });
        
        
        // Set data
        var data = [{
          date: new Date(2019, 5, 12).getTime(),
          value1: 50,
          value2: 48,
          previousDate: new Date(2019, 5, 5)
        }, {
          date: new Date(2019, 5, 13).getTime(),
          value1: 53,
          value2: 51,
          previousDate: "2019-05-06"
        }, {
          date: new Date(2019, 5, 14).getTime(),
          value1: 56,
          value2: 58,
          previousDate: "2019-05-07"
        }, {
          date: new Date(2019, 5, 15).getTime(),
          value1: 52,
          value2: 53,
          previousDate: "2019-05-08"
        }, {
          date: new Date(2019, 5, 16).getTime(),
          value1: 48,
          value2: 44,
          previousDate: "2019-05-09"
        }, {
          date: new Date(2019, 5, 17).getTime(),
          value1: 47,
          value2: 42,
          previousDate: "2019-05-10"
        }, {
          date: new Date(2019, 5, 18).getTime(),
          value1: 59,
          value2: 55,
          previousDate: "2019-05-11"
        }]
        
        series.data.setAll(data);
        series2.data.setAll(data);
        
        
        // Make stuff animate on load
        // https://www.amcharts.com/docs/v5/concepts/animations/
        series.appear(1000);
        series2.appear(1000);
        chart.appear(1000, 100);
        
        }); // end am5.ready()
    </script>        
  </body>
</html>
  • 效果图

标签:root,chart,date,2019,amCharts,series,折线图,new,绘制
From: https://www.cnblogs.com/dogleftover/p/18222080

相关文章

  • 地质灾害风险地图:如何用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实现在地......
  • 详解PySide多线程【Python-Pyside图形界面绘制#2】
    在了解pyside多线程之前,如果是初学者可以先去看看我的第一篇文章《超详细实例详解Python多线程》,文中有对多线程的概念进行详细介绍,如果有相关基础可直接跳过。【Python】超详细实例讲解python多线程(threading模块)_pythonthreading介绍-CSDN博客https://blog.csdn.net/Xiao_......