Amcharts- Stacked column not stacked - amcharts

I'm trying to plot a stacked column graph. Instead of the various components being one on top of the other, they are appearing one next to the other.
Here's the property I'm using
var stackedProps= {
type: "serial",
titles: [{
text: "STACKED CHART",
size: 24,
alpha: 5
}],
valueAxis: [{
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,
lineAlpha: 0.3,
title: "AAAA",
type: "column",
color: "#000000",
valueField: "AAAA"
}, {
balloonText: "<b>[[title]]</b><br><span style='font-size:5px'>[[category]]: <b>[[value]]</b></span>",
fillAlphas: 0.8,
lineAlpha: 0.3,
title: "BBBB",
type: "column",
color: "#000000",
valueField: "BBBB"
}
};
My understanding is that the property stackType: "regular" is responsible for stacking the items one on top of the other.
Could I please request help to identify the mistake?

The serial charts support multiple value axes. Therefore the property is valueAxes (plural form).
If you have it as "valueAxis" (as it seems the case in your code), it is ignored by the chart like any other unknown property, hence columns not being stacked.
So bottom line, if you want to stack your columns, you define valueAxes. If you don't want to stack them, you can completely leave out that part. (unless you want to set some other value axis settings)

Related

Title under chart in amCharts

I need to place title & subtitle under my chart in amCharts library. I tried to use label but I can only place a label in chart area. Anyone got an idea?
Titles can only be placed on the top of the chart. You can use labels to mimic the title functionality by using percent-based x/y coordinates, but you have to set your own margins as labels don't automatically shift the chart margins like titles do. You have to set autoMargins to false and then set your own chart margins, especially marginBottom, in order to give your labels enough space to render on the bottom:
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"autoMargins": false,
"marginLeft": 50,
"marginRight": 20,
"marginBottom": 100,
"allLabels": [{
"x": "50%",
"align": "middle",
"y": "89%",
"bold": true,
"size": 16,
"text": "My Chart Title"
},{
"x": "50%",
"align": "middle",
"y": "94%",
"text": "My Chart Sub-Title"
}],
// ...
});
Here's a demo

why my cursor in Amcharts is "move" hover in chart ?

Why does my cursor show this:
How do I change to default cursor?
This is my code config of amcharts for use in clone function to makeChart
var chartConfig = {
"type": "serial",
"categoryField": "period",
"addClassNames": true,
"startDuration": 1,
"categoryAxis": {
"gridPosition": "start"
},
"trendLines": [],
"graphs": [ {
"bulletField": "last",
"id": "", // id graph
"lineThickness": 4,
"title": "Redemption",
"valueField": "total",
"lineColor": "#ffffff",
}],
"chartCursor": {
"pan": true,
"valueLineEnabled": false,
"valueLineBalloonEnabled": false,
"categoryBalloonEnabled": false,
"cursorAlpha":0,
"cursorColor":"#000000",
"limitToGraph":"", id graph
"valueLineAlpha":0,
"valueZoomable":true,
},
"balloon": {
"adjustBorderColor" : false,
"borderColor": "#000000"
},
}
i delete some line because it show code mostly line and less detail .
can i fix it ?
thank you
The cursor is changed that way if you set the chartCursor's pan property to true. It seems like you have a very small chart in your screenshot, so you can disable the pan and set the zoomable property to false if you want a chartCursor that doesn't zoom.
chartCursor: {
pan: false,
zoomable: false,
// other config
}
Demo
Alternatively, if you need the pan functionality, you can override the cursor using css (assuming your chart div's id is chartdiv):
#chartdiv div {
cursor: default !important;
}
Demo

Image at bottom in every column on amcharts

