简体   繁体   English

如何在AmCharts4类别轴上显示所有标签或减少标签填充?

[英]How to show all labels or reduce label padding on AmCharts4 Category Axis?

I'm building a Pareto chart to show percent and count by category. 我正在建立一个帕累托图,以显示百分比和按类别计数。 It is important to be able to see all category labels on the chart. 能够查看图表上的所有类别标签很重要。 There is currently plenty of space to show more category labels, but the axis isn't showing them. 当前有足够的空间显示更多类别标签,但轴未显示它们。

Is there a way to tell the axis to show all labels, or to reduce the padding/margin on axis labels so that more can be shown? 有没有一种方法可以告诉轴显示所有标签,或者减少轴标签上的填充/边距,以便可以显示更多标签?

I am using Typescript in an Angular app. 我在Angular应用中使用Typescript。

Current Axis Creation Code: 当前轴创建代码:

let categoryAxis = chart.yAxes.push(new am4charts.CategoryAxis());
categoryAxis .title.text = 'Category';
categoryAxis.dataFields.category = categoryField;
categoryAxis.renderer.fontSize = 12;

Image of issue: 问题图片:

发行图片

You need to set minGridDistance to a small enough value to make the chart display more/all labels, eg 您需要将minGridDistance设置为足够小的值,以使图表显示更多/所有标签,例如

categoryAxis.renderer.minGridDistance = 20;

From the documentation 文档中

Actual behavior depends on available space. 实际行为取决于可用空间。 But it's all governed by a single axis renderer's property: minGridDistance . 但这都由单轴渲染器的属性minGridDistance

In human language it means this: "Whatever happens DO NOT place two grid lines closer than X pixels. I'm serious, man!". 在人类语言中,它的意思是:“无论发生什么情况,都不要将两条网格线放置得比X像素更近。我是认真的,伙计!”。

Default settings depend on orientation. 默认设置取决于方向。 For example horizontal axis renderers ( AxisRendererX ) has a default of 120. Vertical axis renderer ( AxisRendererY ): 40. 例如,水平轴渲染器( AxisRendererX )的默认值为120。垂直轴渲染器( AxisRendererY ):40。

Increasing these numbers will mean likely sparser grid lines and related labels. 这些数字的增加将意味着网格线和相关标签可能会稀疏。 Decreasing will probably result in denser grid/labels. 减少可能会导致网格/标签更密集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM