2010-11-30 50 views

回答

3

我可以看到工作的唯一方法是让背景图像在您要显示的每个百分比带上都带有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 
+0

这样的表达方式这是可能的某种其他方式吗? – buda 2010-12-01 15:09:32