我正在寻找如何构建一个群集但未堆叠(分层)的amChart的方法。例如,比较过去3年的月份。我想分别查看1,2年和3年每个月的已售与已发货。
具体来说,使用下面的示例,我需要N America位于欧洲之上或与欧洲相同。目前,它遍及所有集群。
代码:
var chart = AmCharts.makeChart( "chartdiv", {
"type": "serial",
"legend": {
"horizontalGap": 10,
"useGraphSettings": true,
"markerSize": 10
},
"dataProvider": [ {
"year": 2003,
"europe": 2.5,
"namerica": 1.5,
"asia": 2.1,
"lamerica": 1.2,
}, {
"year": 2004,
"europe": 2.6,
"namerica": 2.7,
"asia": 2.2,
"lamerica": 1.3,
}, {
"year": 2005,
"europe": 2.8,
"namerica": 2.9,
"asia": 2.4,
"lamerica": 1.4,
} ],
"valueAxes": [ {
"stackType": "regular",
"axisAlpha": 0,
"gridAlpha": 0
} ],
"graphs": [ {
"fillAlphas": 0.8,
"labelText": "[[title]]",
"lineAlpha": 0.3,
"title": "Europe",
"type": "column",
"color": "#000000",
"valueField": "europe"
}, {
"fillAlphas": 0.8,
"labelText": "[[title]]",
"lineAlpha": 0.3,
"title": "N America",
"type": "column",
"color": "#000000",
"columnWidth":0.3,
"clustered":false,
"stackable": false,
"valueField": "namerica"
}, {
"fillAlphas": 0.8,
"labelText": "[[title]]",
"lineAlpha": 0.3,
"title": "Asia-Pacific",
"type": "column",
"newStack": true,
"color": "#000000",
"valueField": "asia"
}, {
"fillAlphas": 0.8,
"labelText": "[[title]]",
"lineAlpha": 0.3,
"title": "L America",
"type": "column",
"color": "#000000",
"valueField": "lamerica"
} ],
"categoryField": "year",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"gridAlpha": 0,
"position": "left"
}});
我可以在这里靠近:
jsFiddle
我正在尝试合并这两个图表:
https://www.amcharts.com/demos/stacked-clustered-column-chart/
https://www.amcharts.com/demos/layered-column-chart/
谢谢!
答案 0 :(得分:0)
在使列位于同一簇内的同时,实现此目标的最接近方法是设置值轴'stackType: 3d
并将angle
和depth3D
调整为较小的值,以便他们会排队:
AmCharts.makeChart("...", {
// ...
"depth3D": 0, //0 depth to remove the 3d effect and achieve layering.
"angle": 0, //0 angle to center the columns within the cluster. won't 100% center if depth3D is a non-zero value
"columnSpacing3D" : 0,
"columnSpacing": 20, //space the clusters out
// ...
"valueAxes": [ {
"stackType": "3d",
"axisAlpha": 0,
"gridAlpha": 0
} ],
// ...
});
此后,您要做的就是修复图形定义以在每两个图形之后设置newStack: true
属性。
演示:
var chart = AmCharts.makeChart( "chartdiv", {
"type": "serial",
"depth3D": 0, //0 depth to remove the 3d effect and achieve layering.
"angle": 0, //0 angle to center the columns within the cluster. won't 100% center if depth3D is a non-zero value
"columnSpacing3D" : 0,
"columnSpacing": 20, //space the clusters out
"legend": {
"horizontalGap": 10,
"useGraphSettings": true,
"markerSize": 10
},
"dataProvider": [ {
"year": 2003,
"europe": 2.5,
"namerica": 1.5,
"asia": 2.1,
"lamerica": 1.2,
}, {
"year": 2004,
"europe": 2.6,
"namerica": 2.7,
"asia": 2.2,
"lamerica": 1.3,
}, {
"year": 2005,
"europe": 2.8,
"namerica": 2.9,
"asia": 2.4,
"lamerica": 1.4,
} ],
"valueAxes": [ {
"stackType": "3d",
"axisAlpha": 0,
"gridAlpha": 0
} ],
"graphs": [ {
"fillAlphas": 0.8,
"labelText": "[[title]]",
"lineAlpha": 0.3,
"title": "Europe",
"type": "column",
"color": "#000000",
"valueField": "europe"
}, {
"fillAlphas": 0.8,
"labelText": "[[title]]",
"lineAlpha": 0.3,
"title": "N America",
"type": "column",
"color": "#000000",
"valueField": "namerica"
}, {
"fillAlphas": 0.8,
"labelText": "[[title]]",
"lineAlpha": 0.3,
"title": "Asia-Pacific",
"type": "column",
"color": "#000000",
"newStack": true,
"valueField": "asia"
}, {
"fillAlphas": 0.8,
"labelText": "[[title]]",
"lineAlpha": 0.3,
"title": "L America",
"type": "column",
"color": "#000000",
"valueField": "lamerica"
} ],
"categoryField": "year",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"gridAlpha": 0,
"position": "left"
}
} );
#chartdiv {
width: 100%;
height: 500px;
}
<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/themes/none.js"></script>
<div id="chartdiv"></div>