I've tried to gather information about if it is possible to put a different image located at the bottom of every column in a 100% stacked bar chart.
I've seen that is possible to modify some attributes of category labels and put images just above every bar as http://www.amcharts.com/demos/column-chart-images-top/ but I need just the opposite.
In other words, I want to make the base of the column has an image loaded, replacing x axis and category label.
Thanks in advance.
Unfortunately, Category axis does not allow using images in place of category labels.
There's also no way to make the custom bullets from graphs "trickle" outside plot area.
What you can do is to drop those custom icons right down just above category axis line.
To do that you will need:
1) Add additional fields to your data that would contain all zero values.
2) Add a separate graph that would use those fields and display custom bullets.
3) Make the "bullet graph" non-stackable (stackable: false), not clustered (clustered: false), and generally invisible (visibleInLegend: false, fillAlphas: 0, lineAlpha: 0, showBalloon: false)
Here's a working example:
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"dataProvider": [{
"name": "John",
"points": 35022,
"color": "#7F8DA9",
"zero": 0,
"bullet": "//www.amcharts.com/lib/3/images/0.gif"
}, {
"name": "Damon",
"points": 65456,
"color": "#FEC514",
"zero": 0,
"bullet": "//www.amcharts.com/lib/3/images/1.gif"
}, {
"name": "Patrick",
"points": 45724,
"color": "#DB4C3C",
"zero": 0,
"bullet": "//www.amcharts.com/lib/3/images/2.gif"
}, {
"name": "Mark",
"points": 13654,
"color": "#DAF0FD",
"zero": 0,
"bullet": "//www.amcharts.com//lib/3/images/3.gif"
}],
"valueAxes": [{
"maximum": 80000,
"minimum": 0,
"axisAlpha": 0,
"dashLength": 4,
"position": "left"
}],
"startDuration": 1,
"graphs": [{
"balloonText": "<span style='font-size:13px;'>[[category]]: <b>[[value]]</b></span>",
"colorField": "color",
"fillAlphas": 0.8,
"lineAlpha": 0,
"type": "column",
"valueField": "points"
}, {
"showBalloon": false,
"bulletOffset": 16,
"bulletSize": 34,
"customBulletField": "bullet",
"fillAlphas": 0,
"lineAlpha": 0,
"type": "column",
"visibleInLegend": false,
"clustered": false,
"stackable": false,
"valueField": "zero"
}],
"categoryField": "name",
"categoryAxis": {
"axisAlpha": 0,
"gridAlpha": 0,
"tickLength": 0
}
});
<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" style="width: 100%; height: 200px;"></div>
Additionally, if you don't need the text labels on the category axis, you can set it's labelsEnabled: false property.

How to add CategoryAxis in amcharts?

I need to be able to draw a vertical line in the graph and seems easy enough using this information: http://www.amcharts.com/tutorials/vertical-or-horizontal-lines-or-fill-ranges/
However, I am not finding a way to add the CategoryAxis property to the existing chart.
If you are using an object-based configuration, when you create a chart instance it will already have categoryAxis property set:
var chart = new AmCharts.AmSerialChart();
// chart.categoryAxis is already set and populated with a reference to CategoryAxis object
// we can set its properties, including guides
chart.categoryAxis.guides = [ {
"category": "2001",
"toCategory": "2003",
"lineColor": "#CC0000",
"lineAlpha": 1,
"fillAlpha": 0.2,
"fillColor": "#CC0000",
"dashLength": 2,
"inside": true,
""label"Rotation": 90,
"label": "fines for speeding increased"
}, {
"category": "2007",
"lineColor": "#CC0000",
"lineAlpha": 1,
"dashLength": 2,
"inside": true,
""label"Rotation": 90,
"label": "motorcycle fee introduced"
} ];
If you are using JSON-based approach, the guides config needs to go into "categoryAxis" object:
AmCharts.makeChart( "chartdiv", {
"type": "serial",
"categoryAxis": {
"guides": [ {
"category": "2001",
"toCategory": "2003",
"lineColor": "#CC0000",
"lineAlpha": 1,
"fillAlpha": 0.2,
"fillColor": "#CC0000",
"dashLength": 2,
"inside": true,
""label"Rotation": 90,
"label": "fines for speeding increased"
}, {
"category": "2007",
"lineColor": "#CC0000",
"lineAlpha": 1,
"dashLength": 2,
"inside": true,
""label"Rotation": 90,
"label": "motorcycle fee introduced"
} ]
},
// the rest of the chart config
// ...
};

Why colours on an amcharts Candlestick Chart Incorrect and don't Change?

stockGraphs: [{
closeField: "close",
highField: "high",
lowField: "low",
openField: "open",
fillColors: "#009900",
lineColor: "#009900",
fillColorsField: "#009900",
lineAlpha: 1,
fillAlphas: 0.9,
negativeFillColors: "#000000",
negativeLineColor: "#000000",
title: "Price:",
type: "candlestick",
valueField: "close"'
},
The negative bars are coloured black. However the positive bars are: #ff6600.
Here is the Fiddle: http://jsfiddle.net/s8s8bbfd/
Add useDataSetColors: false to stockGraphs[0].
But the negative color doesn't apply on balloon. I don't understand why, with ohlc chart, it works...

Resources