Amcharts chart looking good on preview page but not showing up on final webpage - amcharts

I'm kind of a noob, sorry if the answer is obvious but apparently nobody has asked that same question before.
I'm in the process of writing an article and I'm already using several other Amcharts charts in the article webpage (that are working just fine) like piecharts and sorted bar charts. Now, my problem is that my 100% stacked column charts seem to be working just fine on the plug-in preview mode but just never show up on the webpage, leaving a blank space instead.
This is really weird as that problem exists only with this type of charts, while the other ones appear and load just fine.
I've already given specific IDs to all charts and I made sure to give unique names to variables as well so that there are no duplicates that might screw everything up. Really I am clueless as to what the cause of that problem is and I need some help. Thank you in advance to whomever might be willing to assist me.
Here is the code for both 100% stacked column charts:
Chart 1
var chart10 = am4core.create("chartdiv10", am4charts.XYChart);
chart10.hiddenState.properties.opacity = 0; // this creates initial fade-in
chart10.data = [
{
category: "Matériaux utilisés",
value1: 5,
value2: 5,
value3: 5,
value4: 23,
value5: 39,
value6: 28,
value7: 24
},
{
category: "Marque",
value1: 6,
value2: 9,
value3: 5,
value4: 15,
value5: 39,
value6: 36,
value7: 19
},
{
category: "Possibilités de personnalisation",
value1: 19,
value2: 19,
value3: 28,
value4: 24,
value5: 12,
value6: 15,
value7: 12
},
{
category: "Label Swiss Made",
value1: 7,
value2: 9,
value3: 11,
value4: 23,
value5: 23,
value6: 17,
value7: 39
},
{
category: "Possibilités de revente",
value1: 38,
value2: 23,
value3: 16,
value4: 15,
value5: 16,
value6: 10,
value7: 11
},
{
category: "Ecoresponsabilité",
value1: 25,
value2: 20,
value3: 20,
value4: 21,
value5: 19,
value6: 9,
value7: 15
},
{
category: "Certifications officielles",
value1: 8,
value2: 6,
value3: 6,
value4: 16,
value5: 23,
value6: 33,
value7: 37
},
{
category: "Montre neuve",
value1: 13,
value2: 13,
value3: 6,
value4: 14,
value5: 18,
value6: 25,
value7: 40
},
]
chart10.padding(30, 30, 10, 30);
chart10.colors.list = [
am4core.color("#81BEF7"),
am4core.color("#58ACFA"),
am4core.color("#2E9AFE"),
am4core.color("#0080FF"),
am4core.color("#2E64FE"),
am4core.color("#0431B4"),
am4core.color("#0B2161")
];
var categoryAxis10 = chart10.xAxes.push(new am4charts.CategoryAxis());
categoryAxis10.dataFields.category = "category";
categoryAxis10.renderer.grid.template.location = 0;
var valueAxis10 = chart10.yAxes.push(new am4charts.ValueAxis());
valueAxis10.min = 0;
valueAxis10.max = 100;
valueAxis10.strictMinMax = true;
valueAxis10.calculateTotals = true;
valueAxis10.renderer.minWidth = 40;
var series110 = chart10.series.push(new am4charts.ColumnSeries());
series110.columns.template.width = am4core.percent(80);
series110.columns.template.tooltipText =
"{name}: {valueY.totalPercent.formatNumber('#.00')}%";
series110.name = "1";
series110.dataFields.categoryX = "category";
series110.dataFields.valueY = "value1";
series110.dataFields.valueYShow = "totalPercent";
series110.dataItems.template.locations.categoryX = 0.5;
series110.stacked = true;
series110.tooltip.pointerOrientation = "vertical";
var bullet110 = series110.bullets.push(new am4charts.LabelBullet());
bullet110.interactionsEnabled = false;
bullet110.label.text = "1";
bullet110.label.fill = am4core.color("#ffffff");
bullet110.locationY = 0.5;
var series210 = chart10.series.push(new am4charts.ColumnSeries());
series210.columns.template.width = am4core.percent(80);
series210.columns.template.tooltipText =
"{name}: {valueY.totalPercent.formatNumber('#.00')}%";
series210.name = "2";
series210.dataFields.categoryX = "category";
series210.dataFields.valueY = "value2";
series210.dataFields.valueYShow = "totalPercent";
series210.dataItems.template.locations.categoryX = 0.5;
series210.stacked = true;
series210.tooltip.pointerOrientation = "vertical";
var bullet210 = series210.bullets.push(new am4charts.LabelBullet());
bullet210.interactionsEnabled = false;
bullet210.label.text = "2";
bullet210.label.fill = am4core.color("#ffffff");
bullet210.locationY = 0.5;
var series310 = chart10.series.push(new am4charts.ColumnSeries());
series310.columns.template.width = am4core.percent(80);
series310.columns.template.tooltipText =
"{name}: {valueY.totalPercent.formatNumber('#.00')}%";
series310.name = "3";
series310.dataFields.categoryX = "category";
series310.dataFields.valueY = "value3";
series310.dataFields.valueYShow = "totalPercent";
series310.dataItems.template.locations.categoryX = 0.5;
series310.stacked = true;
series310.tooltip.pointerOrientation = "vertical";
var bullet310 = series310.bullets.push(new am4charts.LabelBullet());
bullet310.interactionsEnabled = false;
bullet310.label.text = "3";
bullet310.locationY = 0.5;
bullet310.label.fill = am4core.color("#ffffff");
var series410 = chart10.series.push(new am4charts.ColumnSeries());
series410.columns.template.width = am4core.percent(80);
series410.columns.template.tooltipText =
"{name}: {valueY.totalPercent.formatNumber('#.00')}%";
series410.name = "4";
series410.dataFields.categoryX = "category";
series410.dataFields.valueY = "value4";
series410.dataFields.valueYShow = "totalPercent";
series410.dataItems.template.locations.categoryX = 0.5;
series410.stacked = true;
series410.tooltip.pointerOrientation = "vertical";
var bullet410 = series410.bullets.push(new am4charts.LabelBullet());
bullet410.interactionsEnabled = false;
bullet410.label.text = "4";
bullet410.label.fill = am4core.color("#ffffff");
bullet410.locationY = 0.5;
var series510 = chart10.series.push(new am4charts.ColumnSeries());
series510.columns.template.width = am4core.percent(80);
series510.columns.template.tooltipText =
"{name}: {valueY.totalPercent.formatNumber('#.00')}%";
series510.name = "5";
series510.dataFields.categoryX = "category";
series510.dataFields.valueY = "value5";
series510.dataFields.valueYShow = "totalPercent";
series510.dataItems.template.locations.categoryX = 0.5;
series510.stacked = true;
series510.tooltip.pointerOrientation = "vertical";
var bullet510 = series510.bullets.push(new am4charts.LabelBullet());
bullet510.interactionsEnabled = false;
bullet510.label.text = "5";
bullet510.label.fill = am4core.color("#ffffff");
bullet510.locationY = 0.5;
var series610 = chart10.series.push(new am4charts.ColumnSeries());
series610.columns.template.width = am4core.percent(80);
series610.columns.template.tooltipText =
"{name}: {valueY.totalPercent.formatNumber('#.00')}%";
series610.name = "6";
series610.dataFields.categoryX = "category";
series610.dataFields.valueY = "value6";
series610.dataFields.valueYShow = "totalPercent";
series610.dataItems.template.locations.categoryX = 0.5;
series610.stacked = true;
series610.tooltip.pointerOrientation = "vertical";
var bullet610 = series610.bullets.push(new am4charts.LabelBullet());
bullet610.interactionsEnabled = false;
bullet610.label.text = "6";
bullet610.label.fill = am4core.color("#ffffff");
bullet610.locationY = 0.5;
var series710 = chart10.series.push(new am4charts.ColumnSeries());
series710.columns.template.width = am4core.percent(80);
series710.columns.template.tooltipText =
"{name}: {valueY.totalPercent.formatNumber('#.00')}%";
series710.name = "7";
series710.dataFields.categoryX = "category";
series710.dataFields.valueY = "value7";
series710.dataFields.valueYShow = "totalPercent";
series710.dataItems.template.locations.categoryX = 0.5;
series710.stacked = true;
series710.tooltip.pointerOrientation = "vertical";
var bullet710 = series710.bullets.push(new am4charts.LabelBullet());
bullet710.interactionsEnabled = false;
bullet710.label.text = "7";
bullet710.label.fill = am4core.color("#ffffff");
bullet710.locationY = 0.5;
categoryAxis10.renderer.labels.template.rotation = 320;
Chart 2
var chart89 = am4core.create("chartdiv89", am4charts.XYChart);
chart89.hiddenState.properties.opacity = 0; // this creates initial fade-in
chart89.data = [
{
category89: "Innovante",
value189: 4,
value289: 9,
value389: 34,
value489: 52,
value589: 33
},
{
category89: "Moderne",
value189: 4,
value289: 15,
value389: 44,
value489: 44,
value589: 25
},
{
category89: "Proche de ses clients",
value189: 10,
value289: 6,
value389: 34,
value489: 41,
value589: 41
},
{
category89: "Fermée/exclusive",
value189: 3,
value289: 8,
value389: 32,
value489: 33,
value589: 56
},
{
category89: "Attrayante professionnellement",
value289: 5,
value389: 15,
value489: 44,
value589: 68
}]
chart89.padding(30, 30, 10, 30);
chart89.colors.list = [
am4core.color("#2E9AFE"),
am4core.color("#0080FF"),
am4core.color("#2E64FE"),
am4core.color("#0431B4"),
am4core.color("#0B2161"),
];
var categoryAxis89 = chart89.xAxes.push(new am4charts.CategoryAxis());
categoryAxis89.dataFields.category = "category89";
categoryAxis89.renderer.grid.template.location = 0;
var valueAxis89 = chart89.yAxes.push(new am4charts.ValueAxis());
valueAxis89.min = 0;
valueAxis89.max = 100;
valueAxis89.strictMinMax = true;
valueAxis89.calculateTotals = true;
valueAxis89.renderer.minWidth = 40;
var series189 = chart89.series.push(new am4charts.ColumnSeries());
series189.columns.template.width = am4core.percent(80);
series189.columns.template.tooltipText =
"{name}: {valueY.totalPercent.formatNumber('#.00')}%";
series189.name = "1";
series189.dataFields.categoryX = "category89";
series189.dataFields.valueY = "value189";
series189.dataFields.valueYShow = "totalPercent";
series189.dataItems.template.locations.categoryX = 0.5;
series189.stacked = true;
series189.tooltip.pointerOrientation = "vertical";
var bullet189 = series189.bullets.push(new am4charts.LabelBullet());
bullet189.interactionsEnabled = false;
bullet189.label.text = "1";
bullet189.label.fill = am4core.color("#ffffff");
bullet189.locationY = 0.5;
var series289 = chart89.series.push(new am4charts.ColumnSeries());
series289.columns.template.width = am4core.percent(80);
series289.columns.template.tooltipText =
"{name}: {valueY.totalPercent.formatNumber('#.00')}%";
series289.name = "2";
series289.dataFields.categoryX = "category89";
series289.dataFields.valueY = "value289";
series289.dataFields.valueYShow = "totalPercent";
series289.dataItems.template.locations.categoryX = 0.5;
series289.stacked = true;
series289.tooltip.pointerOrientation = "vertical";
var bullet289 = series289.bullets.push(new am4charts.LabelBullet());
bullet289.interactionsEnabled = false;
bullet289.label.text = "2";
bullet289.label.fill = am4core.color("#ffffff");
bullet289.locationY = 0.5;
var series389 = chart89.series.push(new am4charts.ColumnSeries());
series389.columns.template.width = am4core.percent(80);
series389.columns.template.tooltipText =
"{name}: {valueY.totalPercent.formatNumber('#.00')}%";
series389.name = "3";
series389.dataFields.categoryX = "category89";
series389.dataFields.valueY = "value389";
series389.dataFields.valueYShow = "totalPercent";
series389.dataItems.template.locations.categoryX = 0.5;
series389.stacked = true;
series389.tooltip.pointerOrientation = "vertical";
var bullet389 = series389.bullets.push(new am4charts.LabelBullet());
bullet389.interactionsEnabled = false;
bullet389.label.text = "3";
bullet389.locationY = 0.5;
bullet389.label.fill = am4core.color("#ffffff");
var series489 = chart89.series.push(new am4charts.ColumnSeries());
series489.columns.template.width = am4core.percent(80);
series489.columns.template.tooltipText =
"{name}: {valueY.totalPercent.formatNumber('#.00')}%";
series489.name = "4";
series489.dataFields.categoryX = "category89";
series489.dataFields.valueY = "value489";
series489.dataFields.valueYShow = "totalPercent";
series489.dataItems.template.locations.categoryX = 0.5;
series489.stacked = true;
series489.tooltip.pointerOrientation = "vertical";
var bullet489 = series489.bullets.push(new am4charts.LabelBullet());
bullet489.interactionsEnabled = false;
bullet489.label.text = "4";
bullet489.label.fill = am4core.color("#ffffff");
bullet489.locationY = 0.5;
var series589 = chart89.series.push(new am4charts.ColumnSeries());
series589.columns.template.width = am4core.percent(80);
series589.columns.template.tooltipText =
"{name}: {valueY.totalPercent.formatNumber('#.00')}%";
series589.name = "5";
series589.dataFields.categoryX = "category89";
series589.dataFields.valueY = "value589";
series589.dataFields.valueYShow = "totalPercent";
series589.dataItems.template.locations.categoryX = 0.5;
series589.stacked = true;
series589.tooltip.pointerOrientation = "vertical";
var bullet589 = series589.bullets.push(new am4charts.LabelBullet());
bullet589.interactionsEnabled = false;
bullet589.label.text = "5";
Also, an important note: I tried using only one at a time on the webpage and this still gave no different result. So probably not a duplicated variable I guess.

