Multiple stacked charts on same page - amcharts

Figured this would be easy, but I'm missing something. Trying to add two stacked 100% charts to the same page. Data is being fed from MySQL via php. I know the php code is correct, since I am able to see correct data in the source code. Problem is, the second chart isn't showing up.
I have (I think) verified that the charts don't have any conflicting IDs. Here is the code for both charts:
Chart 1 (this one displays as expected):
<!-- Chart code -->
<script>
var ageChart = AmCharts.makeChart("agePie", {
"type": "serial",
"theme": "light",
"dataProvider": [{
"demographic": "National",
"18to34": 30.14,
"35to54": 40.14,
"55to64": 13.40,
"65over": 16.32
},
{
"demographic": "Segment",
"18to34": <?php echo $age1Avg ?>,
"35to54": <?php echo $age2Avg ?>,
"55to64": <?php echo $age3Avg ?>,
"65over": <?php echo $age4Avg ?>
}
],
"valueAxes": [{
"stackType": "100%",
"axisAlpha": 0,
"gridAlpha": 0,
"labelsEnabled": false,
"position": "left"
}],
"graphs": [{
"balloonText": "[[title]], [[category]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "18-34",
"type": "column",
"valueField": "18to34"
}, {
"balloonText": "[[title]], [[category]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "35-54",
"type": "column",
"valueField": "35to54"
}, {
"balloonText": "[[title]], [[category]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "55-64",
"type": "column",
"valueField": "55to64"
}, {
"balloonText": "[[category]]:[[title]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "Over 65",
"type": "column",
"valueField": "65over"
}],
"marginTop": 30,
"marginRight": 0,
"marginLeft": 0,
"marginBottom": 40,
"autoMargins": false,
"categoryField": "demographic",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"gridAlpha": 0
}
});
</script>
Chart 2 (this one does NOT display). Should be the same configurations, just a different data comparison.
<script>
var ethChart = AmCharts.makeChart("ethPie", {
"type": "serial",
"theme": "light",
"dataProvider": [{
"demographic2": "National",
"Causacian": 30.14,
"AfricanAmerican": 40.14,
"Latin": 13.40,
"Other": 16.32
},
{
"demographic2": "Segment",
"Causacian": <?php echo $eth1Avg ?>,
"AfricanAmerican": <?php echo $eth2Avg ?>,
"Latin": <?php echo $eth3Avg ?>,
"Other": <?php echo $eth4Avg ?>
}
],
"valueAxes": [{
"stackType": "100%",
"axisAlpha": 0,
"gridAlpha": 0,
"labelsEnabled": false,
"position": "left"
}],
"graphs": [{
"balloonText": "[[title]], [[category]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "Caucasian",
"type": "column",
"valueField": "Caucasian"
}, {
"balloonText": "[[title]], [[category]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "African American",
"type": "column",
"valueField": "AfricanAmerican"
}, {
"balloonText": "[[title]], [[category]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "Latin",
"type": "column",
"valueField": "Latin"
}, {
"balloonText": "[[category]]:[[title]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "Other",
"type": "column",
"valueField": "Other"
}],
"marginTop": 30,
"marginRight": 0,
"marginLeft": 0,
"marginBottom": 40,
"autoMargins": false,
"categoryField": "demographic2",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"gridAlpha": 0
}
});
</script>
Calling each chart by the respective ID:
<div id="agePie"></div>
<div id="ethPie"></div>
Thoughts or shoves in the right direction?

