This section describes how to change the background of a chart.
Background Fill Copy Link
To change the colour of the chart background, simply provide a colour string value for the background.fill property.
{
background: {
fill: 'rgb(63, 127, 255)',
},
}import { Component } from "@angular/core";
import { AgCharts } from "ag-charts-angular";
import {
AgPolarChartOptions,
LegendModule,
ModuleRegistry,
PieSeriesModule,
} from "ag-charts-community";
import { getData } from "./data";
import { random } from "./seededRandom";
import clone from "clone";
function randomChannel() {
return Math.floor(random() * 256);
}
ModuleRegistry.registerModules([LegendModule, PieSeriesModule]);
@Component({
selector: "my-app",
standalone: true,
imports: [AgCharts],
template: `<div class="example-controls">
<div class="controls-row">
<button (click)="randomColor()">🍭 Random color</button>
</div>
</div>
<ag-charts
[options]="options"
></ag-charts>
`,
})
export class AppComponent {
public options;
constructor() {
this.options = {
data: getData(),
series: [
{
type: "pie",
angleKey: "value",
},
],
background: {
fill: "aliceblue",
},
};
}
randomColor = () => {
const options = clone(this.options);
const color = `rgb(${randomChannel()}, ${randomChannel()}, ${randomChannel()})`;
options.background = {
fill: color,
};
this.options = options;
};
}
To set the background of chart elements see Fills & Borders.
API Reference Copy Link
Properties available on the AgChartBackground interface.
- visible
boolean - Whether the background should be visible.
- fill
CssColor - Colour of the chart background.
Properties available on the AgChartBackground interface.
- visible
boolean - Whether the background should be visible.
- fill
CssColor - Colour of the chart background.