Y-Axis label prefix for XY Amcharts - amcharts

I didn't find any solution how to add prefix/suffix for Y-Axis of XYAmChart. Seems like labelFunction are not supported for valueAxes in XY chart type. Any suggestions?
var chart = AmCharts.makeChart("chartdiv", {
"type": "xy",
"theme": "light",
"dataDateFormat": "DD-MM-YYYY",
"graphs": [
{
"id":"g8",
"balloon":{
"drop":true,
"adjustBorderColor":false,
"color":"#ffffff"
},
"bullet":"round",
"bulletBorderAlpha":1,
"bulletColor":"#FFFFFF",
"bulletSize":5,
"dashLength":0,
"hideBulletsCount":50,
"lineThickness":2,
"lineColor":"#67b7dc",
"title":"Store 8",
"useLineColorForBulletBorder":true,
"xField":"d-1-c2",
"yField":"p-1-c2",
"xAxis":"g8",
"balloonText":"<span style='font-size:18px;'>[[d-1-c2]]</span><br>07/1/2017-12/31/2017"
},
{
"id":"g8-copy1",
"balloon":{
"drop":true,
"adjustBorderColor":false,
"color":"#ffffff"
},
"bullet":"round",
"bulletBorderAlpha":1,
"bulletColor":"#FFFFFF",
"bulletSize":5,
"dashLength":15,
"hideBulletsCount":50,
"lineThickness":2,
"lineColor":"#67b7dc",
"title":"Store 8",
"useLineColorForBulletBorder":true,
"xField":"d-1-c1",
"yField":"p-1-c1",
"xAxis":"g8-copy1",
"balloonText":"<span style='font-size:18px;'>[[d-1-c1]]</span><br>1/1/2017-6/29/2017"
}
],
"valueAxes": [
{
"id": "g8",
"axisAlpha": 1,
"gridAlpha": 1,
"axisColor": "#b0de09",
"color": "#b0de09",
"dashLength": 5,
"centerLabelOnFullp": true,
"position": "bottom",
"type": "date",
"minp": "DD-MM-YYYY",
"markPeriodChange": false,
"labelFunction": function(value, valueText) {
return "prefix:" + valueText;
}
},
{
"id": "g8-copy1",
"gridAlpha": 0,
"axisAlpha": 1,
"centerLabelOnFullp": false,
"position": "bottom",
"offset": 40,
"type": "date",
"minp": "DD-MM-YYYY",
'markPeriodChange': false,
"labelFunction": function(value, valueText) {
return "prefix:" + valueText;
}
}
],
"dataProvider": [
{
"d-1-c2":"01/01/2017",
"p-1-c2":"5684.6400"
},{
"d-1-c2":"01/02/2017",
"p-1-c2":"6468.9600"
},{
"d-1-c2":"01/03/2017",
"p-1-c2":"9032.7600"
},{
"d-1-c2":"01/04/2017",
"p-1-c2":"6385.9200"
},{
"d-1-c2":"01/05/2017",
"p-1-c2":"10087.3900"
},{
"d-1-c2":"01/06/2017",
"p-1-c2":"6136.3300"
},
{
"d-1-c1":"01/07/2017",
"p-1-c1":"4659.7000"
},{
"d-1-c1":"01/08/2017",
"p-1-c1":"9719.7100"
},{
"d-1-c1":"01/09/2017",
"p-1-c1":"4789.7300"
},{
"d-1-c1":"01/10/2017",
"p-1-c1":"7448.3900"
},{
"d-1-c1":"01/11/2017",
"p-1-c1":"6202.7200"
},{
"d-1-c1":"01/12/2017",
"p-1-c1":"9274.0300"
},{
"d-1-c1":"01/01/2018"
},{
"d-1-c2":"01/07/2017"
}
]
});
#chartdiv {
width: 100%;
height: 500px;
}
<script src="//www.amcharts.com/lib/3/amcharts.js"></script>
<script src="//www.amcharts.com/lib/3/xy.js"></script>
<script src="//www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv"></div>

