Jump to content

 

Photo

How to render visifire chart as image format?


  • Please log in to reply
10 replies to this topic

#1 Raju MVN

Raju MVN

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 10 December 2008 - 09:27 AM

Hello All,

Is there a way to render visifire chart into image format?

If option is there, can anybody please help in rendering visifire chart as a imgae format (.png or something else)?

Thanx & regards,
Raju MVN

#2 CHIRAG.N.R.

CHIRAG.N.R.

    Advanced Member

  • Administrators
  • PipPipPip
  • 567 posts

Posted 10 December 2008 - 11:32 AM

Update

OMG! I almost forgot WPF. Please look in to somnath's example to print Visifire charts in WPF.

--------

Raju,

Visifire charts cannot be converted image! It's the limitation of Silverlight on which Visifire is built on. We will start supporting print & image conversion as soon as Silverlight comes with it.
Regards,
Chirag
Team Visifire

#3 PqBob

PqBob

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 10 December 2008 - 11:41 AM

Is there any support for rendering WPF charts to image format?

Raju,

Visifire charts cannot be converted image! It's the limitation of Silverlight on which Visifire is built on. We will start supporting print & image conversion as soon as Silverlight comes with it.



#4 mike74

mike74

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 10 December 2008 - 03:01 PM

I do it in my WPF app. See this thread:

http://www.visifire....p?showtopic=413


Raju,

Visifire charts cannot be converted image! It's the limitation of Silverlight on which Visifire is built on. We will start supporting print & image conversion as soon as Silverlight comes with it.



#5 somnath

somnath

    Advanced Member

  • Team Visifire
  • PipPipPip
  • 965 posts
  • Gender:Male
  • Location:Bangalore

Posted 10 December 2008 - 03:10 PM

Hi,

I have written a function to save Visifire chart control as png in WPF. You can use different encoder to save the chart image into different format.

Here is my code:

ExportToPng(new Uri("C:\\VisifireChart.png"), MyChart);

public void ExportToPng(Uri path, Visifire.Charts.Chart surface)
		{   
			if (path == null) return;

			// Save current canvas transform
			Transform transform = surface.LayoutTransform;
			// reset current transform (in case it is scaled or rotated)
			surface.LayoutTransform = null;

			// Create a render bitmap and push the surface to it
			RenderTargetBitmap renderBitmap =
			  new RenderTargetBitmap(
				(int)surface.ActualWidth,
				(int)surface.ActualHeight,
				96d,
				96d,
				PixelFormats.Pbgra32);
			renderBitmap.Render(surface);

			// Create a file stream for saving image
			using (FileStream outStream = new FileStream(path.LocalPath, FileMode.Create))
			{
				// Use png encoder for our data
				PngBitmapEncoder encoder = new PngBitmapEncoder();
				// push the rendered bitmap to it
				encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
				// save the data to the stream
				encoder.Save(outStream);
			}

			// Restore previously saved layout
			surface.LayoutTransform = transform;
		}


#6 Raju MVN

Raju MVN

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 12 December 2008 - 08:11 AM

Thanx alot for you quick turn.

Visifire is a wonderful component I have used.

It looks good if there is a provision for rendering chart as image format..


Update

OMG! I almost forgot WPF. Please look in to somnath's example to print Visifire charts in WPF.

--------

Raju,

Visifire charts cannot be converted image! It's the limitation of Silverlight on which Visifire is built on. We will start supporting print & image conversion as soon as Silverlight comes with it.



#7 chloemarqz

chloemarqz

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 27 November 2009 - 08:57 AM

Does Visifire have a provision chart for image format? I didn't know if there was such one.

yours,
chloe

_______________
Simulation pret

#8 somnath

somnath

    Advanced Member

  • Team Visifire
  • PipPipPip
  • 965 posts
  • Gender:Male
  • Location:Bangalore

Posted 27 November 2009 - 10:47 AM

Hi Chloemarqz,

Checkout the following links from Visifire Documentation.

If you are working with WPF
http://www.visifire.com/documentation/Visifire_Documentation/Common_Tasks/Exporting_Chart_toImage_using_Managed_Code_in_WPF.htm

If you are working with Silverlight
http://www.visifire.com/documentation/Visifire_Documentation/Common_Tasks/Exporting_Chart_as_Image_in_Silverlight.htm

Regards,
Somnath

#9 hammelbeck

