在Angular中更改条形图的图例可以通过以下步骤实现:
ngx-charts-bar-vertical
组件。<ngx-charts-bar-vertical
[view]="view"
[scheme]="colorScheme"
[results]="chartData"
[xAxis]="showXAxis"
[yAxis]="showYAxis"
[legend]="showLegend"
[legendPosition]="legendPosition"
[showXAxisLabel]="showXAxisLabel"
[showYAxisLabel]="showYAxisLabel"
[xAxisLabel]="xAxisLabel"
[yAxisLabel]="yAxisLabel">
</ngx-charts-bar-vertical>
import { Component } from '@angular/core';
@Component({
selector: 'app-bar-chart',
templateUrl: './bar-chart.component.html',
styleUrls: ['./bar-chart.component.css']
})
export class BarChartComponent {
view: any[] = [700, 400];
colorScheme = {
domain: ['#5AA454', '#A10A28', '#C7B42C', '#AAAAAA']
};
chartData = [
{
name: 'Series 1',
value: 100
},
{
name: 'Series 2',
value: 200
},
{
name: 'Series 3',
value: 150
},
{
name: 'Series 4',
value: 50
}
];
showXAxis = true;
showYAxis = true;
showLegend = true;
legendPosition = 'below';
showXAxisLabel = true;
showYAxisLabel = true;
xAxisLabel = 'X Axis';
yAxisLabel = 'Y Axis';
}
showLegend
属性来控制图例的显示与隐藏。legendPosition
属性来设置。可选的值有:'top'、'right'、'bottom'、'left'。colorScheme
属性来设置。你可以自定义颜色方案,或者使用ngx-charts提供的预定义颜色方案。chartData
属性中的数据,以更新条形图的显示。这样,你就可以在Angular中更改条形图的图例了。请注意,以上示例中使用的是ngx-charts库,你也可以根据自己的需求选择其他图表库。
领取专属 10元无门槛券
手把手带您无忧上云