Charts with Dynamic Height or Width based on Categories/Data (SQL 2008, RDL)
You may have been in this situation before - you designed a chart based on a particular dataset and everything looks great. However, later the data volume increases, or new categories dynamically show up in your data source, and there is not enough horizontal/vertical space in the chart to show all the data or categories. Unless, of course, you applied an approach to dynamically increase the height/width of the chart.
There are two new Chart RDL properties in the report designer / report builder property grid to simplify this task in Reporting Services 2008:
-
DynamicHeight: the height the chart should grow/shrink at runtime
-
DynamicWidth: the width the chart should grow/shrink at runtime
If the properties are not specified, then the design time sizes will be applied. Both properties can be set to any RDL expression that evaluates to a size string at runtime (e.g. ="3 in"). Btw, note the space in the size string between the numeric part and the size unit.
The attachment of this posting contains a small report that demonstrates this technique. The report is based on the Northwind sample database (database download link). The chart in the report dynamically increases its width based on the number of countries shown in the chart (determined by a report parameter value). To accomplish this, the DynamicWidth property of the chart is set to the following expression:
=(1 + Parameters!TopNCountries.Value / 2) & " in"
In this example, if you choose to show only the top 5 countries, the chart will have a width of 1+5/2 = 3.5 inches. If you select the top 10 countries, the chart has a width of 1+10/2 = 6 inches and therefore more horizontal room to draw additional categories.
注: RDLC, RDL 中如果有错误,编译会提示有错误,但不会指出哪个项目,哪个文件有错误(VS2008)。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY