2

I want to create a graph using the MS graph control but this needs to be put on a form for it to produce the graph that I can save in a file.

However, since I want to generate a graph from a Windows service and the application does not have a UI, I would like to be able to generate a graph "in-memory" and produce a graphics file.

Is it possible to achieve using MS Chart control or maybe there is another free/open-source control somewhere?

Notes

My application is a command line app that gets called from a windows service to generate a graphics.

The windows service is running without a UI environment.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Stécy
  • 11,951
  • 16
  • 64
  • 89
  • Why in the world would a Windows Service produce a graph in the first place? It sounds to me like the correct approach would be to create a regular application that produced the graph by communicating with the Windows Service to obtain whatever data was required. Since the result would be a standard application (and maintain the proper delegation of responsibilities), it could use the standard graph control. – Cody Gray - on strike Dec 19 '11 at 15:23
  • Use its SaveImage() method. DrawToBitmap() ought to work too. – Hans Passant Dec 19 '11 at 15:26
  • @Cody, The windows service is starting the application to generate the graphics but since the service and the application are not able to use the desktop UI this fails to produce a graphics. – Stécy Dec 19 '11 at 15:31
  • @Hans, starting the application from the windows service does not allow to interact with the desktop and hence I cannot generate the graphics on a form to latter save it to a file – Stécy Dec 19 '11 at 15:34
  • @Stécy: Erm, how is a service starting an application? That doesn't really make any sense. Yes, your comment to Hans is exactly the problem. That's why I suggest doing this from a standard application that is able to communicate with the service using IPC or whatever mechanism. By standard application, I mean one that *does* have the ability to interact with the desktop. That's the point in it being separate from the service. – Cody Gray - on strike Dec 19 '11 at 15:35
  • @Cody, Please see my edits on the question. – Stécy Dec 19 '11 at 15:36
  • Services have a desktop too, you just can't see it. Nor is it required. Post code if you have a problem. – Hans Passant Dec 19 '11 at 15:36
  • @Stécy You can allow services to interact with the desktop through the service properties. If you can't get things to work this way, a crazy but probably workable alternate would be to host ASP.NET in your service and use the ASP.NET Chart control. – jlew Dec 19 '11 at 15:41
  • @jlew: No, you can't. Not since Windows XP, which was about 10 years ago. – Cody Gray - on strike Dec 19 '11 at 15:56
  • @Cody Would you care to explain the "Allow Service To Interact With the Desktop" checkbox on my Windows 7 machine on the Log On tab? – jlew Dec 19 '11 at 16:47
  • @jlew: The checkbox might be there, but it doesn't work anymore. This is a heavily documented change made in Windows Vista ([reference](http://stackoverflow.com/a/4516515/366904)). Not sure why the checkbox wasn't removed or reworded. – Cody Gray - on strike Dec 20 '11 at 00:18
  • @Cody I understand that reference, but the OP only needs a WindowStation to provide a GDI context, not user input. I believe the checkbox DOES give you this capability, but I may be wrong. – jlew Dec 20 '11 at 13:39

0 Answers0