2

Am using a ZedGraph in which data is plotted for a period of more than one year. When its initially displayed, its showing the data in a single shot but the X-axis is in DateTime format. How can I set the X axis values to Year at the time of loading? I need to change the format on different zooming levels ie, on further zooming the format should be MMM/yyyy followed by DD/MMM/yyyy and DD/MMM/yyyy HH:MM:ss

enter image description here

Sarath Subramanian
  • 20,027
  • 11
  • 82
  • 86

1 Answers1

2

Before loading your data your should set something like:

zedgraphControl.GraphPane.XAxis.Scale.Format = "dd.MM.yyyy";

And in zedgraphControl_ZoomEvent you can change scale format again like

private void zedgraphControl_ZoomEvent(ZedGraphControl sender, ZoomState oldState, ZoomState newState)
    {
        GraphPane pane = sender.GraphPane;
        pane.XAxis.Scale.Format = "dd.MM.yyyy HH:mm:ss";
    }

In this event you can add some conditions depends on your current scale.

Varro
  • 73
  • 1
  • 11
  • 1
    To run a test on your current scale, check the value of `yourGraph.GraphPane.XAxis.Scale.MajorUnit` – RMGT Sep 08 '16 at 15:41