Problem solved. It was due to the particular design I copied/paste from somewhere else and gave to the divi textbox containing the charts.

Related

amCharts 4: External Data Source - JSON Output from Database

Still trying to get to grips with amCharts 4 using external data sources, and this is a follow on from my previous question... amCharts 4: External Data Source
I've created a horizontal stacked chart using static data, which works fine (code snippet below).
However, when using the external data source on the same chart, I don't get same result, as the JSON output is different.
This is because the external database table columns and rows are the opposite way around (from the static data) and unfortunately can't be changed at source.
I've gone through the amCharts documentation and demo charts, and tried all sorts to achieve the same chart as the static data version with no success.
e.g. Tried the inversed opposite rotate properties, as well as reconfiguring the chart series and axes.
Maybe, the parseended event can be used to re-map the external data, but to be honest I don't know how.
I've come to a dead-end, and not sure how, or what is the correct (or best practice) method of doing this?
The code (and data structure) for each chart is shown below.
Any help would be very much appreciated. Thanks in advance.
STATIC DATA CHART (Correct)
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);
// Add data
var chartdata = [{
"Name": "Question 1 Shows Here",
"Yes Please": 75,
"Maybe": 45,
"No Thanks": 19
}, {
"Name": "Question 2 Shows Here",
"Yes Please": 35,
"Maybe": 43,
"No Thanks": 26
}, {
"Name": "Question 3 Shows Here",
"Yes Please": 57,
"Maybe": 24,
"No Thanks": 8
}];
chart.data = chartdata;
// Create axes
var categoryAxis = chart.yAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "Name";
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.renderer.minGridDistance = 20;
var valueAxis = chart.xAxes.push(new am4charts.ValueAxis());
valueAxis.numberFormatter.numberFormat = "#";
valueAxis.min = 0;
valueAxis.transitionDuration = 200;
valueAxis.interpolationDuration = 200;
valueAxis.rangeChangeDuration = 200;
// Create series
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueX = "Yes Please";
series.dataFields.categoryY = "Name";
series.name = "Yes Please";
series.tooltipText = "{name}: [bold]{valueX}[/]";
series.stacked = true;
var series2 = chart.series.push(new am4charts.ColumnSeries());
series2.dataFields.valueX = "Maybe";
series2.dataFields.categoryY = "Name";
series2.name = "Maybe";
series2.tooltipText = "{name}: [bold]{valueX}[/]";
series2.stacked = true;
var series3 = chart.series.push(new am4charts.ColumnSeries());
series3.dataFields.valueX = "Don’t Know";
series3.dataFields.categoryY = "Name";
series3.name = "Don’t Know";
series3.tooltipText = "{name}: [bold]{valueX}[/]";
series3.stacked = true;
var series4 = chart.series.push(new am4charts.ColumnSeries());
series4.dataFields.valueX = "No Thanks";
series4.dataFields.categoryY = "Name";
series4.name = "No Thanks";
series4.tooltipText = "{name}: [bold]{valueX}[/]";
series4.stacked = true;
// Add cursor
chart.cursor = new am4charts.XYCursor();
chart.cursor.behavior = "zoomXY";
// Add legend
chart.legend = new am4charts.Legend();
chart.legend.position = "bottom";
<script src="//www.amcharts.com/lib/4/core.js"></script>
<script src="//www.amcharts.com/lib/4/charts.js"></script>
<div id="chartdiv" style="width: 90%; height: 300px";></div>
EXTERNAL DATA CHART (Incorrect)
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);
// Add data
var chartdata = [{
"Name": "Yes Please",
"Question 1 Shows Here": 75,
"Question 2 Shows Here": 45,
"Question 3 Shows Here": 19
}, {
"Name": "Maybe",
"Branding and Logos Score": 367,
"Question 1 Shows Here": 35,
"Question 2 Shows Here": 43,
"Question 3 Shows Here": 26
}, {
"Name": "Don’t Know",
"Question 1 Shows Here": 42,
"Question 2 Shows Here": 31,
"Question 3 Shows Here": 12
}, {
"Name": "No Thanks",
"Question 1 Shows Here": 17,
"Question 2 Shows Here": 27,
"Question 3 Shows Here": 15
}];
chart.data = chartdata;
// Create category axes
var categoryAxis = chart.yAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "Name";
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.renderer.minGridDistance = 20;
// Create value axes
var valueAxis = chart.xAxes.push(new am4charts.ValueAxis());
valueAxis.numberFormatter.numberFormat = "#";
valueAxis.min = 0;
valueAxis.transitionDuration = 200;
valueAxis.interpolationDuration = 200;
valueAxis.rangeChangeDuration = 200;
// Create series
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueX = "Question 1 Shows Here";
series.dataFields.categoryY = "Name";
series.name = "Question 1 Shows Here";
series.tooltipText = "{name}: [bold]{valueX}[/]";
series.stacked = true;
var series2 = chart.series.push(new am4charts.ColumnSeries());
series2.dataFields.valueX = "Question 2 Shows Here";
series2.dataFields.categoryY = "Name";
series2.name = "Question 2 Shows Here";
series2.tooltipText = "{name}: [bold]{valueX}[/]";
series2.stacked = true;
var series3 = chart.series.push(new am4charts.ColumnSeries());
series3.dataFields.valueX = "Question 3 Shows Here";
series3.dataFields.categoryY = "Name";
series3.name = "Question 3 Shows Here";
series3.tooltipText = "{name}: [bold]{valueX}[/]";
series3.stacked = true;
// Add cursor
chart.cursor = new am4charts.XYCursor();
chart.cursor.behavior = "zoomXY";
chart.legend = new am4charts.Legend();
chart.legend.position = "bottom";
<script src="//www.amcharts.com/lib/4/core.js"></script>
<script src="//www.amcharts.com/lib/4/charts.js"></script>
<div id="chartdiv" style="width: 90%; height: 300px";></div>
parseended is the way to go in this situation. You'll need to set up a lookup table for your questions and map them to objects containing the values mapped to each response, for example:
chart.dataSource.events.on("parseended", function(ev) {
var questionMap = {}; //lookup table to map questions to data elements
ev.target.data.forEach(function(item) {
Object.keys(item).forEach(function(key) {
if (key.indexOf('Name') == -1) { //act on non-response keys
if (!questionMap[key]) {
questionMap[key] = {"Name": key}; //create an object containing the name/question pair if it doesn't exist
}
questionMap[key][item.Name] = item[key]; // assign response+value to the object (e.g. "Yes, Please": 75)
}
});
});
//remap lookup table as array
ev.target.data = Object.keys(questionMap).map(function(question) {
return questionMap[question];
});
});
Demo below:
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);
chart.dataSource.url = dataURI(); //fake URL for demonstration purposes
chart.dataSource.events.on("parseended", function(ev) {
var questionMap = {}; //lookup table to map questions to data elements
ev.target.data.forEach(function(item) {
Object.keys(item).forEach(function(key) {
if (key.indexOf('Name') == -1) { //act on non-response keys
if (!questionMap[key]) {
questionMap[key] = {
"Name": key
}; //create an object containing the name/question pair if it doesn't exist
}
questionMap[key][item.Name] = item[key]; // assign response+value to the object (e.g. "Yes, Please": 75)
}
});
});
//remap lookup table as array
ev.target.data = Object.keys(questionMap).map(function(question) {
return questionMap[question];
});
});
// Create axes
var categoryAxis = chart.yAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "Name";
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.renderer.minGridDistance = 20;
var valueAxis = chart.xAxes.push(new am4charts.ValueAxis());
valueAxis.numberFormatter.numberFormat = "#";
valueAxis.min = 0;
valueAxis.transitionDuration = 200;
valueAxis.interpolationDuration = 200;
valueAxis.rangeChangeDuration = 200;
// Create series
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueX = "Yes Please";
series.dataFields.categoryY = "Name";
series.name = "Yes Please";
series.tooltipText = "{name}: [bold]{valueX}[/]";
series.stacked = true;
var series2 = chart.series.push(new am4charts.ColumnSeries());
series2.dataFields.valueX = "Maybe";
series2.dataFields.categoryY = "Name";
series2.name = "Maybe";
series2.tooltipText = "{name}: [bold]{valueX}[/]";
series2.stacked = true;
var series3 = chart.series.push(new am4charts.ColumnSeries());
series3.dataFields.valueX = "Don’t Know";
series3.dataFields.categoryY = "Name";
series3.name = "Don’t Know";
series3.tooltipText = "{name}: [bold]{valueX}[/]";
series3.stacked = true;
var series4 = chart.series.push(new am4charts.ColumnSeries());
series4.dataFields.valueX = "No Thanks";
series4.dataFields.categoryY = "Name";
series4.name = "No Thanks";
series4.tooltipText = "{name}: [bold]{valueX}[/]";
series4.stacked = true;
// Add cursor
chart.cursor = new am4charts.XYCursor();
chart.cursor.behavior = "zoomXY";
// Add legend
chart.legend = new am4charts.Legend();
chart.legend.position = "bottom";
function dataURI() {
return "data:application/json;base64,W3sKICAiTmFtZSI6ICJZZXMgUGxlYXNlIiwKICAiUXVlc3Rpb24gMSBTaG93cyBIZXJlIjogNzUsCiAgIlF1ZXN0aW9uIDIgU2hvd3MgSGVyZSI6IDQ1LAogICJRdWVzdGlvbiAzIFNob3dzIEhlcmUiOiAxOQp9LCB7CiAgIk5hbWUiOiAiTWF5YmUiLAogICJCcmFuZGluZyBhbmQgTG9nb3MgU2NvcmUiOiAzNjcsCiAgIlF1ZXN0aW9uIDEgU2hvd3MgSGVyZSI6IDM1LAogICJRdWVzdGlvbiAyIFNob3dzIEhlcmUiOiA0MywKICAiUXVlc3Rpb24gMyBTaG93cyBIZXJlIjogMjYKfSwgewogICJOYW1lIjogIkRvbuKAmXQgS25vdyIsCiAgIlF1ZXN0aW9uIDEgU2hvd3MgSGVyZSI6IDQyLAogICJRdWVzdGlvbiAyIFNob3dzIEhlcmUiOiAzMSwKICAiUXVlc3Rpb24gMyBTaG93cyBIZXJlIjogMTIKfSwgewogICJOYW1lIjogIk5vIFRoYW5rcyIsCiAgIlF1ZXN0aW9uIDEgU2hvd3MgSGVyZSI6IDE3LAogICJRdWVzdGlvbiAyIFNob3dzIEhlcmUiOiAyNywKICAiUXVlc3Rpb24gMyBTaG93cyBIZXJlIjogMTUKfV0=";
}
<script src="//www.amcharts.com/lib/4/core.js"></script>
<script src="//www.amcharts.com/lib/4/charts.js"></script>
<div id="chartdiv" style="width: 90%; height: 300px" ;></div>

