0

I draw a line in a zedgraph pane, but sometimes it will be like this: Wrong

while it should be:

Right

i can't find anything wrong from my code, anyone know how to solve this, thanks very much!

here is part of my code:

        MasterPane master = zdg_stock.MasterPane;
        var stockValueList = new PointPairList();
        for (int i = 0; i < _dtUserStockHistory.Rows.Count; i++)
        {
            XDate time = XDate.DateTimeToXLDate((DateTime)_dtUserStockHistory.Rows[i]["ush_time"]);
            stockValueList.Add(
                time,
                double.Parse(_dtUserStockHistory.Rows[i]["stock_value"].ToString()));
        }
        var pValue = new GraphPane();
        LineItem lValue = pValue.AddCurve(string.Empty, stockValueList, Color.Red);
        master.Add(pValue);
        using (Graphics g = zdg_stock.CreateGraphics())
        {
            master.SetLayout(g, PaneLayout.SingleColumn);
            zdg_stock.AxisChange();
            zdg_stock.IsSynchronizeXAxes = true;
            zdg_stock.IsAutoScrollRange = true;
            zdg_stock.IsShowHScrollBar = true;
            zdg_stock.IsEnableVZoom = false;
            zdg_stock.IsShowPointValues = true;
        }

        zdg_stock.AxisChange();
MangMang
  • 427
  • 1
  • 5
  • 17

1 Answers1

1

how about a sorting before plotting?

user287107
  • 9,286
  • 1
  • 31
  • 47
  • sorting in SQL or in DataTable? i'm trying to add 'order by time' in my sql. – MangMang Jun 19 '12 at 07:18
  • it does not matter where, but the fact that in your first graph the line is also going backwards indicates that your data is not in a time sorted order. – user287107 Jun 19 '12 at 21:05
  • but it does not happen regularly, i changed nothing but reopen the form, it turns to be normal. whatever, i have add 'order by time', and watching whether it will happen again.Thanks~ – MangMang Jun 22 '12 at 08:16