Skip to content

Instantly share code, notes, and snippets.

@xxswingxx
Created October 22, 2019 14:03
Show Gist options
  • Save xxswingxx/a3ba92d49b1901b8ad5b3be638684563 to your computer and use it in GitHub Desktop.
Save xxswingxx/a3ba92d49b1901b8ad5b3be638684563 to your computer and use it in GitHub Desktop.
amchart month column chart with date parsing
<!-- Styles -->
<style>
#chartdiv {
width : 100%;
height : 500px;
}
</style>
<!-- Resources -->
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/serial.js"></script>
<!-- Chart code -->
<script>
function customLabelFunction(valueText, date, categoryAxis) {
return (date.getMonth() + 1) + "/" + date.getFullYear().toString().substr(-2)
}
var chart = AmCharts.makeChart("chartdiv", {
"type": "serial",
"theme": "none",
"marginRight": 40,
"marginLeft": 40,
"autoMarginOffset": 0,
"mouseWheelZoomEnabled":false,
"dataDateFormat": "YYYY-MM",
"valueAxes": [{
"id": "v1",
"zeroGridAlpha": 1,
"axisThickness": 0,
"axisAlpha": 0,
"gridCount": 0,
"position": "left",
}],
"graphs": [{
"type":"column",
"id": "g1",
"showBalloon":false,
"bulletBorderThickness": 0,
"bulletSize": 0,
"maxBulletSize": 0,
"minBulletSize": 0,
"hideBulletsCount": 50,
"lineThickness": 0,
"fillAlphas": 1,
"columnWidth": 0.75,
"valueField": "value",
}],
"chartCursor": {},
"categoryField": "month",
"categoryAxis": {
"parseDates": true,
"axisAlpha": 0,
"axisThickness": 0,
"labelFrequency": 1,
"minorGridAlpha": 0,
"minorGridEnabled": false,
"minPeriod": "MM",
"labelFunction": customLabelFunction
},
"dataProvider": [{
"month": "2012-07",
"value": 13
}, {
"month": "2012-08",
"value": 13
}, {
"month": "2012-09",
"value": 35
}, {
"month": "2012-10",
"value": 46
}, {
"month": "2012-12",
"value": 66
}, {
"month": "2013-01",
"value": 67
}, {
"month": "2013-02",
"value": 64
}, {
"month": "2013-03",
"value": 66
}, {
"month": "2013-04",
"value": 60
}, {
"month": "2013-05",
"value": 63
}, {
"month": "2013-07",
"value": 61
}, {
"month": "2013-08",
"value": 60
}]
});
</script>
<!-- HTML -->
<div id="chartdiv"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment