We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Drawing a single bar graph

Thread ID:

Created:

Updated:

Platform:

Replies:

89535 Aug 27,2009 12:32 PM Sep 2,2009 03:18 AM ASP.NET Web Forms (Classic) 6
loading
Tags: PDF
Aaron Hood
Asked On August 27, 2009 12:32 PM

I was able to create a single bar graph by drawing two rectangles on top of each other. However, I am unable to get exactly what I want. I want to draw a dashed box and then fill the box a certain percent.

Like:

0% 50% 100%
-------------------------------------
| | |
|Filled (gradient) | White |
| | |
-------------------------------------

Any suggestions?

Sri Subhashini M [Syncfusion]
Replied On August 28, 2009 04:17 AM

Hi Aaron,

Thank you for your interest in Essential PDF.

We can draw Rectangle with dashed border by setting DashStyle of the PdfPen as Dash. And we can fill the rectangle with gradient color with the help of the PdfLinearGradientBrush. Kindly refer the below code snippet,


// Create a new page.
PdfPage page = doc.Pages.Add();
PdfGraphics g = page.Graphics;

PdfPen pen = new PdfPen(Color.Black);
pen.DashStyle = PdfDashStyle.Dash;

RectangleF rect = new RectangleF(10, 120, 200, 100);
PdfLinearGradientBrush gBrush = new PdfLinearGradientBrush(rect, Color.LightGreen, Color.Brown, PdfLinearGradientMode.BackwardDiagonal);
pen.Color = Color.Black;
g.DrawRectangle(pen, gBrush, rect);

rect = new RectangleF(200, 120, 100, 100);
g.DrawRectangle(pen, PdfBrushes.White, rect);


Could you please try the below sample from the below specified location and let me know if this helps,

http://files.syncfusion.com/samples/PDF.Windows/PDF_Window_F89535.zip

Regards,
Suba

Aaron Hood
Replied On August 28, 2009 11:36 AM

That worked. However, I tweaked it a bit to make it easier to move the percent filled for dynamic purposes. It works except I am unable to make the gradientbrush rectangle to change pen color to gray. For some reason it's always black. Any suggestions?

Here is what I have:

PdfPen pen = new PdfPen(Color.Gray);
pen.DashStyle = PdfDashStyle.Dash;
pen.Color = Color.Gray;

RectangleF rect = new RectangleF(0, 120, 300, 13);
g.DrawRectangle(pen, PdfBrushes.White, rect);

rect = new RectangleF(0, 120, 200, 13);
PdfLinearGradientBrush gBrush = new PdfLinearGradientBrush(rect, Color.LightGreen, Color.White, PdfLinearGradientMode.Vertical);
pen.Color = Color.Gray;
g.DrawRectangle(pen, gBrush, rect);

Aaron Hood
Replied On August 28, 2009 01:33 PM

I think I found the problem but I do not understand why it's a problem.

Why do I get a black border when I draw a the same colored border on top of each other?

Example 1 (I get a gray border around the gradient box):
PdfPen pen = new PdfPen(Color.LightGray);
pen.DashStyle = PdfDashStyle.Dash;
pen.Color = Color.LightGray;

RectangleF rect = new RectangleF(0, 120, 300, 13);
g.DrawRectangle(pen, PdfBrushes.White, rect);

pen.Color = Color.Gray;
rect = new RectangleF(0, 120, 200, 13);
PdfLinearGradientBrush gBrush = new PdfLinearGradientBrush(rect, Color.LightGreen, Color.White, PdfLinearGradientMode.Vertical);
g.DrawRectangle(pen, gBrush, rect);

Example 2 (I get a black border):
PdfPen pen = new PdfPen(Color.LightGray);
pen.DashStyle = PdfDashStyle.Dash;
pen.Color = Color.LightGray;

RectangleF rect = new RectangleF(0, 120, 300, 13);
g.DrawRectangle(pen, PdfBrushes.White, rect);

pen.Color = Color.LightGray;
rect = new RectangleF(0, 120, 200, 13);
PdfLinearGradientBrush gBrush = new PdfLinearGradientBrush(rect, Color.LightGreen, Color.White, PdfLinearGradientMode.Vertical);
g.DrawRectangle(pen, gBrush, rect);

Sri Subhashini M [Syncfusion]
Replied On September 1, 2009 04:35 AM

Hi Aaron,

It seems that you have drawn the rectangle two times on the same area. So, the Gray border has been drawn twice and the border color looks like black. Could you please try the below code snippet and let me know if this helps?


PdfPen pen = new PdfPen(Color.LightGray);
pen.DashStyle = PdfDashStyle.Dash;
pen.Color = Color.LightGray;

ectangleF rect = new RectangleF(0, 120, 300, 13);
//g.DrawRectangle(pen, PdfBrushes.White, rect);

pen.Color = Color.LightGray;
rect = new RectangleF(0, 120, 200, 13);
PdfLinearGradientBrush gBrush = new PdfLinearGradientBrush(rect, Color.LightGreen, Color.White, PdfLinearGradientMode.Vertical);
g.DrawRectangle(pen, gBrush, rect);


Regards,
Suba

Aaron Hood
Replied On September 1, 2009 11:32 AM

I just tried your example and it has a black border as well.

Sri Subhashini M [Syncfusion]
Replied On September 2, 2009 03:18 AM

Hi Aaron,

I am afraid that I was not able to reproduce the issue in our testing environment. I have created a simple sample to test this issue and it is available in the following link.

http://files.syncfusion.com/samples/Pdf.Windows/PDF_Window_F89535_1.zip

Please have a look at the above sample and if still the issue exists, could you please try reproducing it in the above sample or send us your working sample (if possible) so that we could sort out the cause of the issue and provide you a solution?

Regards,
Suba

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;