Remove vertical label axis of Multiple-Value-Axes amchart

I am okay all the line types under graph but I don't need their vertical represents
morever I have only one axis and yaxis values in my chart but multiple lines.
How can I customize this amchart sample or find any suitable chart for my need?
Practically every component in the chart has a disabled property that you can use to hide or reveal. To get rid of the line and labels, simply set the disabled property to true to remove them, similar to how the grid was disabled:
valueAxis.renderer.line.disabled = true; //disables axis line
valueAxis.renderer.labels.template.disabled = true; //disables labels
valueAxis.renderer.grid.template.disabled = true; //disables grid
Demo:
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);
// Increase contrast by taking evey second color
chart.colors.step = 2;
// Add data
chart.data = generateChartData();
// Create axes
var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
// Create series
function createAxisAndSeries(field, name, bullet) {
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
var series = chart.series.push(new am4charts.LineSeries());
series.dataFields.valueY = field;
series.dataFields.dateX = "date";
series.strokeWidth = 2;
series.yAxis = valueAxis;
series.name = name;
series.tooltipText = "{name}: [bold]{valueY}[/]";
series.tensionX = 0.8;
var interfaceColors = new am4core.InterfaceColorSet();
switch(bullet) {
case "triangle":
var bullet = series.bullets.push(new am4charts.Bullet());
bullet.width = 12;
bullet.height = 12;
bullet.horizontalCenter = "middle";
bullet.verticalCenter = "middle";
var triangle = bullet.createChild(am4core.Triangle);
triangle.stroke = interfaceColors.getFor("background");
triangle.strokeWidth = 2;
triangle.direction = "top";
triangle.width = 12;
triangle.height = 12;
break;
case "rectangle":
var bullet = series.bullets.push(new am4charts.Bullet());
bullet.width = 10;
bullet.height = 10;
bullet.horizontalCenter = "middle";
bullet.verticalCenter = "middle";
var rectangle = bullet.createChild(am4core.Rectangle);
rectangle.stroke = interfaceColors.getFor("background");
rectangle.strokeWidth = 2;
rectangle.width = 10;
rectangle.height = 10;
break;
default:
var bullet = series.bullets.push(new am4charts.CircleBullet());
bullet.circle.stroke = interfaceColors.getFor("background");
bullet.circle.strokeWidth = 2;
break;
}
valueAxis.renderer.line.disabled = true;
valueAxis.renderer.labels.template.disabled = true;
valueAxis.renderer.grid.template.disabled = true;
}
createAxisAndSeries("visits", "Visits", "circle");
createAxisAndSeries("views", "Views", "triangle");
createAxisAndSeries("hits", "Hits", "rectangle");
// Add legend
chart.legend = new am4charts.Legend();
// Add cursor
chart.cursor = new am4charts.XYCursor();
// generate some random data, quite different range
function generateChartData() {
var chartData = [];
var firstDate = new Date();
firstDate.setDate(firstDate.getDate() - 100);
firstDate.setHours(0, 0, 0, 0);
var visits = 1600;
var hits = 2900;
var views = 8700;
for (var i = 0; i < 15; i++) {
// we create date objects here. In your data, you can have date strings
// and then set format of your dates using chart.dataDateFormat property,
// however when possible, use date objects, as this will speed up chart rendering.
var newDate = new Date(firstDate);
newDate.setDate(newDate.getDate() + i);
visits += Math.round((Math.random()<0.5?1:-1)*Math.random()*10);
hits += Math.round((Math.random()<0.5?1:-1)*Math.random()*10);
views += Math.round((Math.random()<0.5?1:-1)*Math.random()*10);
chartData.push({
date: newDate,
visits: visits,
hits: hits,
views: views
});
}
return chartData;
}
#chartdiv {
width: 100%;
height: 500px;
}
<script src="https://www.amcharts.com/lib/4/core.js"></script>
<script src="https://www.amcharts.com/lib/4/charts.js"></script>
<div id="chartdiv"></div>
multiple-value-axes remove 3rd axis from chart.
Only two axis will show.