Please run the snippet below. Your code is working and it seems the lack of a defined dimension would be causing the issue.
I recommend you to try set a CSS class for both charts in case they should have the same dimension. Check the example below:
.chartdiv {
width: 100%;
height: 300px;
}
Add the class to both DivElement:
<div id="agePie" class="chartdiv"></div>
<div id="ethPie" class="chartdiv"></div>
Make sure you clean your browser cache. That could explain why you didn't see the difference before.
var ageChart = AmCharts.makeChart("agePie", {
"type": "serial",
"theme": "light",
"dataProvider": [{
"demographic": "National",
"18to34": 30.14,
"35to54": 40.14,
"55to64": 13.40,
"65over": 16.32
},
{
"demographic": "Segment",
"18to34": 24,
"35to54": 40,
"55to64": 60,
"65over": 80
}
],
"valueAxes": [{
"stackType": "100%",
"axisAlpha": 0,
"gridAlpha": 0,
"labelsEnabled": false,
"position": "left"
}],
"graphs": [{
"balloonText": "[[title]], [[category]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "18-34",
"type": "column",
"valueField": "18to34"
}, {
"balloonText": "[[title]], [[category]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "35-54",
"type": "column",
"valueField": "35to54"
}, {
"balloonText": "[[title]], [[category]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "55-64",
"type": "column",
"valueField": "55to64"
}, {
"balloonText": "[[category]]:[[title]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "Over 65",
"type": "column",
"valueField": "65over"
}],
"marginTop": 30,
"marginRight": 0,
"marginLeft": 0,
"marginBottom": 40,
"autoMargins": false,
"categoryField": "demographic",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"gridAlpha": 0
}
});
var ethChart = AmCharts.makeChart("ethPie", {
"type": "serial",
"theme": "light",
"dataProvider": [{
"demographic2": "National",
"Causacian": 30.14,
"AfricanAmerican": 40.14,
"Latin": 13.40,
"Other": 16.32
},
{
"demographic2": "Segment",
"Causacian": 23,
"AfricanAmerican": 34,
"Latin": 12,
"Other": 3
}
],
"valueAxes": [{
"stackType": "100%",
"axisAlpha": 0,
"gridAlpha": 0,
"labelsEnabled": false,
"position": "left"
}],
"graphs": [{
"balloonText": "[[title]], [[category]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "Caucasian",
"type": "column",
"valueField": "Caucasian"
}, {
"balloonText": "[[title]], [[category]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "African American",
"type": "column",
"valueField": "AfricanAmerican"
}, {
"balloonText": "[[title]], [[category]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "Latin",
"type": "column",
"valueField": "Latin"
}, {
"balloonText": "[[category]]:[[title]]<br><span style='font-size:14px;'><b>[[value]]</b></span>",
"fillAlphas": 0.9,
"fontSize": 11,
"labelText": "[[title]]: [[value]]%",
"lineAlpha": 0.5,
"title": "Other",
"type": "column",
"valueField": "Other"
}],
"marginTop": 30,
"marginRight": 0,
"marginLeft": 0,
"marginBottom": 40,
"autoMargins": false,
"categoryField": "demographic2",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"gridAlpha": 0
}
});
.chartdiv {
width: 100%;
height: 300px;
}
<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="agePie" class="chartdiv"></div>
<div id="ethPie" class="chartdiv"></div>

Related

amCharts Clustered but not stacked

I am looking for how to build an amChart that is clustered but not stacked (layered). An example would be comparing month to month for the last 3 years. For each month I want to see sold vs shipped, year 1,2 and 3 clustered.
Specifically, using the below example, I need N America to be on top of or in the same cluster as Europe. Currently it is across all the clusters.
Code:
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"
}});
I can get close here:
jsFiddle
I'm attempting to combine these two charts:
https://www.amcharts.com/demos/stacked-clustered-column-chart/
https://www.amcharts.com/demos/layered-column-chart/
Thanks!
The closest way you can achieve this while having the columns centered within the same cluster is to set the value axis' stackType: 3d and tweak the angle and depth3D to small values so that they'll line up:
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
} ],
// ...
});
All you have to do after that is fix the graph definitions to set the newStack: true property after every two graphs.
Demo:
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>

How in AmCharts move slider in scrollbar to left?

