2

i have a working DLL where i have one function to add arrays to a list and another function that shows all list-arrays in a ZED-Graph-diagram. All arrays have the same size. Currently the x-axis is shown in points from 0 to 1024. Question is: What do i have to change to display the x-axis in time?

I have the value "Intervall" (time between two points) that i can pass into the function.

Thanks for the help.

Here is what i have so far:

public void AddGraph(double[] Values, string LegendName)
{
    int i = 0;
    PointPairList list = new PointPairList();
    for (i = 0; i < Values.Length; i++)
    {
        list.Add(i, Values[i]);
    }

    if (i > MaxXAxis)
        MaxXAxis = i;

    SList.Add(list);
    SListColor.Add(Color.Black);
    SListName.Add(LegendName);
}

public void ShowDiagram(string Title, string XAxisName, string YAxisName, int Timeout_ms)
{     
    ZedGraph.ZedGraphControl zgc = new ZedGraphControl();
    GraphPane myPane = zgc.GraphPane;
    LineItem myCurve = null;


    // Set the titles and axis labels
    myPane.Title.Text = Title;
    myPane.XAxis.Title.Text = XAxisName;
    myPane.YAxis.Title.Text = YAxisName;

    for (int i = 0; i < SList.Count(); i++)
    {
        myCurve = myPane.AddCurve(SListName[i], SList[i], SListColor[i], SymbolType.None);
        myCurve.Line.Width = 2;
    }

    // Add gridlines to the plot, and make them gray
    myPane.XAxis.MinorGrid.IsVisible = true;
    myPane.YAxis.MinorGrid.IsVisible = true;
    myPane.XAxis.MinorGrid.Color = Color.LightGray;
    myPane.YAxis.MinorGrid.Color = Color.LightGray;
    myPane.XAxis.MinorGrid.DashOff = 0;
    myPane.YAxis.MinorGrid.DashOff = 0;

    myPane.XAxis.MajorGrid.IsVisible = true;
    myPane.YAxis.MajorGrid.IsVisible = true;
    myPane.XAxis.MajorGrid.Color = Color.Gray;
    myPane.YAxis.MajorGrid.Color = Color.Gray;
    myPane.XAxis.MajorGrid.DashOff = 0;
    myPane.YAxis.MajorGrid.DashOff = 0;

    // Move Legend to buttom
    myPane.Legend.Position = LegendPos.Bottom;

    zgc.AxisChange();

    myPane.XAxis.Scale.Max = MaxXAxis;

    zgc.Location = new Point(0, 0);
    zgc.Size = new Size(panel_diagramm.ClientRectangle.Width, panel_diagramm.ClientRectangle.Height);

    panel_diagramm.Controls.Add(zgc);             
}
shadowsora
  • 663
  • 7
  • 15
Thomas Mann
  • 99
  • 3
  • 19

1 Answers1

1

This is my first time posting so I apologize for not putting it in a better format. The following allows you to setup your x-axis to display time:

myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Title.Text = "Time (HH:MM:SS)";
myPane.XAxis.Scale.Format = "HH:mm:ss";
myPane.XAxis.Scale.MajorUnit = DateUnit.Minute;
myPane.XAxis.Scale.MinorUnit = DateUnit.Minute;
myPane.XAxis.Scale.Min = DateTime.Now.Subtract(new TimeSpan(0, 0, 10, 0, 0).ToOADate();
myPane.XAxis.Scale.Max = DateTime.Now.ToOADate();
shadowsora
  • 663
  • 7
  • 15
JayCee
  • 21
  • 3