Search code examples
.netgraphingzedgraph

How do I limit the number of decimal places shown in a ZedGraph Y Scale?


I am using ZedGraph's master pane to display two graphs that have synchronized X axes. I am running into a problem when I zoom in on one of the graphs. As I zoom in, the Y axis will show an increasing number of decimal places, eventually causing the zoomed-in graph to be narrower than the other graph, preventing their X axes from lining up exactly.

The workarounds I have tried:

  • Set the YAxis.MinSpace and Y2Axis.MinSpace on both subpanes larger
  • Make YAxis.Scale.FontSpect.Size smaller

Both of these will help but do not fix the problem. Eventually, I'll zoom in enough that one graph is showing enough decimal places on the scale that the two graphs are no longer the same width.

I think I can solve the problem by restricting the number of decimal places displayed, but I can't find a way to do this.


Solution

  • For a fixed number of decimal places, you can do

    GraphPane.YAxis.Scale.Format = "F0"; // 0 decimal places
    

    Or if you wanted to have a chance to examine the current visible range before deciding on the number of decimal places, you can add an event handler for

    GraphPane.YAxis.ScaleFormatEvent