如何在报告服务表或矩阵中创建部分着色的单元格?例如:我的值为 45,我只想用红色填充 45% 的单元格,而其他 55% 的单元格保持白色?
最佳答案
我认为可行的唯一方法是为您要显示的每个百分比带设置一个充满 x% 红色的背景图像。 然后,您可以设置一个表达式,根据特定字段的值用正确的图像填充背景。
这不是最好的解决方案,因为您将需要 20 张图像才能获得 5% 的波段。
另一种选择是编写一个 webservice/asp.net 页面,该页面将根据查询字符串以正确的比例生成图像。然后就可以给aspx页面设置背景图片了。 This article是如何通过 asp.net 动态创建图像的示例
测试了以下代码,它可以很好地生成单元格图表。
protected void Page_Load(object sender, EventArgs e)
{
int percent = 0;
int height = 20;
if (Request.QueryString.AllKeys.Contains("percent"))
{
int.TryParse(Request.QueryString["percent"], out percent);
}
if (Request.QueryString.AllKeys.Contains("height"))
{
int.TryParse(Request.QueryString["height"], out height);
}
Bitmap respBitmap = new Bitmap(100, height, PixelFormat.Format32bppRgb);
Graphics graphics = Graphics.FromImage(respBitmap);
Brush brsh = new SolidBrush(Color.White);
graphics.FillRectangle(brsh, new Rectangle(0, 0, respBitmap.Width, respBitmap.Height));
brsh = new SolidBrush(Color.Red);
graphics.FillRectangle(brsh, new Rectangle(0, 0, respBitmap.Width * percent / 100, respBitmap.Height));
Response.ContentType = "image/jpeg";
Response.Charset = "";
respBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);
}
转到所需的文本框,将 BackGroundImage 源更改为外部并将值更改为表达式。 使用类似于
的表达式= "http://mysite/chartimage.aspx?percentage=" & Fields!MyField.Value
关于reporting-services - 报告服务部分彩色单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4317637/