How can I make AMchart 4 horizontally scrollable without showing scrollbars

I am working on mobile screen only application and using AMCharts 4 in Angular 5. I have tried many different tricks and solutions to make the the line chart horizontally scrollable while displaying only a portion of the data given at any one time without having to display the scrollbar to no avail.
Below is my code to generate the chart:
this.data = [{
id: 156
tran_amount: "125.0"
value_date: "2019-02-05T12:00:46.173"
}, {
tran_amount: "12345.0"
value_date: "2019-01-05T12:00:46.173"
}];
let chart = am4core.create("amchart-container", am4charts.XYChart);
chart.data = [];
let categoryAxis = chart.xAxes.push(new am4charts.DateAxis());
categoryAxis.dataFields.date = "value_date";
let valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.zoom({start: 0.8, end: 1, priority: 'end'});
valueAxis.renderer.labels.template.disabled = true;
// valueAxis.title.text = "Account Balance";
// valueAxis.renderer.labels.template.adapter.add("text", function(text, target) {
// return "" ;
// });
let lineSeries = chart.series.push(new am4charts.LineSeries());
lineSeries.dataFields.valueY = "tran_amount";
lineSeries.dataFields.dateX = "value_date";
chart.cursor = new am4charts.XYCursor();
// chart.cursor.element.addStyle({})
chart.cursor.behavior = 'panX';
// chart.cursor.disabled = true;
// chart.cursor.marginLeft = 0;
chart.scrollbarX = new am4core.Scrollbar();
chart.scrollbarX.height = new am4core.Percent(0);
chart.scrollbarX.width = new am4core.Percent(10);
// chart.scrollbarX.disabled = true;
chart.zoomOutButton.disabled = true;
chart.swipeable = true;
chart.events.on('ready', () => {
// setTimeout(() => valueAxis.zoom({start: 0, end: 0.2, priority: 'start'}), 300);
chart.maxZoomFactor = 32;
chart.zoomToIndexes(this.data.length - 1 < 0 ? 0 : this.data.length - 1, this.data.length);
console.log('ready');
})'
this.chart.data = this.data;
The code has a lot of problems. Here is a cleaned up, working example where the chart will scroll if you do that with touch:
let chart = am4core.create("chartdiv", am4charts.XYChart);
chart.data = [{
tran_amount: 125.0,
value_date: new Date("2019-01-05T12:00:00.000")
}, {
tran_amount: 12345.0,
value_date: new Date("2019-02-05T12:00:00.000")
}, {
tran_amount: 12345.0,
value_date: new Date("2019-03-05T12:00:00.000")
}];
let categoryAxis = chart.xAxes.push(new am4charts.DateAxis());
categoryAxis.start = 0.7;
categoryAxis.keepSelection = true;
let valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
let lineSeries = chart.series.push(new am4charts.LineSeries());
lineSeries.dataFields.valueY = "tran_amount";
lineSeries.dataFields.dateX = "value_date";
chart.cursor = new am4charts.XYCursor();
chart.cursor.behavior = 'panX';
chart.scrollbarX = new am4core.Scrollbar();
chart.zoomOutButton.disabled = true;
chart.swipeable = true;