labelFunction is definitely supported as you can see below.
"valueAxes": [ {
"position": "bottom",
"axisAlpha": 0,
"labelFunction": function(value, valueText) {
return "prefix:" + valueText;
}
}, {
"minMaxMultiplier": 1.2,
"axisAlpha": 0,
"position": "left",
"labelFunction": function(value, valueText) {
return "prefix:" + valueText;
}
} ],
Demo:
var chart = AmCharts.makeChart( "chartdiv", {
"type": "xy",
"theme": "light",
"balloon":{
"fixedPosition":true,
},
"dataProvider": [ {
"y": 10,
"x": 14,
"value": 59,
"y2": -5,
"x2": -3,
"value2": 44
}, {
"y": 5,
"x": 3,
"value": 50,
"y2": -15,
"x2": -8,
"value2": 12
}, {
"y": -10,
"x": 8,
"value": 19,
"y2": -4,
"x2": 6,
"value2": 35
}, {
"y": -6,
"x": 5,
"value": 65,
"y2": -5,
"x2": -6,
"value2": 168
}, {
"y": 15,
"x": -4,
"value": 92,
"y2": -10,
"x2": -8,
"value2": 102
}, {
"y": 13,
"x": 1,
"value": 8,
"y2": -2,
"x2": 0,
"value2": 41
}, {
"y": 1,
"x": 6,
"value": 35,
"y2": 0,
"x2": -3,
"value2": 16
} ],
"valueAxes": [ {
"position": "bottom",
"axisAlpha": 0,
"labelFunction": function(value, valueText) {
return "prefix:" + valueText;
}
}, {
"minMaxMultiplier": 1.2,
"axisAlpha": 0,
"position": "left",
"labelFunction": function(value, valueText) {
return "prefix:" + valueText;
}
} ],
"startDuration": 1.5,
"graphs": [ {
"balloonText": "x:<b>[[x]]</b> y:<b>[[y]]</b><br>value:<b>[[value]]</b>",
"bullet": "circle",
"bulletBorderAlpha": 0.2,
"bulletAlpha": 0.8,
"lineAlpha": 0,
"fillAlphas": 0,
"valueField": "value",
"xField": "x",
"yField": "y",
"maxBulletSize": 100
}, {
"balloonText": "x:<b>[[x]]</b> y:<b>[[y]]</b><br>value:<b>[[value]]</b>",
"bullet": "diamond",
"bulletBorderAlpha": 0.2,
"bulletAlpha": 0.8,
"lineAlpha": 0,
"fillAlphas": 0,
"valueField": "value2",
"xField": "x2",
"yField": "y2",
"maxBulletSize": 100
} ]
} );
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/xy.js"></script>
<script src="//www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv"></div>
You can also use unit and unitPosition if your custom labeling doesn't
require any additional logic that you can leverage through labelFunction.
"valueAxes": [ {
"position": "bottom",
"axisAlpha": 0,
"unit": "unit-prefix:",
"unitPosition": "left"
}, {
"minMaxMultiplier": 1.2,
"axisAlpha": 0,
"position": "left",
"unit": "unit-prefix:",
"unitPosition": "left"
} ],
Demo below.
var chart = AmCharts.makeChart( "chartdiv", {
"type": "xy",
"theme": "light",
"balloon":{
"fixedPosition":true,
},
"dataProvider": [ {
"y": 10,
"x": 14,
"value": 59,
"y2": -5,
"x2": -3,
"value2": 44
}, {
"y": 5,
"x": 3,
"value": 50,
"y2": -15,
"x2": -8,
"value2": 12
}, {
"y": -10,
"x": 8,
"value": 19,
"y2": -4,
"x2": 6,
"value2": 35
}, {
"y": -6,
"x": 5,
"value": 65,
"y2": -5,
"x2": -6,
"value2": 168
}, {
"y": 15,
"x": -4,
"value": 92,
"y2": -10,
"x2": -8,
"value2": 102
}, {
"y": 13,
"x": 1,
"value": 8,
"y2": -2,
"x2": 0,
"value2": 41
}, {
"y": 1,
"x": 6,
"value": 35,
"y2": 0,
"x2": -3,
"value2": 16
} ],
"valueAxes": [ {
"position": "bottom",
"axisAlpha": 0,
"unit": "unit-prefix:",
"unitPosition": "left"
}, {
"minMaxMultiplier": 1.2,
"axisAlpha": 0,
"position": "left",
"unit": "unit-prefix:",
"unitPosition": "left"
} ],
"startDuration": 1.5,
"graphs": [ {
"balloonText": "x:<b>[[x]]</b> y:<b>[[y]]</b><br>value:<b>[[value]]</b>",
"bullet": "circle",
"bulletBorderAlpha": 0.2,
"bulletAlpha": 0.8,
"lineAlpha": 0,
"fillAlphas": 0,
"valueField": "value",
"xField": "x",
"yField": "y",
"maxBulletSize": 100
}, {
"balloonText": "x:<b>[[x]]</b> y:<b>[[y]]</b><br>value:<b>[[value]]</b>",
"bullet": "diamond",
"bulletBorderAlpha": 0.2,
"bulletAlpha": 0.8,
"lineAlpha": 0,
"fillAlphas": 0,
"valueField": "value2",
"xField": "x2",
"yField": "y2",
"maxBulletSize": 100
} ]
} );
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/xy.js"></script>
<script src="//www.amcharts.com/lib/3/themes/light.js"></script>
<div id="chartdiv"></div>

