Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 775
buda Avatar asked Jun 16 '26 10:06

buda


1 Answers

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
like image 166
Nat Avatar answered Jun 21 '26 23:06

Nat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!