Skip to content

Commit aa7d1c8

Browse files
Knowledge base article on dealing with crowded grid lines in the chart (#91)
* feat(kb): article on crowded grid lines in the chart initial commit * chore(kb): fixed typo in crowded grid lines chart article * chore(chart): minor improvements on kb for decluttering grid lines Co-authored-by: Marin Bratanov <[email protected]>
1 parent f9c0040 commit aa7d1c8

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
title: Prevent crowded grid lines in the Chart
3+
description: How to prevent crowded grid lines in the Chart
4+
type: how-to
5+
page_title: Prevent crowded grid lines in the Chart
6+
slug: chart-kb-crowded-grid-lines
7+
position:
8+
tags:
9+
res_type: kb
10+
---
11+
12+
## Environment
13+
<table>
14+
<tbody>
15+
<tr>
16+
<td>Product</td>
17+
<td>Chart for Blazor</td>
18+
</tr>
19+
</tbody>
20+
</table>
21+
22+
23+
## Description
24+
25+
I have a Chart that has to visualize a big volume of data. This makes the grid lines clustered and the Chart hard to read and follow.
26+
27+
## Solution
28+
29+
You can choose which grid lines to show (every `n`-th `Step`) and to `Skip` the first `m` through parameters on the respective grid line tag. Read more to see how to get to those tags and use the parameters.
30+
31+
The general approach to customize a Chart is to apply settings using nested tags. In the case of the grid lines the parent tag is
32+
33+
* for [categorical charts]({%slug components/chart/databind%}#series-types): x-axis `<ChartCategoryAxis>` and y-axis `<ChartValueAxis>`.
34+
* for [numerical charts]({%slug components/chart/databind%}#series-types): x-axis `<ChartXAxis>` and y-axis `<ChartYAxis>`.
35+
36+
You can control the `MajorGridLines` for both axes from their respective nested tags - `<ChartCategoryAxisMajorGridLines />` (the vertical grid lines) and `<ChartValueAxisMajorGridLines />` (the horizontal grid lines).
37+
38+
You can apply the following settings:
39+
* `Step` - skip the rendering of every `n-th` line.
40+
* `Visible` - toggle whether the grid lines are visible.
41+
* `Skip` - skip the rendering of the first `n` lines, where `n` is the `double` number passed to the parameter.
42+
* You can also control other visual settings of the lines like their `Color`, `Width` and `DashType`.
43+
44+
You can do the same for the `MinorGridLines` too.
45+
46+
For a [`Date Axis` Chart]({%slug components/chart/date-axis%}), you can set the `BaseUnit` parameter of the `<ChartCategoryAxis>` tag according to the data of your application to further control the granularity of the grid lines - this is what the number of categories and, thus, grid lines, depends on.
47+
48+
>caption Declutter the grid lines of a Categorical Chart
49+
50+
````CSHTML
51+
@* This example shows how to render every second grid line for the category axis and disable the lines for the value axis *@
52+
53+
<TelerikChart>
54+
<ChartSeriesItems>
55+
<ChartSeries Type="ChartSeriesType.Column" Name="Product 1" Data="@series1Data">
56+
</ChartSeries>
57+
<ChartSeries Type="ChartSeriesType.Column" Name="Product 2" Data="@series2Data">
58+
</ChartSeries>
59+
</ChartSeriesItems>
60+
61+
<ChartCategoryAxes>
62+
<ChartCategoryAxis Categories="@xAxisItems">
63+
<ChartCategoryAxisMajorGridLines Step="2" />
64+
</ChartCategoryAxis>
65+
</ChartCategoryAxes>
66+
67+
<ChartValueAxes>
68+
<ChartValueAxis>
69+
<ChartValueAxisMajorGridLines Visible="false" />
70+
</ChartValueAxis>
71+
</ChartValueAxes>
72+
73+
<ChartTitle Text="Quarterly revenue per product"></ChartTitle>
74+
75+
<ChartLegend Position="ChartLegendPosition.Right">
76+
</ChartLegend>
77+
</TelerikChart>
78+
79+
@code {
80+
public List<object> series1Data = new List<object>() { 10, 2, 5, 6, 8 };
81+
public List<object> series2Data = new List<object>() { 5, 8, 2, 7, 6 };
82+
public string[] xAxisItems = new string[5];
83+
84+
protected override void OnInitialized()
85+
{
86+
for (int i = 0; i < 5; i++)
87+
{
88+
xAxisItems[i] = $"label {i + 1}";
89+
}
90+
}
91+
}
92+
93+
````
94+
95+
>caption The result from the code snippet above
96+
97+
![customize chart grid lines](images/chart-grid-lines-example.png)
98+
99+
100+
## Notes
101+
102+
You can also see the Knowledge base article regarding [overlapping labels]({%slug chart-kb-crowded-labels%}) to further improve the layout of the Chart.
Loading

0 commit comments

Comments
 (0)