首页 > 其他分享 >amCharts绘制甜甜圈

amCharts绘制甜甜圈

时间:2024-05-30 16:23:36浏览次数:18  
标签:root 甜甜 charts chart amCharts template series0 series1 绘制

案例1

  • 代码案例
<!DOCTYPE html>
<html>
  <head>
    <script src="https://cdn.amcharts.com/lib/5/index.js"></script>
    <script src="https://cdn.amcharts.com/lib/5/percent.js"></script>
    <script src="https://cdn.amcharts.com/lib/5/themes/Animated.js"></script>
    <style>
        #chartdiv {
          width: 550PX;
          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/percent-charts/pie-chart/
        // start and end angle must be set both for chart and series
        var chart = root.container.children.push(
          am5percent.PieChart.new(root, {
            layout: root.verticalLayout
          })
        );
        
        // Create series
        // https://www.amcharts.com/docs/v5/charts/percent-charts/pie-chart/#Series
        // start and end angle must be set both for chart and series
        var series0 = chart.series.push(
          am5percent.PieSeries.new(root, {
            valueField: "value",
            categoryField: "category",
            alignLabels: false,
            radius: am5.percent(100),
            innerRadius: am5.percent(80)
          })
        );
        
        series0.states.create("hidden", {
          startAngle: 180,
          endAngle: 180
        });
        
        series0.slices.template.setAll({
          fillOpacity: 0.5,
          strokeOpacity: 0,
          templateField: "settings"
        });
        
        series0.slices.template.states.create("hover", { scale: 1 });
        series0.slices.template.states.create("active", { shiftRadius:0 });
        
        series0.labels.template.setAll({
          templateField: "settings"
        });
        
        series0.ticks.template.setAll({
          templateField: "settings"
        });
        
        series0.labels.template.setAll({
          textType: "circular",
          radius: 30
        });
        
        // Set data
        // https://www.amcharts.com/docs/v5/charts/percent-charts/pie-chart/#Setting_data
        series0.data.setAll([
          {
            category: "First + Second",
            value: 60
          },
          {
            category: "Unused",
            value: 30,
            settings: { forceHidden: true }
          }
        ]);
        
        // Create series
        // https://www.amcharts.com/docs/v5/charts/percent-charts/pie-chart/#Series
        // start and end angle must be set both for chart and series
        var series1 = chart.series.push(
          am5percent.PieSeries.new(root, {
            radius: am5.percent(95),
            innerRadius: am5.percent(85),
            valueField: "value",
            categoryField: "category",
            alignLabels: false
          })
        );
        
        series1.states.create("hidden", {
          startAngle: 180,
          endAngle: 180
        });
        
        series1.slices.template.setAll({
          templateField: "sliceSettings",
          strokeOpacity: 0
        });
        
        series1.labels.template.setAll({
          textType: "circular"
        });
        
        series1.labels.template.adapters.add("radius", function (radius, target) {
          var dataItem = target.dataItem;
          var slice = dataItem.get("slice");
          return -(slice.get("radius") - slice.get("innerRadius")) / 2 - 10;
        });
        
        series1.slices.template.states.create("hover", { scale: 1 });
        series1.slices.template.states.create("active", { shiftRadius:0 });
        
        series1.ticks.template.setAll({
          forceHidden: true
        });
        
        // Set data
        // https://www.amcharts.com/docs/v5/charts/percent-charts/pie-chart/#Setting_data
        series1.data.setAll([{
          category: "First",
          value: 30
        }, {
          category: "Second",
          value: 30
        }, {
          category: "Remaining",
          value: 30,
          sliceSettings: { fill: am5.color(0xdedede) }
        }]);
        
        }); // end am5.ready()
    </script>       
  </body>
</html>
  • 效果图
点击查看详情

标签:root,甜甜,charts,chart,amCharts,template,series0,series1,绘制
From: https://www.cnblogs.com/dogleftover/p/18222601

相关文章

  • amCharts绘制饼图
    案例1代码案例<!DOCTYPEhtml><html><head><scriptsrc="https://cdn.amcharts.com/lib/5/index.js"></script><scriptsrc="https://cdn.amcharts.com/lib/5/percent.js"></script><scri......
  • 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......
  • 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......
  • 地质灾害风险地图:如何用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*......