|
| 1 | +--- |
| 2 | +title: How to Reduce the Excessive Whitespace Around the Chart |
| 3 | +description: Learn how to adjust the padding and legend position of a Chart and remove unnecessary white space. |
| 4 | +type: how-to |
| 5 | +page_title: How to Reduce the Excessive Whitespace Around the Chart |
| 6 | +slug: chart-kb-remove-excess-whitespace |
| 7 | +tags: chart, padding |
| 8 | +res_type: kb |
| 9 | +ticketid: 1663179, 1559824 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +<table> |
| 15 | + <tbody> |
| 16 | + <tr> |
| 17 | + <td>Product</td> |
| 18 | + <td>Chart for Blazor</td> |
| 19 | + </tr> |
| 20 | + </tbody> |
| 21 | +</table> |
| 22 | + |
| 23 | +## Description |
| 24 | + |
| 25 | +This KB article answers the following questions: |
| 26 | + |
| 27 | +- How to adjust the padding of a Chart in Blazor? |
| 28 | +- How to reduce white space around the Chart that is within a Telerik Card? |
| 29 | +- How to make the Chart more compact? |
| 30 | + |
| 31 | +## Solution |
| 32 | + |
| 33 | +To reduce the whitespace around a Chart, use the `Padding` parameter of the ChartSeries. |
| 34 | + |
| 35 | +````CSHTML |
| 36 | +<TelerikCard Width="330px"> |
| 37 | + <CardHeader> |
| 38 | + <CardTitle>Simple Pie Chart</CardTitle> |
| 39 | + </CardHeader> |
| 40 | + <CardBody> |
| 41 | + <TelerikChart Height="300px"> |
| 42 | + <ChartSeriesItems> |
| 43 | + <ChartSeries Type="ChartSeriesType.Pie" |
| 44 | + Data="@pieData" |
| 45 | + Field="@nameof(MyPieChartModel.SegmentValue)" |
| 46 | + CategoryField="@nameof(MyPieChartModel.SegmentName)" |
| 47 | + Padding="5"> |
| 48 | + </ChartSeries> |
| 49 | + </ChartSeriesItems> |
| 50 | + <ChartLegend Position="ChartLegendPosition.Bottom" Width="300"> |
| 51 | + </ChartLegend> |
| 52 | + </TelerikChart> |
| 53 | + </CardBody> |
| 54 | +</TelerikCard> |
| 55 | +
|
| 56 | +@code { |
| 57 | + private List<MyPieChartModel> pieData = new List<MyPieChartModel> |
| 58 | + { |
| 59 | + new MyPieChartModel |
| 60 | + { |
| 61 | + SegmentName = "Product 1", |
| 62 | + SegmentValue = 2 |
| 63 | + }, |
| 64 | + new MyPieChartModel |
| 65 | + { |
| 66 | + SegmentName = "Product 2", |
| 67 | + SegmentValue = 3 |
| 68 | + }, |
| 69 | + new MyPieChartModel |
| 70 | + { |
| 71 | + SegmentName = "Product 3", |
| 72 | + SegmentValue = 4 |
| 73 | + } |
| 74 | + }; |
| 75 | +
|
| 76 | + public class MyPieChartModel |
| 77 | + { |
| 78 | + public string SegmentName { get; set; } |
| 79 | + public double SegmentValue { get; set; } |
| 80 | + } |
| 81 | +} |
| 82 | +```` |
| 83 | + |
| 84 | +## See Also |
| 85 | + |
| 86 | +- [ChartSeries API Documentation](https://docs.telerik.com/blazor-ui/api/telerik.blazor.components.chartseries) |
| 87 | +- [Chart for Blazor Overview]({%slug components/chart/overview%}) |
0 commit comments