Related

How do I apply y Axis min and max values ​to a chart of type: xy?

I want to apply minimum 0 and maximum 1 to the y and x axes of a type: xy graph in html.
in EJS, i graphed the code from the first answer in Creating a "normal" line chart in amcharts.js with arrays?
html
<div id="chartdiv2"></div>
js
var y = [0,0.8481,1];
var y0 = [0,0.5,1];
var y1 = [0,0.8957,1];
var y2 = [0,0.9088,1];
var y3 = [0,0.6256,0.6745,0.8911,1];
var x = [0,0.0342,1];
var x0 = [0,0.5,1];
var x1 = [0,0.1152,1];
var x2 = [0,0.0297,1];
var x3 = [0,0.0297,0.0342,0.1152,1];
var chartData = [];
for( var i = 0; i < x.length; i++ ) {
chartData.push( {
"x": x[ i ],
"y": y[ i ],
"x0": x0[ i ],
"y0": y0[ i ],
"y1": y1[ i ],
"x1": x1[ i ],
"y2": y2[ i ],
"x2": x2[ i ],
} )
}
for( var i = 0; i < x3.length; i++ ) {
chartData.push( {
"y3": y3[ i ],
"x3": x3[ i ]
} );
}
var chart = AmCharts.makeChart( "chartdiv2",{
"type": "xy",
"pathToImages": "https://www.amcharts.com/lib/3/images/",
"dataProvider": chartData,
"graphs": [
{
"bullet": null,
"bulletSize": 0,
"lineAlpha": 1,
"lineThickness": 2,
"fillAlphas": 0,
"xField": "x",
"yField": "y",
},{
"bullet": null,
"bulletSize": 0,
"lineAlpha": 1,
"lineThickness": 2,
"fillAlphas": 0,
"xField": "x1",
"yField": "y1",
},{
"bullet": null,
"bulletSize": 0,
"lineAlpha": 1,
"lineThickness": 2,
"fillAlphas": 0,
"xField": "x2",
"yField": "y2",
},{
"bullet": null,
"bulletSize": 0,
"lineAlpha": 1,
"lineThickness": 2,
"fillAlphas": 0,
"xField": "x3",
"yField": "y3",
},{
"bullet": null,
"bulletSize": 0,
"lineAlpha": 1,
"lineThickness": 2,
"fillAlphas": 0,
"xField": "x0",
"yField": "y0",
}
],"yAxes": [{
"type": "ValueAxis",
"min": 0,
"max": 1
}],"xAxes": [{
"type": "ValueAxis",
"min": 0,
"max": 1
}]
});
https://www.amcharts.com/docs/v4/concepts/axes/value-axis/
"yAxes": [{
"type": "ValueAxis",
"min": 0,
"max": 1
}],"xAxes": [{
"type": "ValueAxis",
"min": 0,
"max": 1
}]
Applying the code above does not change the minimum and maximum of the y and x axes to 0 and 1.
in addition, i'm not sure if this is the correct way.
You're mixing the two versions up. The value axis documentation you linked to is for version 4, whereas the majority of your code (and the linked stackoverflow question) is using version 3, which defines value axes like this:
"valueAxes": [{
"minimum": 0,
"maximum": 1,
"position": "left"
},{
"minimum": 0,
"maximum": 1,
"position": "bottom"
}]
Updated demo using version 3:
var y = [0,0.8481,1];
var y0 = [0,0.5,1];
var y1 = [0,0.8957,1];
var y2 = [0,0.9088,1];
var y3 = [0,0.6256,0.6745,0.8911,1];
var x = [0,0.0342,1];
var x0 = [0,0.5,1];
var x1 = [0,0.1152,1];
var x2 = [0,0.0297,1];
var x3 = [0,0.0297,0.0342,0.1152,1];
var chartData = [];
for( var i = 0; i < x.length; i++ ) {
chartData.push( {
"x": x[ i ],
"y": y[ i ],
"x0": x0[ i ],
"y0": y0[ i ],
"y1": y1[ i ],
"x1": x1[ i ],
"y2": y2[ i ],
"x2": x2[ i ],
} )
}
for( var i = 0; i < x3.length; i++ ) {
chartData.push( {
"y3": y3[ i ],
"x3": x3[ i ]
} );
}
var chart = AmCharts.makeChart( "chartdiv2",{
"type": "xy",
"pathToImages": "https://www.amcharts.com/lib/3/images/",
"dataProvider": chartData,
"graphs": [
{
"bullet": null,
"bulletSize": 0,
"lineAlpha": 1,
"lineThickness": 2,
"fillAlphas": 0,
"xField": "x",
"yField": "y",
},{
"bullet": null,
"bulletSize": 0,
"lineAlpha": 1,
"lineThickness": 2,
"fillAlphas": 0,
"xField": "x1",
"yField": "y1",
},{
"bullet": null,
"bulletSize": 0,
"lineAlpha": 1,
"lineThickness": 2,
"fillAlphas": 0,
"xField": "x2",
"yField": "y2",
},{
"bullet": null,
"bulletSize": 0,
"lineAlpha": 1,
"lineThickness": 2,
"fillAlphas": 0,
"xField": "x3",
"yField": "y3",
},{
"bullet": null,
"bulletSize": 0,
"lineAlpha": 1,
"lineThickness": 2,
"fillAlphas": 0,
"xField": "x0",
"yField": "y0",
}
],"yAxes": [{
"type": "ValueAxis",
"min": 0,
"max": 1
}],"xAxes": [{
"type": "ValueAxis",
"min": 0,
"max": 1
}]
});
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/xy.js"></script>
<div id="chartdiv2" style="width: 100%; height: 300px;"></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>