hammelbeck

    Newbie

  • Members
  • Pip
  • 5 posts
  • Gender:Male
  • Location:Salenstein
  • Interests:ASP.NET / VB.NET / SQL 2005 - 2008

Posted 20 February 2010 - 05:11 PM

Hi Chloemarqz,

Checkout the following links from Visifire Documentation.

If you are working with WPF
http://www.visifire.com/documentation/Visifire_Documentation/Common_Tasks/Exporting_Chart_toImage_using_Managed_Code_in_WPF.htm

If you are working with Silverlight
http://www.visifire.com/documentation/Visifire_Documentation/Common_Tasks/Exporting_Chart_as_Image_in_Silverlight.htm

Regards,
Somnath


Dear Somnath,

I rewrote your code to VB.NET. I actually want to create graphs in ASP.NET with WPF and display a rendered
image using a windows-DLL which I reference from ASP.NET. Below is the code from a VB.NET-Windows App.
When I bind the chart to a system.windows.forms.integration.elemenshost then the graph is displayed correctly.
When I take the chart and pass to the "SaveChart"-function then I get an exception "pixelwidth is not set".
Maybe it is something with "'Chart.LayoutTransform = Nothing" what I do wrong.
I would be happy if you could help me. Another question of mine is: how can I scale a chart?

Thank you very much in advance.

Sincerely
Henry-JP






Private Sub CreateChart()
Dim chart As New Chart()
Dim dataSeries As New DataSeries
dataSeries.RenderAs = RenderAs.Column
Dim i As Integer = 0
For i = 0 To 250
Dim dataPoint As New DataPoint
dataPoint.XValue = i
dataPoint.YValue = i
dataPoint.ToolTipText = "Hello world..."
dataSeries.DataPoints.Add(dataPoint)
Next
chart.Series.Add(dataSeries)
Dim P As String = System.IO.Path.GetFullPath(".") + "\test2.png"
eh.Child = chart
chart.BeginInit()
SaveChart(P, chart)
End Sub

Public Function SaveChart(ByVal P As String, ByVal Chart As Visifire.Charts.Chart) As Boolean
Dim T As Windows.Media.Transform
T = Chart.LayoutTransform
'Chart.LayoutTransform = Nothing
Dim IW As Integer = Chart.ActualWidth
Dim IH As Integer = Chart.ActualHeight
Dim RB As System.Windows.Media.Imaging.RenderTargetBitmap = New System.Windows.Media.Imaging.RenderTargetBitmap(IW, IH, 96D, 96D, System.Windows.Media.PixelFormats.Pbgra32)
RB.Render(Chart)
Dim fo As System.Windows.Media.Imaging.PngBitmapEncoder = New System.Windows.Media.Imaging.PngBitmapEncoder
fo.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(RB))
If System.IO.File.Exists(P) Then System.IO.File.Delete(P)
Dim OS As System.IO.FileStream = New System.IO.FileStream(P, IO.FileMode.Create)
fo.Save(OS)
End Function
_________________________
No questions? No answers!

#10 vivek

vivek

    Advanced Member

  • Team Visifire
  • PipPipPip
  • 3,588 posts
  • Gender:Male
  • Location:Bangalore

Posted 22 February 2010 - 06:14 AM

Hi Hammelbeck,

You are trying to extract a bitmap from chart before it gets rendered. In order to do this you have to use Measure and Arrange methods for chart which fires the size changed event. Once size changed event is fired, the child objects will be positioned and the size of UIElement (chart) will be determined by which you will be able to extract a bitmap from chart.

Example:

chart.BeginInit()
chart.EndInit()
chart.Measure(new Size(500, 300))
chart.Arrange(new Rect(0, 0, 500, 300))
chart.UpdateLayout()
SaveChart(P, chart)

But in this case loaded event for chart may fire after generating the bitmap and we are animating the chart once it is loaded because of which you may not be able to see the rendered chart. So i suggest you to set AnimationEnabled property to False in chart.

Regards,
Vivek
Team Visifire


#11 hammelbeck

hammelbeck

    Newbie

  • Members
  • Pip
  • 5 posts
  • Gender:Male
  • Location:Salenstein
  • Interests:ASP.NET / VB.NET / SQL 2005 - 2008

Posted 26 February 2010 - 02:12 PM

Dear Vivek,

thanks a lot for your reply. I tried and it is working perfect
once setting AnimationEnabled to false.
Thanks a lot and greetings.

Sincerely
Henry-JP
_________________________
No questions? No answers!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users