如何增大Infragistics igx-doughnut-chart标签字体大小?(v16.1.29)
解决igniteui-angular v16.1.29中igx-doughnut-chart标签字体大小问题
方法一:CSS自定义样式覆盖
直接通过CSS选择器定位图表标签元素,强制设置字体大小,避免图表缩小时字体被自动缩小:
/* 全局环形图标签样式 */ igx-doughnut-chart .igx-ring-series-label { font-size: 14px !important; /* 按需调整尺寸 */ font-weight: 500; /* 可选,提升可读性 */ white-space: nowrap; /* 防止标签换行 */ }
若需仅针对特定图表生效,可给图表添加自定义类:
<igx-doughnut-chart class="custom-donut-chart" ...> <!-- 现有代码 --> </igx-doughnut-chart>
对应CSS:
.custom-donut-chart .igx-ring-series-label { font-size: 14px !important; }
方法二:使用自定义标签模板(推荐)
通过igx-label-template完全自定义标签内容与样式,不受图表默认缩放逻辑影响:
<igx-doughnut-chart *ngIf="chartMan && chartMan.length > 0; else noDataTemplate" #chartDonutMan height="80%" width="100%" allowSliceSelection="true" innerExtent="0.6"> <igx-ring-series [dataSource]="chartMan" valueMemberPath="percentage" labelMemberPath="name" legendLabelMemberPath="name" [legend]="true" startAngle="0" labelsPosition="OutsideEnd" labelExtent="30" radiusFactor="0.7" [brushes]="brushColorsMan" labelOuterColor="white" leaderLineStrokeThickness="2" othersCategoryThreshold="0" [labelFormat]="labelFormatMan"> <!-- 自定义标签模板 --> <ng-template igxLabelTemplate let-item="item"> <span style="font-size: 14px; color: white; font-weight: 500;"> {{ item.name }} </span> </ng-template> </igx-ring-series> </igx-doughnut-chart>
可根据需求调整模板内的font-size、颜色等属性,确保标签字体大小始终符合设置,不会随图表尺寸变化自动缩小。
内容的提问来源于stack exchange,提问作者fatin amirah
相关产品推荐
相关产品推荐

