Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display several graphs which have common X Axis using ZedGraph library?

I need to display several graphs which have a common X Axis and a legend. What I want to achieve is displayed on the picture. The main goal is to have several Y Axis on the one line, not paralelly. So, several curves can be displayed without intersection with each other.

I know how to display several graphs, but then each of them has its own legend and Y Axis.

enter image description here

like image 547
Peter17 Avatar asked Jul 06 '11 14:07

Peter17


1 Answers

I worked with ZedGraph in two of my projects and it doesn't seem to support this feature. Basically, you have two options at this point:

1. Use another plotting library

If you don't have a lot of things depending on ZedGraph already, maybe it's not too late for switching to another plotting control. I worked with this library (CodeProject link), and it has a decent look and support for stacked graphs:

enter image description here

It's less feature-rich compared to ZedGraph, but if 2d-plotting is all you really need, you should probably give it a try.

2. Cheat by creating multiple ZedGraph panes

You can make all your graphs panes have the same width and the same zoom. By setting IsSynchronizeXAxes property to true you make sure that all the panes on ZedGraph control have their X-Axes synchronized automatically.

There are few useful articles to help you achieve the effect you want. Although in Russian, they provide code samples and illustrations and should be of use even without understanding the comments.

  • Plotting multiple graphs on single ZedGraph control
  • Multiple graphs layout
  • Synchronizing zoom and pan on multiple graphs
  • Aligning graph panes properly

You should also hide X-axis and everything else that you don't need. Single legend is tricky but can be achieved by only showing a legend for the topmost graph and adding fake dummy curves with no points to this graph to populate the legend.

like image 181
Dyppl Avatar answered Nov 20 '22 10:11

Dyppl