Multiple stacked charts on same page

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>

How do I suppress graph values from appearing in the legend on mouseover in AmCharts?

I am using AmCharts with a legend and chart cursor enabled however I don't want the graph values to appear in the legend on mouseover. How do I disable that? Please see my screenshot.
Chart Image
Assuming you're using the regular serial chart (post your code next time), you can suppress the legend value on mouseover by setting the legend's valueText to an empty string, e.g.
AmCharts.makeChart("chartdiv", {
// ...
legend: {
valueText: "",
// ...
},
// ...
});
Demo below:
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"legend": {
"useGraphSettings": true,
"valueText": ""
},
"dataProvider": [{
"year": 1930,
"italy": 1,
"germany": 5,
"uk": 3
}, {
"year": 1934,
"italy": 1,
"germany": 2,
"uk": 6
}, {
"year": 1938,
"italy": 2,
"germany": 3,
"uk": 1
}, {
"year": 1950,
"italy": 3,
"germany": 4,
"uk": 1
}, {
"year": 1954,
"italy": 5,
"germany": 1,
"uk": 2
}, {
"year": 1958,
"italy": 3,
"germany": 2,
"uk": 1
}],
"valueAxes": [{
"integersOnly": true,
"maximum": 6,
"minimum": 1
}],
"startDuration": 0,
"graphs": [{
"balloonText": "place taken by Italy in [[category]]: [[value]]",
"bullet": "round",
"title": "Italy",
"valueField": "italy",
"fillAlphas": 0
}, {
"balloonText": "place taken by Germany in [[category]]: [[value]]",
"bullet": "round",
"title": "Germany",
"valueField": "germany",
"fillAlphas": 0
}, {
"balloonText": "place taken by UK in [[category]]: [[value]]",
"bullet": "round",
"title": "United Kingdom",
"valueField": "uk",
"fillAlphas": 0
}],
"chartCursor": {
"zoomable": false
},
"categoryField": "year"
});
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<div id="chartdiv" style="width: 100%; height: 300px"></div>

