?
Solved

Printing Charts from ASP.NET

Posted on 2010-01-04
11
Medium Priority
?
686 Views
Last Modified: 2012-05-08
I'm trying to print out charts that I create using System.Web.UI.DataVisualization.Charting.  I have tried setting the ImageType to ChartImageType.Png but I still get the same thing -- an empty box with a red "X" in the corner.

I also have Menus, GridViews, etc and those print just fine.  It's the charts that won't cooperate.
0
Comment
Question by:StacyThomas
  • 6
  • 5
11 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 26171345
check the folder permissions of the folder where the Chart control is writing the images dynamically.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 26171366
try this out also
<add key="ChartImageHandler" value="storage=memory;timeout=20;URL=/_layouts/Images/MicrosoftChartControls/" />

also check the link for details
http://chartpart.codeplex.com/WorkItem/View.aspx?WorkItemId=10666
0
 

Author Comment

by:StacyThomas
ID: 26171575
I've tried the following and still no luck:
 <add key="ChartImageHandler" value="storage=memory;timeout=20;URL=/_layouts/Images/MicrosoftChartControls/" />

(Based on the link) <add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />

(Based on the link in the link )  <add key="ChartImageHandler" value="storage=session;timeout=20"/>

(Based on another suggestion in the link in the link)  <add key="ChartImageHandler" value="storage=file;timeout=20;dir=C:\WINNT\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files;" />



I appreciate your quick suggestions.  Any other ideas?  Thanks!!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:Roshan Davis
ID: 26171655
hi Stacy
can you check this example in your machine and see whether it is showing the same way?
http://www.codeproject.com/KB/dotnet/newmicrosoftchartcontrol.aspx

~Rosh
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 26171710
Also can you check this link? http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/a5b09b47-23b2-4cb4-bc0a-966e486a65a2

specially the part
Unfortunately this is a product bug which is already addressed in the next version.

The chart http handler cannot deliver images until at least one chart control is rendered in the current process.  For now I would suggest the following workaround - using global.asax to emulate chart rendering once before the chart handler is invoked:

        // This is Global.asax.cs
        static bool _chartInitialized;  
        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            if (!_chartInitialized)
            {
                _chartInitialized = true;
                string s = ChartHttpHandler.Settings.FolderName;
            }
        }


For more info please read this thread http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/31975aad-807d-4056-9910-03ce04a143be/
0
 

Author Comment

by:StacyThomas
ID: 26171879
Thanks roshmon.  I think that those are addressing when the chart won't render on the page, which mine will.  They render fine, they just won't print.  I think my initial question wasn't very clear, now that I re-read it.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 26172750
can you quote some code that you are using for printing?
Are you referring the attribute "ImageType" anywhere before printing? can you check the type is coreectly given there 9I mean PNG)
0
 

Author Comment

by:StacyThomas
ID: 26172779
Yes, I'm setting the image type to "png" as shown in the code below.
chartName.ImageType = ChartImageType.Png;

Open in new window

0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 1500 total points
ID: 26172820
Can you try a SaveImage before your print?
chartName.SaveImage(filename, ChartImageFormat.Png)

Open in new window

0
 

Author Comment

by:StacyThomas
ID: 26174328
Got it!  Have to change the ImageLocation (got the tip from here: http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/thread/ee6a7f19-d63d-48ab-9186-0f1ee1221408 )

chartName.ImageType = ChartImageType.Png;
chartName.ImageLocation = "ChartPic_#UID";
chartName.ImageStorageMode = ImageStorageMode.UseImageLocation;

Open in new window

0
 

Author Closing Comment

by:StacyThomas
ID: 31672395
Solution led to the correct answer, which is that the image location needs to be set.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Integration Management Part 2
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month16 days, 21 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question