I have AmCharts diagram as on screen. diagram screen
By default slider in scrollbar in right position. How to make it in left position by default?
left position scrollbar
Which options I should add to
"chartScrollbar": {
"enabled": true
},
UPD: Full code AmChart diagram.
I have some options with "zoom", but if I comment it, nothing changes.-----------------------------------------------------------------------------------------------------------
var chartOptions = {
"type": "serial",
"theme": "light",
"columnWidth": 0.6,
"maxSelectedSeries": 3,
"rotate": false,
"mouseWheelScrollEnabled": true,
"zoomOutOnDataUpdate": false,
"zoomOutButtonPadding": 2,
"startDuration": 0,
"panEventsEnabled": false,
"chartScrollbar": {
},
"legend": {
"position": "bottom",
'fontSize': 12
},
"dataProvider": dataProvider,
"valueAxes": [{
"stackType": "regular",
"axisAlpha": 0.3,
"gridAlpha": 0,
'fontSize': 13
}],
"graphs": [{
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[value]]→[[CLIENT_REFUSED_MONEY]]</span>",
"fillAlphas": 0.8,
"labelText": "[[value]]→[[CLIENT_REFUSED_MONEY]]",
"lineAlpha": 0.3,
"title": "Refused",
"type": "column",
"color": "#000000",
"valueField": "CLIENT_REFUSED_COUNT",
'fontSize': 16,
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[value]]→[[DENIED_MONEY]]</span>",
"fillAlphas": 0.8,
"labelText": "[[value]]→[[DENIED_MONEY]]",
"lineAlpha": 0.3,
"title": "Denied",
"type": "column",
"color": "#000000",
"valueField": "DENIED_COUNT",
'fontSize': 16,
}, {
// On mouse hover which balloon is show
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[value]]→[[IN_PROGRESS_MONEY]]</span>",
"fillAlphas": 0.8,
// Text on column (may unicode symbols, other fields)
"labelText": "[[value]]→[[IN_PROGRESS_MONEY]]",
"lineAlpha": 0.3,
"title": "In progress",
"type": "column",
"color": "#000000",
// Variable from data provider.
"valueField": "IN_PROGRESS_COUNT",
'fontSize': 16,
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[value]]→[[APPROVED_MONEY]]</span>",
"fillAlphas": 0.8,
"labelText": "[[value]]→[[APPROVED_MONEY]]",
"lineAlpha": 0.3,
"title": "Approved",
"type": "column",
"color": "#000000",
"valueField": "APPROVED_COUNT",
'fontSize': 16,
}],
"categoryField": "operator",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"gridAlpha": 0,
"position": "left",
'fontSize': 13,
'boldLabels': true
},
};
AmCharts.makeChart("underwriters-deals-chart", chartOptions);
maxSelectedSeries defaults your chart scrollbar selection to the right with the zoom specified. You'll need to add some code to the chart's init event to call zoomToIndexes to shift it over to the left:
var chartOptions = {
// ...
listeners: [{
event: "init",
method: function(e) {
e.chart.zoomToIndexes(0, e.chart.maxSelectedSeries);
}
}]
};
Demo below:
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"columnWidth": 0.6,
"maxSelectedSeries": 3,
"rotate": false,
"mouseWheelScrollEnabled": true,
"zoomOutOnDataUpdate": false,
"zoomOutButtonPadding": 2,
"startDuration": 0,
"panEventsEnabled": false,
"chartScrollbar": {},
"legend": {
"position": "bottom",
'fontSize': 12
},
"dataProvider": generateData(),
"valueAxes": [{
"stackType": "regular",
"axisAlpha": 0.3,
"gridAlpha": 0,
'fontSize': 13
}],
"graphs": [{
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[value]]→[[CLIENT_REFUSED_MONEY]]</span>",
"fillAlphas": 0.8,
"labelText": "[[value]]→[[CLIENT_REFUSED_MONEY]]",
"lineAlpha": 0.3,
"title": "Refused",
"type": "column",
"color": "#000000",
"valueField": "CLIENT_REFUSED_COUNT",
'fontSize': 16,
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[value]]→[[DENIED_MONEY]]</span>",
"fillAlphas": 0.8,
"labelText": "[[value]]→[[DENIED_MONEY]]",
"lineAlpha": 0.3,
"title": "Denied",
"type": "column",
"color": "#000000",
"valueField": "DENIED_COUNT",
'fontSize': 16,
}, {
// On mouse hover which balloon is show
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[value]]→[[IN_PROGRESS_MONEY]]</span>",
"fillAlphas": 0.8,
// Text on column (may unicode symbols, other fields)
"labelText": "[[value]]→[[IN_PROGRESS_MONEY]]",
"lineAlpha": 0.3,
"title": "In progress",
"type": "column",
"color": "#000000",
// Variable from data provider.
"valueField": "IN_PROGRESS_COUNT",
'fontSize': 16,
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[value]]→[[APPROVED_MONEY]]</span>",
"fillAlphas": 0.8,
"labelText": "[[value]]→[[APPROVED_MONEY]]",
"lineAlpha": 0.3,
"title": "Approved",
"type": "column",
"color": "#000000",
"valueField": "APPROVED_COUNT",
'fontSize': 16,
}],
"categoryField": "operator",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"gridAlpha": 0,
"position": "left",
'fontSize': 13,
'boldLabels': true
},
"listeners": [{
"event": "init",
"method": function(e) {
e.chart.zoomToIndexes(0, e.chart.maxSelectedSeries);
}
}]
});
function generateData() {
var data = [];
for (var i = 0; i < 10; ++i) {
data.push({
CLIENT_REFUSED_COUNT: Math.floor(Math.random() * 10 + 1),
DENIED_COUNT: Math.floor(Math.random() * 15 + 1),
IN_PROGRESS_COUNT: Math.floor(Math.random() * 25 + 1),
APPROVED_COUNT: Math.floor(Math.random() * 30 + 1),
CLIENT_REFUSED_MONEY: Math.floor(Math.random() * 40000 + 1),
DENIED_MONEY: Math.floor(Math.random() * 20000 + 1),
IN_PROGRESS_MONEY: Math.floor(Math.random() * 150000 + 1),
APPROVED_MONEY: Math.floor(Math.random() * 200000 + 1),
operator: "Operator-" + (i + 1)
});
}
return data;
}
html,
body {
width: 100%;
height: 100%;
margin: 0px;
}
#chartdiv {
width: 100%;
height: 100%;
}
<script src="//www.amcharts.com/lib/3/amcharts.js"></script>
<script src="//www.amcharts.com/lib/3/serial.js"></script>
<script src="//www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv"></div>