About Y-axis scale in amCharts

I am facing problem with scale on vertical axis like 2,4,6,8,10 etc or 5,10,15,20. I have achieved this on one axis (name Iron in ppm) but how to achieve this on second y-axis?
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "light",
"id": "SweepGraph",
"legend": {
"marginTop": 150,
"useGraphSettings": true
},
"synchronizeGrid": synchronizeGridFlag,
"dataProvider": SortedChartData,
"valueAxes": [{
"id": "BaseNumber",
"axisColor": "#0000ff",
"axisThickness": 2,
"axisAlpha": 1,
"position": "right",
"title": "BaseNumber in mgKOH/g",
"minimum" : BaseNumberMinimum,
"maximum": BaseNumberMaximum,
"autoGridCount": false,
"gridCount": 100,
"synchronizationMultiplier": ironLabelFrequency,
"strictMinMax": true,
//"synchronizationMultiplier": BaseNumberLabelFrequency
}, {
"id": "Iron",
"maximum": IronMaximum,
"minimum": IronMinimum,
"minMaxMultiplier": 0,
"precision": 0,
"synchronizationMultiplier": ironLabelFrequency,
"synchronizeWith": "BaseNumber",
"strictMinMax": true,
"axisAlpha": 1,
"axisColor": "#ff0000",
"axisThickness": 2,
"gridCount": 100,
"gridThickness": 0,
"minHorizontalGap": 0,
"minVerticalGap": 0,
"title": "Iron in ppm"
}],
"graphs": AmCharts.parseJSON(graphData),
"chartScrollbar": {},
"chartCursor": {
"cursorPosition": "pointer",
"oneBalloonOnly": true,
"valueZoomable":true
},
"guides":GlobalSweepGuides,
"categoryField": "FeedRate",
"categoryAxis": {
"gridPosition": "start",
"title": "ACC Value in (g/Kw/h)/(%wt)",
"axisColor": "#DADADA",
"minorGridEnabled": true,
"autoGridCount": false,
"gridCount": 12
},
"export": {
"enabled": true,
"menu": [],
"libs": {
"path": "http://www.amcharts.com/lib/3/plugins/export/libs/"
},
"position": "bottom-right"
}
});
Here is jsFiddle url:https://jsfiddle.net/HARSHAD557/jgz289fw/
Please solve this problem.

Resources