ashish kumar - 2018-07-13

Hi All,
I have implemented ZedGraph in windows application (c#) and its working great.
But facing one problem in auto scroll section. In first one minutes section candle stick graph generate one by one in the panel on each second. Once the time reached to 60 second, application starts scrolling.

In next each tick, application generating new candle and graph moving forward to x axis. As the time increased slowly and gradually new graph generation position shifted towards left side (as shown in the image).

In the shared image when time is 01:05 at the time graph position is different and at the time of 1:40 same graph position in shifted (shifted to left).
https://drive.google.com/file/d/1ZP64MbXzQhnoL1YgsEmwQvUhFf0FMeMq/view?usp=sharing

I need help and please let me know how can I fix this issue.

----------------CODE---------------
private void test(double paramhigh, double paramlow, double paramopen, double paramclose, string paramtag)
{
int j = 1;
double x = xDate.XLDate;
double time = (Environment.TickCount - TickStart) / 1000.0;
Scale xScale = zg1.GraphPane.XAxis.Scale;
if (time > xScale.Max - xScale.MajorStep)
{
if (intMode == 1)
{
if (xAxisIncrement == 5)
{
xScale.Max = (time-1) + xScale.MajorStep+2;
xScale.Min = xScale.Max - 30.0;
xAxisIncrement = 1;
}
else
{
// xScale.Max = time + xScale.MajorStep;
//xScale.Min = xScale.Max - 30.0;
}
xAxisIncrement += 1;
}
else
{
xScale.Max = time + xScale.MajorStep;
xScale.Min = 0;
}
}
if (j == 1)
{
myPane.Title.Text = "Diamond Future Trading";
myPane.XAxis.Title.Text = "Trading Date";
myPane.YAxis.Title.Text = "Diamond Price";
// First day is feb 1st
//new XDate(2006, 2, 1);

        }
        double open = paramopen;// paramhigh;
        double close = paramclose;// + rand.NextDouble() * 10.0 - 5.0;
        double hi = paramhigh; //Math.Max(open, close) + rand.NextDouble() * 5.0;
        double low = paramlow; //Math.Min(open, close) - rand.NextDouble() * 5.0;

        StockPt pt = new StockPt(x, hi, low, open, close, 100000, hi.ToString());
        spl.Add(pt);

        open = close;
        // Advance one day
        xDate.AddMinutes(1);
        // but skip the weekends
        if (XDate.XLDateToDayOfWeek(xDate.XLDate) == 6)
            xDate.AddDays(2.0);
        //}

        //CandleStickItem myCurve = myPane.AddCandleStick( "trades", spl, Color.Black );
        JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick("", spl);
        if (j == 1)
        {

            myPane.XAxis.MajorGrid.DashOff = 2;                          // sets the Dash in the X axis
            myPane.XAxis.MajorGrid.IsVisible = true;                     // sets grid in the X axis 
            myPane.XAxis.Scale.FontSpec.Angle = 0;                       // sets the angle in the X axis

            myPane.YAxis.MajorGrid.DashOff = 2;                          // sets the Dash in the X axis
            myPane.YAxis.MajorGrid.IsVisible = true;                     // sets grid in the X axis

            myCurve.Stick.IsAutoSize = false;
            myCurve.Stick.Color = Color.Blue;

            // Use DateAsOrdinal to skip weekend gaps
            myPane.XAxis.Type = AxisType.DateAsOrdinal;

            // pretty it up a little
            myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);
            myPane.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45.0f);

            // Tell ZedGraph to calculate the axis ranges
            zg1.AxisChange();
            zg1.Invalidate();
            j = 2;
        }
    }
 

Last edit: ashish kumar 2018-07-13