waving flag waving flag

<script type="text/javascript">
canvas.onmouseover = function onMouseover(e) {
waveFlag( flag, 20, 10, 150, 200, -0.1 );
}
canvas.onmouseout = function onMouseover(e) {
}
</script>
Above code is when the mouse move to the flag the flag will waving, how can i stop waving the flag when mouse out???
Just stop the setInterval from firing and the function will stop
<script type="text/javascript">
var timer = null;
function waveFlag( canvas, wavelength, amplitude, period, shading, squeeze ) {
if (!squeeze) squeeze = 0;
if (!shading) shading = 100;
if (!period) period = 200;
if (!amplitude) amplitude = 10;
if (!wavelength) wavelength = canvas.width/10;
var fps = 30;
var ctx = canvas.getContext('2d');
var w = canvas.width, h = canvas.height;
var od = ctx.getImageData(0,0,w,h).data;
// var ct = 0, st=new Date;
return setInterval(function(){
var id = ctx.getImageData(0,0,w,h);
var d = id.data;
var now = (new Date)/period;
for (var y=0;y<h;++y){
var lastO=0,shade=0;
var sq = (y-h/2)*squeeze;
for (var x=0;x<w;++x){
var px = (y*w + x)*4;
var pct = x/w;
var o = Math.sin(x/wavelength-now)*amplitude*pct;
var y2 = y + (o+sq*pct)<<0;
var opx = (y2*w + x)*4;
shade = (o-lastO)*shading;
d[px ] = od[opx ]+shade;
d[px+1] = od[opx+1]+shade;
d[px+2] = od[opx+2]+shade;
d[px+3] = od[opx+3];
lastO = o;
}
}
ctx.putImageData(id,0,0);
// if ((++ct)%100 == 0) console.log( 1000 * ct / (new Date - st));
},1000/fps);
}
var canvas = document.getElementById("flag");
canvas.onmouseover = function onMouseover(e) {
timer = waveFlag( flag, 20, 10, 150, 200, -0.1 );
}
canvas.onmouseout = function onMouseover(e) {
window.clearInterval(timer);
timer = null;
}
</script>

