WPF Graph Drawing using Path scaling RRS feed

  • Question

  • I'm new to WPF and I enjoy it but I have ran into a little problem that seems like it should have a simple solution, but I have been working on it for about a week now and can't seem to get it to work. I'm using Path Geometry to Draw a fairly simple graph dynamically. The Y-axis covers a range of remperatures from 0 to 1600 Celcius. The graphs that are displayed almost always have all their values within this range and if they don't I don't want to show those points anyway. I really want the range to be static. Now, the size of the canvas that this graph goes on however, I want to be dynamic. It has the X and the Y-axes displayed with little marks every 200 degrees, drawn with a separate Path-figure from the curve itself. When I resize the canvas, it works perfectly with the axes, because I have the stretch property set to fill. The problem, however, is with the curve itself. Not all curves cover the range from 0 to 1600, so when I set the strecth property to fill as you can imagine, if the path only ranges from let's say 200 to 1400, the stretch property will stretch it so that it looks like it ranges from 0 to 1600. This is of course not what I want.

    If I don't use fill, when the graph is resized, obviously the graph does not follow the axes and can even get cut off. I can solve this by drawing a little extra line every time at 0 and at 1600 and use the fill property, but it doesn't seem to be a very elegant solution. On top of that, if I happen to have values outside this range later in the curve, then it's not to scale with the axes again. I have been searching for a way to define that my path is to be defined between the range of 0 to 1600 so cut off anything other than that and stretch the 0 to 1600 range into the canvas, but I haven't been able to find anything. I have been looking at the clip property for example. But nothing really seems to work for me. Perhaps I am going about it entirely wrong?

    I'm coding in C#, VS2010 .NET 4.0

    Any guidance would be greatly appreciated. 

    Thursday, June 3, 2010 7:39 AM