Reputation: 25
I'm displaying a rotated bar chart in amCharts. I need to display the label for each bar, regardless of the value. If the value is zero, no bar displays so the label doesn't display. Is there a way I can always show the label, regardless of value?
Or better yet, is there a way that I can make the graph.labelOffset reference a function that will return a different amount depending on the value?
Here's a Fiddle of what I'm working with. Notice that the 3rd item has a value of 0, so no label displays.
Here's the javascript code for the chart.
var gamingData = [
{
"label": "1",
"name": "Thinone",
"grade": 30,
"pounds": 3.6,
"percentage": 2.3
},
{
"label": "2",
"name": "Studmuffin",
"grade": 60,
"pounds": 3.6,
"percentage": 2.3
},
{
"label": "3",
"name": "Slacker",
"grade": 0,
"pounds": 3.6,
"percentage": 2.3
},
{
"label": "4",
"name": "Momof2",
"grade": 60,
"pounds": 3.6,
"percentage": 2.3
},
{
"label": "5",
"name": "TheVas",
"grade": 120,
"pounds": 3.6,
"percentage": 2.3
}];
var displayGamingChart = function(gamingData, chartDiv) {
var chart = AmCharts.makeChart(chartDiv, {
"theme": "light",
"type": "serial",
"dataProvider": gamingData,
"graphs": [{
"balloonText": "Down [[pounds]]lbs and [[percentage]]%",
"fillAlphas": 1,
"lineAlpha": 0.2,
// "title": "Minutes",
"type": "column",
"valueField": "grade",
"labelText": "[[name]]",
"labelOffset": -75,
"legendValueText": "",
"fillColors": "#94BA65"
}],
"startDuration": 1,
"depth3D": 20,
"angle": 30,
"rotate": true,
"categoryField": "label",
"categoryAxis": {
"gridPosition": "start",
"fillAlpha": 0.05,
"position": "left"
},
"export": {
"enabled": true
}
});
}
displayGamingChart(gamingData, "gamingChart");
Upvotes: 1
Views: 2304
Reputation: 8595
To force display of labels, even those that do not fit, set showAllValueLabels
to true
in your graph's config:
"graphs": [{
"balloonText": "Down [[pounds]]lbs and [[percentage]]%",
"fillAlphas": 1,
"lineAlpha": 0.2,
// "title": "Minutes",
"type": "column",
"valueField": "grade",
"labelText": "[[name]]",
"labelOffset": -75,
"legendValueText": "",
"fillColors": "#94BA65",
"showAllValueLabels": true
}]
As for the second part of your question, there's no function that would differentiate label offset for each bar individually.
Upvotes: 1