开发者

Reporting services partially colored cell

How can开发者_高级运维 i create partialy colored cell in reporting services table or matrix? For example: I hava value of 45& i want to fill only 45% of cell with red color, and other 55% stay white?


The only way I can see that working is to have a background image that is x% full of red for each percentage band you want to show. Then you can set an expression to fill the background with the correct image depending on the value of a particular field.

Not quite the greatest solution as you are going to need 20 images just to get 5% bands.

The other option is to write a webservice/asp.net page that will generate an image in the correct proportions based on a querystring. Then you can set the background image to the aspx page. This article is an example of how to create an image on the fly through asp.net

Tested the following code and it works quite nicely to produce an in cell chart.

 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);

    }

Go to the text box you want, change the BackGroundImage source to external and the value to an expression. Use an expression something like

= "http://mysite/chartimage.aspx?percentage=" & Fields!MyField.Value
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