Amcharts漏斗图,如何设置固定高度?

时间:2017-10-25 11:18:10

标签: javascript charts amcharts

我有https://www.amcharts.com/demos/funnel-chart/?theme=none的漏斗图表。它工作正常。

我想为片段设置一个固定的高度,但我不知道如何。

1 个答案:

答案 0 :(得分:3)

没有办法直接在配置中设置固定高度段,但您可以通过设置段的区域/高度的假值来使用您的数据伪造它,但在您的单独属性中显示实际值balloonTextlabelText,例如:

  "dataProvider": [ {
    "title": "Website visits",
    "areaValue": 30, //value used for segment height/area
    "realValue": 300
  }, {
    "title": "Downloads",
    "areaValue": 30,
    "realValue": 123
  }, // ...
  ],
  // ...
  "valueField": "areaValue", //use the area value for visual purposes
  "balloonText": "[[title]]:<b>[[realValue]]</b>", //reference the actual value through the realValue
  "labelText": "[[title]]: [[realValue]]", 

使用相同高度的段进行演示:

var chart = AmCharts.makeChart("chartdiv", {
  "type": "funnel",
  "theme": "none",
  "dataProvider": [{
    "title": "Website visits",
    "areaValue": 30,
    "realValue": 300
  }, {
    "title": "Downloads",
    "areaValue": 30,
    "realValue": 123
  }, {
    "title": "Requested prices",
    "areaValue": 30,
    "realValue": 98
  }, {
    "title": "Contacted",
    "areaValue": 30,
    "realValue": 72
  }, {
    "title": "Purchased",
    "areaValue": 30,
    "realValue": 35
  }, {
    "title": "Asked for support",
    "areaValue": 30,
    "realValue": 25
  }, {
    "title": "Purchased more",
    "areaValue": 30,
    "realValue": 18
  }],
  "titleField": "title",
  "marginRight": 160,
  "marginLeft": 15,
  "labelPosition": "right",
  "funnelAlpha": 0.9,
  "valueField": "areaValue",
  "balloonText": "[[title]]:<b>[[realValue]]</b>",
  "labelText": "[[title]]: [[realValue]]",
  "startX": 0,
  "neckWidth": "40%",
  "startAlpha": 0,
  "outlineThickness": 1,
  "neckHeight": "30%",
  "export": {
    "enabled": true
  }
});
#chartdiv {
  width: 100%;
  height: 500px;
}
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/funnel.js"></script>
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script>
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" />
<script src="https://www.amcharts.com/lib/3/themes/none.js"></script>
<div id="chartdiv"></div>