Skip to content

Instantly share code, notes, and snippets.

@ronokdev
Created April 3, 2018 04:49
Show Gist options
  • Save ronokdev/7fa8fffa5c8bb5a7022fefd58575e5f0 to your computer and use it in GitHub Desktop.
Save ronokdev/7fa8fffa5c8bb5a7022fefd58575e5f0 to your computer and use it in GitHub Desktop.
Axis Color for Amchart Serial Chart
::: RefUrl for Dataloader → https://github.com/amcharts/dataloader
::: We are using "dataLoader" to load the data on Amchart.
::: Dataloader Function →
"dataLoader": {
"url": 'GraphUrl',
"format": "json",
"init": function ( options, chart ) {
console.log( 'Loading started' );
},
"load": function ( options, chart ) {
console.log( 'Loaded file FOR DISTRICT ' + options.url );
},
"complete": function ( chart ) {
console.log( 'Woohoo! Finished loading' );
// for Coloring the Axis---------START---------
for (i = 0; i < chart.graphs.length; i++) {
var graph = chart.graphs[i];
console.log(graph);
if (graph.fillColorsFunction !== undefined) {
graph.fillColorsField = graph.valueField + "FillColor";
var counter= 0;
for (var x = 0; x < chart.dataProvider.length; x++) {
if(counter == 10) {
counter = 0;
}
var dp = chart.dataProvider[x];
var colorKey = "autoColor-"+i;
graph.lineColorField = colorKey;
graph.fillColorsField = colorKey
var color = chart.colors[counter];
dp[graph.fillColorsField]= color;
counter++;
}
}
}
// for Coloring the Axis---------END---------
},
"error": function ( options, chart ) {
console.log( 'Ummm something went wrong loading this file: ' + options.url );
},
"progress": function( totalPercent, filePercent, url ) {
console.log( 'Total percent loaded: ' + Math.round( totalPercent ) );
},
},
"graphs": [{
"fillColorsFunction": "", //Very Important
"autoColor": true, //Very Important
}],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment