0

The following code will only display the standard graph, but will not print the axis text nor plot any of the coordinates.

public void JapaneseCandleStick()
{
    //GraphPane myPane = base.GraphPane;

    GraphPane myPane = new GraphPane();

    myPane.Title.Text = "Japanese Candlestick Chart Demo";
    myPane.XAxis.Title.Text = "Trading Date";
    myPane.YAxis.Title.Text = "Share Price, $US";

    StockPointList spl = new StockPointList();
    Random rand = new Random();

    // First day is jan 1st
    XDate xDate = new XDate(2006, 1, 1);
    double open = 50.0;

    for (int i = 0; i < 50; i++)
    {
        double x = xDate.XLDate;
        double close = open + rand.NextDouble() * 10.0 - 5.0;
        double hi = Math.Max(open, close) + rand.NextDouble() * 5.0;
        double low = Math.Min(open, close) - rand.NextDouble() * 5.0;

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

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

    JapaneseCandleStickItem myCurve = myPane.AddJapaneseCandleStick("trades", spl);
    myCurve.Stick.IsAutoSize = true;
    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);

    zedGraphControl1.AxisChange();
    //base.ZedGraphControl.AxisChange();
}

What is wrong with the above and why cannot I see any text or see the plots? It all compiles without errors, hence the referencing and the ZedGraph implementation/referencing seems to be in order.

user247702
  • 23,641
  • 15
  • 110
  • 157
Kishor
  • 29
  • 2

1 Answers1

0

when you create an instance of Graphpane it must be referenced to zedGraphControl1, use the following line of code :

 GraphPane myPane = zedGraphControl1.GraphPane; 

& here's the output:

enter image description here

SanVEE
  • 2,009
  • 5
  • 34
  • 55
  • That works OK. Thanks for your help San. But why does it work only when called from private void Form1_Load(object sender, EventArgs e)? Call from a button or anywhere else in the program & we get nothing? – Kishor Jun 09 '14 at 09:50
  • Not really, it should work with button press events as well. I don't see any reason for not working. create another thread & share your code! – SanVEE Jun 09 '14 at 13:14