How to sync three GraphPane's in ZedGraph?
Asked Answered
B

2

3

While using ZedGraph to display six graphs on three GraphPane's as shown in first pic, all graphs are in sync. However when i try to display the date for the first pane the graph are out of sync as shown in the second pic. Its important that all six graphs remain in sync for the user to make sense of the whole chart.

I have tried XAxis.Type = AxisType.Date as suggested by tmwoods here and was able to show the dates along X axis. The DateTime along X axis can be in minutes/seconds say from 9:00 AM to 4:00 PM could also be in days say form 28/1/2009 to 25/11/2012

Picture-1

Picture-2

Babysitter answered 14/4, 2013 at 7:2 Comment(4)
Could you use the same scaling on all three charts? I mean so the date displays on all three. My only other thought is to make the Maximum on the latter two charts to be ~530 (I am guessing where they get cut off) so the data stretches across the whole chart.Brill
@Brill say i have 3 arrays Xaxis[] = {1,2,3,4,5,6,7,8,...} Yaxis[] = {40,42,45,50,39,38,41...} Date[] = {10-Apr,11-Apr,12-Apr,13-Apr,14-Apr,15-Apr...} Can i plot the graph using the values in the Xaxis and Yaxis array and just show the dates from the Date array at the corresponding points along the X axis. i would like to use the contents of the date array just for displaying and plot values using X and Y arrays.Babysitter
After a bit of research I am led to believe that you cannot add a second X-Axis; you can only do that with the Y-Axis. I think the only solution to this is a hack; you'll have to cut off the second two charts by setting the maximum value so the chart stretches; I think this might be the only way. If you explain what you're trying to do a bit more maybe we can brainstorm another solution though :)Brill
@Brill sorry about the delay. The green graph on first pane is the price of a stock and the black one is its moving average. On the second pane are technical indicators modified-RSI and modified-ADX. On the third pane are custom made price action indicators. To track a stock symbol all the indicators below should be showing data relevant to that particualar instant of time on the first pane(in-sync) [en.wikipedia.org/wiki/Relative_strength_index] ...[investopedia.com/terms/a/adx.asp]Babysitter
B
2

OK, I think I got it. Try adding this to your code:

pane1.Chart.Rect = new RectangleF (pane2.Chart.Rect.X,
            pane2.Chart.Rect.Y,
            pane2.Chart.Rect.Width,
            pane2.Chart.Rect.Height);

I've been peeking around and Zedgraph supports something called Graph Align but I can't find source on it anywhere. The closest I have found is here; check out the bottom-most example. It describes how to align multiple charts of varyng sizing vertically. But I haven't tested it out.

Brill answered 19/4, 2013 at 14:35 Comment(0)
P
2

The accepted answer is correct and works, however, ZedGraph has a built-in feature that keeps all axes in sync:

zgc.IsSynchronizeXAxes = true; // This keeps X axes min and max in sync
zgc.IsSynchronizeYAxes = true; // This keeps Y axes min and max in sync
zgc.MasterPane.IsCommonScaleFactor = true // This will ensure a common Scale is applied to all graphPanes axes.

Here is a IsCommonScaleFactor and a IsSynchronizeXAxes or IsSynchronizeYAxes sample.

Prelature answered 23/11, 2013 at 20:47 Comment(1)
Oops, it looks like something was missing. I edited my answer.Prelature

© 2022 - 2024 — McMap. All rights reserved.