首页 > 其他分享 >AnyChart绘制折线图

AnyChart绘制折线图

时间:2024-05-30 09:12:07浏览次数:29  
标签:AnyChart 绘制 chart value var series 折线图 line data

  • 代码案例
<html>
    <head>
      <script src="https://cdn.anychart.com/releases/v8/js/anychart-base.min.js"></script>
      <script src="https://cdn.anychart.com/releases/v8/js/anychart-ui.min.js"></script>
      <script src="https://cdn.anychart.com/releases/v8/js/anychart-exports.min.js"></script>
      <link href="https://cdn.anychart.com/releases/v8/css/anychart-ui.min.css" type="text/css" rel="stylesheet">
      <link href="https://cdn.anychart.com/releases/v8/fonts/css/anychart-font.min.css" type="text/css" rel="stylesheet">
      <style type="text/css">
    
        html,
        body,
        #container {
          width: 400px;
          height: 350px;
          margin: 0;
          padding: 0;
        }
      
    </style>
    </head>
    <body>
    
      <div id="container"></div>
    
    
      <script>
    
      anychart.onDocumentReady(function () {
    
        // create a data set on our data
        var dataSet = anychart.data.set(getData());
    
        // map data for the first series,
        // take x from the zero column and value from the first column
        var firstSeriesData = dataSet.mapAs({ x: 0, value: 1 });
    
        // map data for the second series,
        // take x from the zero column and value from the second column
        var secondSeriesData = dataSet.mapAs({ x: 0, value: 2 });
    
        // map data for the third series,
        // take x from the zero column and value from the third column
        var thirdSeriesData = dataSet.mapAs({ x: 0, value: 3 });
    
        // map data for the fourth series,
        // take x from the zero column and value from the fourth column
        var fourthSeriesData = dataSet.mapAs({ x: 0, value: 4 });
    
        // create a line chart
        var chart = anychart.line();
    
        // turn on the line chart animation
        chart.animation(true);
    
        // configure the chart title text settings
        chart.title('Acceptance of same-sex relationships in the US over the last 2 decades');
    
        // set the y axis title
        chart.yAxis().title('% of people who accept same-sex relationships');
    
        // turn on the crosshair
        chart.crosshair().enabled(true).yLabel(false).yStroke(null);
    
        // create the first series with the mapped data
        var firstSeries = chart.line(firstSeriesData);
        firstSeries
          .name('18-34')
          .stroke('3 #f49595')
          .tooltip()
          .format('Age group 18-34 : {%value}%');
    
        // create the second series with the mapped data
        var secondSeries = chart.line(secondSeriesData);
        secondSeries
          .name('35-49')
          .stroke('3 #f9eb97')
          .tooltip()
          .format('Age group 35-49 : {%value}%');
    
        // create the third series with the mapped data
        var thirdSeries = chart.line(thirdSeriesData);
        thirdSeries
          .name('50-64')
          .stroke('3 #a8d9f6')
          .tooltip()
          .format('Age group 50-64 : {%value}%');
    
        // create the fourth series with the mapped data
        var fourthSeries = chart.line(fourthSeriesData);
        fourthSeries
          .name('65+')
          .stroke('3 #e2bbfd')
          .tooltip()
          .format('Age group 65+ : {%value}%');
    
        // turn the legend on
        chart.legend().enabled(true);
    
        // set the container id for the line chart
        chart.container('container');
    
        // draw the line chart
        chart.draw();
    
      });
    
      function getData() {
        return [
          ['1990',16.9,12.2,10.2,5.2],
          ['1991',17,17.8,10,4.8],
          ['1993',26.5,23.8,16.8,6.6],
          ['1994',28.7,22,17.3,9.1],
          ['1996',35.7,24,22.6,9.2],
          ['1998',37.2,24.6,22.4,11.2],
          ['2000',36.5,26.2,23.7,9.9],
          ['2002',40,34.4,23.8,16.4],
          ['2004',33.3,28.8,32.5,14.3],
          ['2006',40.2,32.1,27.5,15.1],
          ['2008',49.3,37.2,31.4,17.1],
          ['2010',51.9,42.5,36.1,28.5],
          ['2012',53.1,43.8,36,24.6],
          ['2014',63.7,45.9,44.7,31.3],
          ['2016',66.3,52,42.3,37.2],
          ['2018',70.1,57.7,49.2,39]
        ];
      }
    
    </script>
    </body>
    </html>             
  • 效果图

标签:AnyChart,绘制,chart,value,var,series,折线图,line,data
From: https://www.cnblogs.com/dogleftover/p/18221593

相关文章

  • 使用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_......
  • iOS开发_绘制圆角矩形虚线环
    -(void)drawRect:(CGRect)rect{//获取上下文(/画笔/绘图环境)CGContextRefcontext=UIGraphicsGetCurrentContext();//小段长度CGFloatline_dash=self.height/20;//虚线的样式:长5空隙15长10空隙30长2空隙20...//CGFloa......
  • matplotlib-折线图的常用操作合集
    序言:感悟:复杂的折线图,都是由基础的折线图慢慢加工绘制而成,我们通过绘制出基本折线图,然后分析需要添加的功能,慢慢润色图形即可完成复杂的图形绘制。折线图:以折线的上升或下降来表示统计数量的增减变化的统计图特点:能够显示数据的变化趋势,反映事物的变化情况。(变化)我们以一个......
  • Vue3标签组件绘制--自定义按钮组件
    不知道怎么的,突然想绘制一个标签,比如el-button什么的。今天研究一下吧,不知道能不能整出来以后就可以绘制自己的组件,弄自己的组件库了。不知道有朝一日能不能让越组件青史留名?嘻嘻,百日梦做差不多了,接着去查查资料。文章分为三个部分:1.按钮组件实现(根据查阅的一个文章实现基......