I have a graph with columns for which I would like to color bars according to the value of a third variable (Correction). The color for “Yes” has to be #FF4B35 and for “No”: #1C7BFF.
I also need to show the legend on the top of my graph.
Here, is the graph I would like to have:
Here is my code:
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);
// Add data
chart.data = [
{
"Pays": "Croatie",
"Co?t par hab.": 4.32,
"Correction": "Oui"
},
{
"Pays": "Bulgarie",
"Co?t par hab.": 1.728,
"Correction": "Oui"
},
{
"Pays": "Grèce",
"Co?t par hab.": 5.168,
"Correction": "No"
},
{
"Pays": "Roumanie",
"Co?t par hab.": 4.672,
"Correction": "Oui"
},
{
"Pays": "Lettonie",
"Co?t par hab.": 7.264,
"Correction": "No"
}];
// Create axis X
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "Pays";
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.renderer.minGridDistance = 1;
categoryAxis.renderer.labels.template.rotation = -45;
categoryAxis.renderer.labels.template.verticalCenter = "top";
categoryAxis.renderer.labels.template.horizontalCenter = "right";
categoryAxis.renderer.grid.template.disabled = true;
// Create axis Y
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.title.text = "Euros PPA par habitant";
// Create series for column
var series1_1 = chart.series.push(new am4charts.ColumnSeries());
series1_1.dataFields.valueY = "Co?t par hab.";
series1_1.dataFields.categoryX = "Pays";
series1_1.strokeWidth = 0;
series1_1.fillOpacity = 0.7;
Does anyone know how to do it?
question from:
https://stackoverflow.com/questions/66067218/color-column-graph-by-groups-in-amcharts 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…