【问题标题】:How to use multiple color in donut chart of amcharts? [closed]如何在amcharts的圆环图中使用多种颜色? [关闭]
【发布时间】:2018-03-15 13:52:12
【问题描述】:

我想在圆环图中提供 2 种颜色,这将使渐变填充作为 amcharts 中的背景颜色。

我已经找到了单色渐变色的解决方案,但是如何给一个以上颜色的渐变色呢?

Current Donut chart

Resulted Donut chart

这是我的代码:

 var chart5 = AmCharts.makeChart( "emp-hour-chartContainer1", {
                "type": "pie",
                "theme": "light",
                "dataProvider": chartEmpData1,
                "titleField": "title",
                "valueField": "value",
                "labelRadius": -21,
                "radius": "50%",
                "innerRadius": "50%",
                "alpha": 1,
                "fontSize": 12,
                "color": "#ffffff",
                "labelText": "[[title]] Days",
                "balloonText": "[[title]] Days",
                "colors":["#f7b72f","#02aace"],
                "export": {
                    "enabled": true
                },
                "allLabels": [{
                    "y": "45%",
                    "align": "center",
                    "size": 15,
                    "text": "Work",
                    "color": "#262727"
                }]
            });

【问题讨论】:

    标签: jquery html css amcharts


    【解决方案1】:

    您可以通过定义gradientRatio 对切片应用渐变,例如:

    AmCharts.makeChart("...", {
      // ...
      gradientRatio: [-.4, 0, .2], //negative = darker gradient, positive = lighter gradient
      // ...
    });
    

    演示:

    var chartEmpData1 = [{title: 13, value: 13}, {title: 25, value: 25}]
    var chart5 = AmCharts.makeChart("emp-hour-chartContainer1", {
      type: "pie",
      theme: "light",
      dataProvider: chartEmpData1,
      titleField: "title",
      valueField: "value",
      gradientRatio: [-.4, 0, .2],
      labelRadius: -21,
      radius: "50%",
      innerRadius: "50%",
      alpha: 1,
      fontSize: 12,
      color: "#ffffff",
      labelText: "[[title]] Days",
      balloonText: "[[title]] Days",
      colors: ["#f7b72f", "#02aace"],
      export: {
        enabled: true
      },
      allLabels: [
        {
          y: "45%",
          align: "center",
          size: 15,
          text: "Work",
          color: "#262727"
        }
      ]
    });
    #emp-hour-chartContainer1 {
      width: 300px;
      height: 300px;
      margin: 0 auto;
    }
    <script src="//www.amcharts.com/lib/3/amcharts.js"></script>
    <script src="//www.amcharts.com/lib/3/pie.js"></script>
    <script src="//www.amcharts.com/lib/3/themes/light.js"></script>
    <div id="emp-hour-chartContainer1"></div>

    【讨论】:

    • 我使用了这个解决方案,但无法得到结果图。感谢您的帮助。
    • 您唯一的其他选择是使用 SVG 过滤器,但您必须启用 addClassNames。见this article
    猜你喜欢
    • 1970-01-01
    • 2020-01-09
    • 2013-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    相关资源
    最近更新 更多