Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make Silverlight support Chart to Picture

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to make Silverlight support chart to picture, the article is very detailed, has a certain reference value, interested friends must read it!

Therefore, the realization of chart to picture can be divided into several steps.

one。 Write a WPF client program

The idea is very simple.

1.1 define a timer, and then detect the xml file of a directory, where the tentative name of the directory is chart

Timer = new DispatcherTimer (); timer.Interval = new TimeSpan (0,0,2); timer.Tick + = new EventHandler (timer_Tick); timer.Start (); void timer_Tick (object sender, EventArgs e) {string [] files = System.IO.Directory.GetFiles (AppDomain.CurrentDomain.BaseDirectory + "chart"); if (files.Length > 0) {}}

1.2 if any, it is deserialized into a Chart object for rendering

Void timer_Tick (object sender, EventArgs e) {string [] files = System.IO.Directory.GetFiles (AppDomain.CurrentDomain.BaseDirectory + "chart"); if (files.Length > 0) {LoadXml (files [0]);}} private void LoadXml (string xmlFile) {XmlDocument doc = new XmlDocument (); doc.Load (xmlFile); StringReader stringReader = new StringReader (doc.InnerXml); XmlReader xmlReader = XmlReader.Create (stringReader); Chart chart = XamlReader.Load (xmlReader) as Chart; chart.AnimationEnabled = false StringReader.Close (); xmlReader.Close (); this.Content=chart;}

1.3 take screenshots after rendering

Void timer_Tick (object sender, EventArgs e) {string [] files = System.IO.Directory.GetFiles (AppDomain.CurrentDomain.BaseDirectory + "chart"); if (files.Length > 0) {LoadXml (files [0]); PrintPicture (files [0]);} private void PrintPicture (string fileName) {this.Dispatcher.BeginInvoke (new Action () = > {int Height = (int) this.ActualHeight; int Width = (int) this.ActualWidth) RenderTargetBitmap bmp = new RenderTargetBitmap (Width, Height, 96,96, PixelFormats.Pbgra32); bmp.Render (this); string file = "C:\\ temp\\ a.jpg"; BitmapEncoder encoder; encoder = new JpegBitmapEncoder (); encoder.Frames.Add (BitmapFrame.Create (bmp)); using (Stream stm = File.Create (file)) {encoder.Save (stm);} File.Delete (fileName);}), System.Windows.Threading.DispatcherPriority.Render);}

1.4 delete the xml file after converting to a picture

two。 Place the compiled wpf program in the web root directory, and then start the program

three。 Use ajax interaction to transfer the currently displayed xml to the chart directory

Front end

$.ajax ({type: "POST", url: "ajaxServer.aspx", data: "name=" + vChart.dataUri, success: function (msg) {alert ("Success");}})

Back end

Copy xml files or other processing methods to get xml to the chart directory

Protected void Page_Load (object sender, EventArgs e) {File.Copy (Server.MapPath (this.Request ["name"]), Server.MapPath (".. / chart/" + this.Request ["name"]);}

Note: pay attention to the namespaces of wpf and silverlight when converting. It can also be regarded as a method, which is more than enough to generate pictures for charts.

The above is all the contents of the article "how to make Silverlight support Chart to Picture". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report