Reputation: 1507
I have a bar chart and i was wondering if there is a way to make all the graphics have the same colour:
https://codepen.io/conormdowney/pen/xmVRjd
var chart = am4core.create("chartdiv", am4charts.XYChart);
chart.data = [{
"category": "Research",
"value1": 450,
"value2": 1200,
"value3": 960,
"value4": 710,
"value5": 900
}, {
"category": "Marketing",
"value1": 1200,
"value2": 450,
"value3": 850,
"value4": 1250,
"value5": 950
}, {
"category": "Distribution",
"value1": 1850,
"value2": 1700,
"value3": 450,
"value4": 870,
"value5": 600
}];
// Create axes
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "category";
categoryAxis.renderer.grid.template.location = 0;
//categoryAxis.renderer.minGridDistance = 30;
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
// Create series
function createSeries(field) {
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueY = field;
series.dataFields.categoryX = "category";
return series;
}
createSeries("value1");
createSeries("value2");
createSeries("value3");
createSeries("value4");
createSeries("value5");```
Upvotes: 1
Views: 211
Reputation: 41
As @xorsparks answer, but my bars were a variation of my one colour. I found that I had to set chart.colors.passOptions = {};
to stop that from happening.
Upvotes: 0
Reputation: 16012
There are two methods:
series.columns.template.fill = chart.colors.getIndex(0);
series.columns.template.stroke = chart.colors.getIndex(0);
reuse
to true on the chart's colors
object to have it only reuse colors from the list. Setting the list to a single color will essentially be the same as the lines from the first method:chart.colors.reuse = true;
chart.colors.list = [
am4core.color("#845EC2")
];
Upvotes: 1