Woutero Posted April 13 Share Posted April 13 Sherzod How do I transfer the image on a TUniChart to a BitMap so that I can save the chart to a MemoryStream to be loaded by an TImage? Alternatively, how do I transfer the image on a UniChart to a TCanvas? In Delphi it would be as below, but UniChart does not have Draw as a member: ThisChart:TChart; BitMap : TBitMap; MyStream :TMemoryStream; X,Y : integer; Bitmap:=TBitmap.Create; try X := ThisChart.Width; Y := ThisChart.Height; Bitmap.Height:=Y; Bitmap.Width:=X; ThisChart.Draw(Bitmap.Canvas, Rect(0, 0, X, Y)); MyStream:=TMemoryStream.Create; Bitmap.SaveToStream(MyStream); finally Bitmap.Free; end; Image1.Picture.Bitmap.LoadFromStream( MyStream ); Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 13 Share Posted April 13 @Woutero Quote Link to comment Share on other sites More sharing options...
Woutero Posted April 13 Author Share Posted April 13 Thank you Sherzod. Though when I do UniSession.AddJS('Form1.Chart1.chart.save({type: ''image/png''})'); then, I get an error: "Form1.Chart1.chart.save is not a function" My MainForm is named Form1 and my UniChart is named Chart1. I'm using UniGUI Complete Professional V1.90.0.1560 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 13 Share Posted April 13 @Woutero procedure TMainForm.UniButton1Click(Sender: TObject); begin UniChart1.SaveImage; end; procedure TMainForm.UniChart1ChartImage(Sender: TUniCustomChart; Image: TGraphic); var fName : string; begin fName := UniServerModule.LocalCachePath + 'Chart.png'; Image.SaveToFile(fName); UniSession.SendFile(fName); end; Quote Link to comment Share on other sites More sharing options...
Woutero Posted April 13 Author Share Posted April 13 Thank you Sherzod, it works! Quote Link to comment Share on other sites More sharing options...
Woutero Posted April 14 Author Share Posted April 14 Hi Sherzod I have a problem. The UniChart1.SaveImage will eventually trigger the UniChart1ChartImage event. However, I need the UniChart1ChartImage event to fire earlier so that I can use the result still within the UniButton1Click procedure. Example: UniButton1Click calls DoSomething procedure DoSomething; begin UniChart1.SaveImage; // I want to use the png file created by UniChart1ChartImage here. // but the UniChartImage event only triggers after DoSomething procedure has finished. // So I need to call UniChart1.SaveImage earlier, before I execute DoSomething end; So I'm looking for an event that will trigger every time just after a Chart has been drawn/updated? Which event fires just after a UniChart has been drawn/updated? Then I can use that event to call UniChart1.SaveImage to create the png file upfront before DoSomething is executed. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 15 Share Posted April 15 22 hours ago, Woutero said: So I'm looking for an event that will trigger every time just after a Chart has been drawn/updated? If I understand you correctly, you can use these client events I think: Quote Link to comment Share on other sites More sharing options...
Woutero Posted April 15 Author Share Posted April 15 Thanks Sherzod So how do I execute UniChart1.SaveImage; from within the chart.redraw event? Remember that when I use UniSession.AddJS('Form1.Chart1.chart.save({type: ''image/png''})'); then, I get an error: "Form1.Chart1.chart.save is not a function" Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 15 Share Posted April 15 2 minutes ago, Woutero said: from within the chart.redraw event? You can try sending an ajaxRequest to the server inside this event, and execute the server side code. Quote Link to comment Share on other sites More sharing options...
Woutero Posted April 15 Author Share Posted April 15 Thanks, can you please give a code example? In essence I want to trigger the procedure TMainForm.UniChart1ChartImage(Sender: TUniCustomChart; Image: TGraphic); event on demand Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 15 Share Posted April 15 Once again, please clarify your case step by step. Perhaps we will find another optimal solution. Quote Link to comment Share on other sites More sharing options...
Woutero Posted April 15 Author Share Posted April 15 Thanks for your continued help Sherzod. I really appreciate it. As I understand, UniChart1.SaveImage; triggers the event: UniChart1ChartImage(Sender: TUniCustomChart; Image: TGraphic) All I want to do is to trigger this event on request. Is that possible? Is there any UniSession.AddJS() code that can do this? Quote Link to comment Share on other sites More sharing options...
Woutero Posted April 17 Author Share Posted April 17 Sherzod I am able to trigger the UniChart1ChartImage event on demand by using a UniTimer set to RunOnce. Every time I update a chart, I enable this Timer which then calls UniChart.SaveImage which then triggers the ChartImage event. Quote Link to comment Share on other sites More sharing options...
Woutero Posted April 17 Author Share Posted April 17 On 4/13/2024 at 4:55 PM, Sherzod said: @Woutero procedure TMainForm.UniButton1Click(Sender: TObject); begin UniChart1.SaveImage; end; procedure TMainForm.UniChart1ChartImage(Sender: TUniCustomChart; Image: TGraphic); var fName : string; begin fName := UniServerModule.LocalCachePath + 'Chart.png'; Image.SaveToFile(fName); UniSession.SendFile(fName); end; Sherzod When using Image.SaveToFile(FileName), how does one set the file type? For example, if I want to use a jpg, how do I set JPG, or does UniGUI automatically look at the extension of the FileName? Quote Link to comment Share on other sites More sharing options...
Woutero Posted April 17 Author Share Posted April 17 Also, when using Image.SaveToStream() within procedure TMainForm.UniChart1ChartImage(Sender: TUniCustomChart; Image: TGraphic); what is the default image type, or how does one set it? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted April 17 Share Posted April 17 Hello, 3 hours ago, Woutero said: default image type The default image type is png. I will check... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.