Skip to content

Commit 8c1c96f

Browse files
docs(chart): size and resize
1 parent 1b7e483 commit 8c1c96f

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

components/chart/overview.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,62 @@ To use a Telerik chart for Blazor:
9090
}
9191
````
9292

93+
## Chart Size
94+
95+
To control the chart size, use its `Width` and `Height` properties. You can read more on how they work in the [Dimensions]({%slug common-features/dimensions%}) article.
96+
97+
You can also set the chart size in percentage values so it occupies its container. If the parent container size changes, you must call its `Resize()` method after the DOM has been redrawn and the new container dimensions are rendered.
98+
99+
>caption Change the 100% chart size dynamically
100+
101+
````CSHTML
102+
@using Telerik.Blazor
103+
@using Telerik.Blazor.Components.Chart
104+
@using Telerik.Blazor.Components.Button
105+
106+
<TelerikButton OnClick="@ResizeChart">Resize the container and redraw the chart</TelerikButton>
107+
108+
<div style="border: 1px solid red;width:@ContainerWidth; height: @ContainerHeight">
109+
110+
<TelerikChart Width="100%" Height="100%" ref="@theChart">
111+
112+
<TelerikChartSeriesItems>
113+
<TelerikChartSeries Type="ChartSeriesType.Column" Name="Product 1" Data="@someData">
114+
</TelerikChartSeries>
115+
</TelerikChartSeriesItems>
116+
<TelerikChartCategoryAxes>
117+
<TelerikChartCategoryAxis Categories="@xAxisItems"></TelerikChartCategoryAxis>
118+
</TelerikChartCategoryAxes>
119+
<TelerikChartTitle Text="Quarterly sales trend"></TelerikChartTitle>
120+
121+
</TelerikChart>
122+
123+
</div>
124+
125+
@functions {
126+
string ContainerWidth { get; set; } = "400px";
127+
string ContainerHeight { get; set; } = "300px";
128+
Telerik.Blazor.Components.Chart.TelerikChart theChart { get; set; }
129+
130+
async Task ResizeChart()
131+
{
132+
//resize the container
133+
ContainerHeight = "500px";
134+
ContainerWidth = "800px";
135+
136+
//give time to the framework and browser to resize the actual DOM so the chart can use the expected size
137+
await Task.Delay(20);
138+
139+
//redraw the chart
140+
theChart.Refresh();
141+
}
142+
143+
public List<object> someData = new List<object>() { 10, 2, 7, 5 };
144+
145+
public string[] xAxisItems = new string[] { "Q1", "Q2", "Q3", "Q4" };
146+
}
147+
````
148+
93149
## See Also
94150

95151
* [Data Binding]({%slug components/chart/databind%})

0 commit comments

Comments
 (0)