How can I set amCharts stacked column style colors automatically

I want to create a generic chart for stacked column charts. I will create an angularjs directive that contains a <div id="chart"></div> and my charts will be in it.
I am settings a dataProvider for amCharts but I need to set colors all of items. Does not generate colors automatically?
Could you please provide your data provider, and do you provide it at the time of initialization of chart or you are providing it dynamically?
Here is an example from amchart with data provider in initialization time.
jsfiddle
var chart = AmCharts.makeChart("chart", {
"type": "serial",
"theme": "light",
"legend": {
"horizontalGap": 10,
"maxColumns": 1,
"position": "right",
"useGraphSettings": true,
"markerSize": 10
},
"dataProvider": [{
"year": 2003,
"europe": 2.5,
"namerica": 2.5,
"asia": 2.1,
"lamerica": 0.3,
"meast": 0.2,
"africa": 0.1
}, {
"year": 2004,
"europe": 2.6,
"namerica": 2.7,
"asia": 2.2,
"lamerica": 0.3,
"meast": 0.3,
"africa": 0.1
}, {
"year": 2005,
"europe": 2.8,
"namerica": 2.9,
"asia": 2.4,
"lamerica": 0.3,
"meast": 0.3,
"africa": 0.1
}],
"valueAxes": [{
"stackType": "regular",
"axisAlpha": 0.3,
"gridAlpha": 0
}],
"graphs": [{
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Europe",
"type": "column",
"color": "#000000",
"valueField": "europe"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "North America",
"type": "column",
"color": "#000000",
"valueField": "namerica"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Asia-Pacific",
"type": "column",
"color": "#000000",
"valueField": "asia"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Latin America",
"type": "column",
"color": "#000000",
"valueField": "lamerica"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Middle-East",
"type": "column",
"color": "#000000",
"valueField": "meast"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Africa",
"type": "column",
"color": "#000000",
"valueField": "africa"
}],
"categoryField": "year",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"gridAlpha": 0,
"position": "left"
},
"export": {
"enabled": true
}});

Property in Amcharts to set balloon alignment?

