javascript - amcharts不规则网格轴

标签 javascript amcharts

我需要内联堆叠不同宽度的列。 也许需要将 x 网格更改为不规则。 如何消除具有不同 columnWidth 的列之间的距离? 或者如何使列一一定位而没有空位?

照片, enter image description here

演示如下:

var chart = AmCharts.makeChart("chartdiv", {
  "type": "serial",
  "theme": "light",
  "marginRight": 70,
  "dataProvider": [{
    "country": "USA",
    "visits1": 3025,
    "color": "#FF0F00"
  }, {
    "country": "China",
    "visits2": 1882,
    "color": "#FF6600"
  }, {
    "country": "Japan",
    "visits3": 1809,
    "color": "#FF9E01"
  }, ],
  "valueAxes": [{
    "axisAlpha": 0,
    "position": "left",
    "title": "Visitors from country"
  }],
  "startDuration": 1,
  "graphs": [{
    "balloonText": "<b>[[category]]: [[value]]</b>",
    "fillColorsField": "color",
    "fillAlphas": 0.9,
    "lineAlpha": 0.2,
    "type": "column",
    "valueField": "visits1",
    "columnWidth":0.8
  },
  {
    "balloonText": "<b>[[category]]: [[value]]</b>",
    "fillColorsField": "color",
    "fillAlphas": 0.9,
    "lineAlpha": 0.2,
    "type": "column",
    "valueField": "visits2",
    "columnWidth":0.2
  },
  {
    "balloonText": "<b>[[category]]: [[value]]</b>",
    "fillColorsField": "color",
    "fillAlphas": 0.9,
    "lineAlpha": 0.2,
    "type": "column",
    "valueField": "visits3",
    "columnWidth":0.5
  }],
  "chartCursor": {
    "categoryBalloonEnabled": false,
    "cursorAlpha": 0,
    "zoomable": false
  },
  "categoryField": "country",
  "categoryAxis": {
    "gridPosition": "start",
    "labelRotation": 45
  },
  "export": {
    "enabled": true
  }

});
#chartdiv {
  width: 100%;
  height: 500px;
}

.amcharts-export-menu-top-right {
  top: 10px;
  right: 0;
}
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.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/light.js"></script>
<div id="chartdiv"></div>			

最佳答案

您需要保留 1 个图表并使用 widthField在您的 CategoryAxis 中确定列宽。

var chart = AmCharts.makeChart("chartdiv", {
  "type": "serial",
  "theme": "light",
  "marginRight": 70,
  "dataProvider": [{
    "country": "USA",
    "visits": 3025,
    "color": "#FF0F00",
    "width": 0.8
  }, {
    "country": "China",
    "visits": 1882,
    "color": "#FF6600",
    "width": 0.2
  }, {
    "country": "Japan",
    "visits": 1809,
    "color": "#FF9E01",
    "width": 0.5
  }, ],
  "valueAxes": [{
    "axisAlpha": 0,
    "position": "left",
    "title": "Visitors from country"
  }],
  "startDuration": 1,
  "graphs": [{
    "balloonText": "<b>[[category]]: [[value]]</b>",
    "fillColorsField": "color",
    "fillAlphas": 0.9,
    "lineAlpha": 0.2,
    "type": "column",
    "valueField": "visits"
  }],
  "chartCursor": {
    "categoryBalloonEnabled": false,
    "cursorAlpha": 0,
    "zoomable": false
  },
  "categoryField": "country",
  "categoryAxis": {
    "gridPosition": "start",
    "labelRotation": 45,
    "widthField": "width"
  },
  "export": {
    "enabled": true
  }

});
#chartdiv {
  width: 100%;
  height: 500px;
}

.amcharts-export-menu-top-right {
  top: 10px;
  right: 0;
}
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.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/light.js"></script>
<div id="chartdiv"></div>

关于javascript - amcharts不规则网格轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48263620/

相关文章:

javascript - Dojo 多个带有下拉按钮的非模式对话框

javascript - 在事件处理程序javascript中访问事件对象

javascript - 如何使用 webpack 处理动态图像路径

javascript - 在 amcharts4 的气泡图中的气泡下标记

javascript - AmChart 倍数日期值

javascript - IE 和 GMap API 2 包装器错误

javascript - 将 Canvas 分成几 block

javascript - 如何在 amCharts v4 中添加外部事件系列?

javascript - Angular 2 中的 Amcharts 点击事件不起作用

java - 在 J2EE 项目中将 amCharts 与 maven 和 spring 一起使用