ThreeJS test works fine in Chrome, but nothing shows in IE10

I have this little test script which I'll try to include below. It works fine in Chrome but not in IE10. IE10 gives me a nice white screen. I tried putting in the meta-equiv thing to help IE10 get the hint, but that did not change anything (in either browser). Please help.
<!-- language: lang-js -->
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<style>
body {
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<div id="container"></div>
<script src="three.min.js"></script>
<script defer="defer">
// http://www.aerotwist.com/tutorials/getting-started-with-three-js/
var cubes = [];
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// camera
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 5000);
camera.position.z = 800;
// scene
var scene = new THREE.Scene();
// material
var phongMaterial = new THREE.MeshPhongMaterial({ambient: 0x555555,
color: 0x555555,
specular: 0xffffff,
shininess: 50,
side: THREE.FrontSide,
shading: THREE.SmoothShading});
var phongBack = new THREE.MeshPhongMaterial({ambient: 0x555555,
color: 0x995555,
specular: 0xffffff,
shininess: 50,
side: THREE.BackSide,
shading: THREE.SmoothShading});
var materials = [phongMaterial, phongBack];
// cube
//var cube = new THREE.Mesh(new THREE.CubeGeometry(200, 200, 200), material);
var geom = new THREE.Geometry();
var a = 100;
var b = 100;
var c = 300;
var geom = new THREE.Geometry();
var halfPi = (Math.PI / 2.0);
var u = -halfPi;
var uInc = Math.PI / 200.0;
var v = - Math.PI;
var vInc = uInc * 2.0;
var vertexNdx = 0;
var vs = [];
var on = true;
while (u < halfPi) {
var oneLine = [];
vs.push(oneLine);
while (v < Math.PI) {
var x = a * Math.cos(u) * Math.cos(v);
var y = b * Math.cos(u) * Math.sin(v);
var z = c * Math.sin(v) * Math.sin(u);
x += Math.random();
y += Math.random();
z += Math.random();
var v1 = new THREE.Vector3(x, y, z);
geom.vertices.push(v1);
oneLine.push(vertexNdx++);
if (on)
{
if (vs.length > 1 && oneLine.length > 1)
{
var uNdx = vs.length - 1;
var vNdx = oneLine.length - 1;
geom.faces.push(new THREE.Face3(vs[uNdx - 1][vNdx - 1],
vs[uNdx - 1][vNdx],
vs[uNdx][vNdx - 1]));
geom.faces.push(new THREE.Face3(vs[uNdx][vNdx - 1],
vs[uNdx - 1][vNdx],
vs[uNdx][vNdx]));
}
//on = false;
}
else
{
on = true;
}
v += vInc;
}
v = -Math.PI;
u += uInc;
}
var oneLine = vs[0];
var uNdx = vs.length - 1;
for (var vNdx = 1; vNdx < oneLine.length; vNdx++)
{
geom.faces.push(new THREE.Face3(vs[0][vNdx - 1],
vs[0][vNdx],
vs[uNdx][vNdx - 1]));
geom.faces.push(new THREE.Face3(vs[uNdx][vNdx - 1],
vs[0][vNdx],
vs[uNdx][vNdx]));
}
geom.computeFaceNormals();
var cube = new THREE.SceneUtils.createMultiMaterialObject(geom, materials);
cube.overdraw = true;
cube.rotation.x = Math.PI * 0.1;
scene.add(cube);
cubes.push(cube);
var geom = new THREE.Geometry();
var a = 100;
var b = 100;
var c = 300;
var geom = new THREE.Geometry();
var halfPi = (Math.PI / 2.0);
var u = -halfPi;
var uInc = Math.PI / 200.0;
var v = - Math.PI;
var vInc = uInc * 2.0;
var vertexNdx = 0;
var vs = [];
var on = true;
while (u < halfPi) {
var oneLine = [];
vs.push(oneLine);
var xRand = Math.random();
while (v < Math.PI) {
var x = a * Math.cos(u) * Math.cos(v);
var y = b * Math.cos(u) * Math.sin(v);
var z = c * Math.sin(v) * Math.sin(u);
x += xRand;
y += Math.random();
z += Math.random();
var v1 = new THREE.Vector3(x, y, z);
geom.vertices.push(v1);
oneLine.push(vertexNdx++);
if (on)
{
if (vs.length > 1 && oneLine.length > 1)
{
var uNdx = vs.length - 1;
var vNdx = oneLine.length - 1;
geom.faces.push(new THREE.Face3(vs[uNdx - 1][vNdx - 1],
vs[uNdx - 1][vNdx],
vs[uNdx][vNdx - 1]));
geom.faces.push(new THREE.Face3(vs[uNdx][vNdx - 1],
vs[uNdx - 1][vNdx],
vs[uNdx][vNdx]));
}
//on = false;
}
else
{
on = true;
}
v += vInc;
}
v = -Math.PI;
u += uInc;
}
var oneLine = vs[0];
var uNdx = vs.length - 1;
for (var vNdx = 1; vNdx < oneLine.length; vNdx++)
{
geom.faces.push(new THREE.Face3(vs[0][vNdx - 1],
vs[0][vNdx],
vs[uNdx][vNdx - 1]));
geom.faces.push(new THREE.Face3(vs[uNdx][vNdx - 1],
vs[0][vNdx],
vs[uNdx][vNdx]));
}
geom.applyMatrix(new THREE.Matrix4().translate(new THREE.Vector3(200, 0, 0)));
geom.computeFaceNormals();
var cube = new THREE.SceneUtils.createMultiMaterialObject(geom, materials);
cube.overdraw = true;
cube.rotation.x = Math.PI * 0.1;
scene.add(cube);
cubes.push(cube);
var geom = new THREE.Geometry();
var a = 100;
var b = 100;
var c = 300;
var geom = new THREE.Geometry();
var halfPi = (Math.PI / 2.0);
var u = -halfPi;
var uInc = Math.PI / 200.0;
var v = - Math.PI;
var vInc = uInc * 2.0;
var vertexNdx = 0;
var vs = [];
var on = true;
while (u < halfPi) {
var oneLine = [];
vs.push(oneLine);
var yRand = Math.random();
while (v < Math.PI) {
var x = a * Math.cos(u) * Math.cos(v);
var y = b * Math.cos(u) * Math.sin(v);
var z = c * Math.sin(v) * Math.sin(u);
x += Math.random();
y += yRand;
z += Math.random();
var v1 = new THREE.Vector3(x, y, z);
geom.vertices.push(v1);
oneLine.push(vertexNdx++);
if (on)
{
if (vs.length > 1 && oneLine.length > 1)
{
var uNdx = vs.length - 1;
var vNdx = oneLine.length - 1;
geom.faces.push(new THREE.Face3(vs[uNdx - 1][vNdx - 1],
vs[uNdx - 1][vNdx],
vs[uNdx][vNdx - 1]));
geom.faces.push(new THREE.Face3(vs[uNdx][vNdx - 1],
vs[uNdx - 1][vNdx],
vs[uNdx][vNdx]));
}
//on = false;
}
else
{
on = true;
}
v += vInc;
}
v = -Math.PI;
u += uInc;
}
var oneLine = vs[0];
var uNdx = vs.length - 1;
for (var vNdx = 1; vNdx < oneLine.length; vNdx++)
{
geom.faces.push(new THREE.Face3(vs[0][vNdx - 1],
vs[0][vNdx],
vs[uNdx][vNdx - 1]));
geom.faces.push(new THREE.Face3(vs[uNdx][vNdx - 1],
vs[0][vNdx],
vs[uNdx][vNdx]));
}
geom.applyMatrix(new THREE.Matrix4().translate(new THREE.Vector3(-200, 0, 0)));
geom.computeFaceNormals();
var cube = new THREE.SceneUtils.createMultiMaterialObject(geom, materials);
cube.overdraw = true;
cube.rotation.x = Math.PI * 0.1;
scene.add(cube);
cubes.push(cube);
// add subtle ambient lighting
var ambientLight = new THREE.AmbientLight(0xdddddd);
scene.add(ambientLight);
// directional lighting
var directionalLight = new THREE.DirectionalLight(0xffffff);
directionalLight.position.set(1, 1, 1).normalize();
scene.add(directionalLight);
var screenW = window.innerWidth;
var screenH = window.innerHeight;
var spdx = 0, spdy = 0, mouseX = 0, mouseY = 0, mouseDown = false;
document.addEventListener('mousemove', function(event) {
mouseX = event.clientX;
mouseY = event.clientY;
}, false);
document.body.addEventListener('mousedown', function(event) {
mouseDown = true;
}, false);
document.body.addEventListener('mouseup', function(event) {
mouseDown = false;
}, false);
function animate() {
spdy = (screenH / 2 - mouseY) / 40;
spdx = (screenW / 2 - mouseX) / 40;
if (mouseDown) {
for (var loop = 0; loop < cubes.length; loop++) {
var cube = cubes[loop];
cube.rotation.x = spdy;
cube.rotation.y = spdx;
}
}
renderer.render(scene, camera);
requestAnimationFrame(function(){
animate();
});
};
// start animation
animate();
</script>
</body>
</html>
And feel free to steal my little play test code if you like it. If you make something that looks cool, let me see it! I'm looking for organic-looking shapes that are made mathematically.
IE10 does not support WebGL. I think your code will work if you just switch from WebGLRenderer to CanvasRenderer, but the lighting won't be as accurate.

Resources