Does anybody have any idea about the property that changes the alignment of the balloon in amcharts to the one in figure 1. By default the balloon alignment in the charts rendered in my project is as in figure 2, which sometimes leads to truncation and overflow as shown in figure 3 if the balloon-text is too long.Hoping that alignment of balloon-text as shown in figure 1 will help me resolve this issue.
What you are probably looking for is a fixed position for the rollover balloon.
This can be achieved by setting fixedPosition in your balloon settings. I.e.:
"balloon": {
"fixedPosition": true
}
Another solution is to enable chart cursor. When chart cursor is enabled all balloons will be adaptively displayed either to the left or to the right of the column center.
Here's a chart cursor that is set up to not display anything beyond a single balloon of the hovered column segment:
"chartCursor": {
"cursorAlpha": 0,
"oneBalloonOnly": true
}
Finally, the very long continuous strings can be a problem as well. I suggest you use \n symbol to add line break points into those. I.e.:
"title": "North Americaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaa",
Here's a complete working demo:
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"legend": {
"horizontalGap": 10,
"maxColumns": 1,
"position": "right",
"useGraphSettings": true,
"markerSize": 10
},
"dataProvider": [{
"year": 2003,
"europe": 2.5,
"namerica": 2.5,
"asia": 2.1,
"lamerica": 0.3,
"meast": 0.2,
"africa": 0.1
}, {
"year": 2004,
"europe": 2.6,
"namerica": 2.7,
"asia": 2.2,
"lamerica": 0.3,
"meast": 0.3,
"africa": 0.1
}, {
"year": 2005,
"europe": 2.8,
"namerica": 2.9,
"asia": 2.4,
"lamerica": 0.3,
"meast": 0.3,
"africa": 0.1
}],
"valueAxes": [{
"stackType": "regular",
"axisAlpha": 0.3,
"gridAlpha": 0
}],
"graphs": [{
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Europe",
"type": "column",
"color": "#000000",
"valueField": "europe"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "North Americaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaa",
"type": "column",
"color": "#000000",
"valueField": "namerica"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Asia-Pacific",
"type": "column",
"color": "#000000",
"valueField": "asia"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Latin America",
"type": "column",
"color": "#000000",
"valueField": "lamerica"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Middle-East",
"type": "column",
"color": "#000000",
"valueField": "meast"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Africa",
"type": "column",
"color": "#000000",
"valueField": "africa"
}],
"balloon": {
"fixedPosition": true,
"maxWidth": 10000
},
"chartCursor": {
"cursorAlpha": 0,
"oneBalloonOnly": true
},
"categoryField": "year",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"gridAlpha": 0,
"position": "left"
},
"export": {
"enabled": true
}
});
#chartdiv {
width: 1000px;
height: 500px;
}
<script src="http://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="http://www.amcharts.com/lib/3/serial.js"></script>
<script src="http://www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv"></div>

How to specify colors of stack categories in stacked column chart of amCharts?

I am using a stacked column chart from amCharts. It picks default colors for the categories.
Can I change the colors of the stacks? I want to specify the colors myself. How would I do that?
http://jsfiddle.net/jn2695pc/
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "none",
"legend": {
"horizontalGap": 10,
"maxColumns": 1,
"position": "right",
"useGraphSettings": true,
"markerSize": 10
},
"dataProvider": [{
"year": 2003,
"europe": 2.5,
"namerica": 2.5,
"asia": 2.1,
"lamerica": 0.3,
"meast": 0.2,
"africa": 0.1
}, {
"year": 2004,
"europe": 2.6,
"namerica": 2.7,
"asia": 2.2,
"lamerica": 0.3,
"meast": 0.3,
"africa": 0.1
}, {
"year": 2005,
"europe": 2.8,
"namerica": 2.9,
"asia": 2.4,
"lamerica": 0.3,
"meast": 0.3,
"africa": 0.1
}],
"valueAxes": [{
"stackType": "regular",
"axisAlpha": 0.3,
"gridAlpha": 0
}],
"graphs": [{
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Europe",
"type": "column",
"color": "#000000",
"valueField": "europe"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "North America",
"type": "column",
"color": "#000000",
"valueField": "namerica"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Asia-Pacific",
"type": "column",
"color": "#000000",
"valueField": "asia"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Latin America",
"type": "column",
"color": "#000000",
"valueField": "lamerica"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Middle-East",
"type": "column",
"color": "#000000",
"valueField": "meast"
}, {
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Africa",
"type": "column",
"color": "#000000",
"valueField": "africa"
}],
"categoryField": "year",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"gridAlpha": 0,
"position": "left"
},
"exportConfig":{
"menuTop":"20px",
"menuRight":"20px",
"menuItems": [{
"icon": '/lib/3/images/export.png',
"format": 'png'
}]
}
});
Just add in the "fillColors": "#ffffff",
to each of your "graphs": [..]
This will fill it with white:
ie.
"graphs": [{
"balloonText": "<b>[[title]]</b><br><span style='font-size:14px'>[[category]]: <b>[[value]]</b></span>",
"fillAlphas": 0.8,
"labelText": "[[value]]",
"lineAlpha": 0.3,
"title": "Europe",
"type": "column",
"color": "#000000",
"fillColors": "#ffffff",
"valueField": "europe"
},

Resources