views:

22

answers:

2

I have successfully used the c++ example project to draw graphs from my c++ project using zedgraph. However there is no example with Date axis for c++.

The following code is taken from the c# example found here http://zedgraph.org/wiki/index.php?title=Tutorial:Date_Axis_Chart_Demo. Please see my comments with the text //JEM// to see where my problem is

  PointPairList list = new PointPairList();
   for ( int i=0; i<36; i++ )
   {
      double x = (double) new XDate( 1995, 5, i+11 );

//JEM//This line above doesnt work in c++

  double y = Math.Sin( (double) i * Math.PI / 15.0 );
  list.Add( x, y );

}

 ....missing code...

// Set the XAxis to date type

myPane.XAxis.Type = AxisType.Date;

//JEM//This one also doesnt work even if i change it to the syntax that c++ understands i.e

myPane->XAxis->Type = AxisType->Date;

Please help

A: 

Maybe C++ has some problems with the anonymous variables?
Try to create a XDate object first before converting it to double.

XDate date = new XDate( 1995, 5, i+11 );
double x = (double)date;
Gacek
A: 

Thanks Gacek. This is how it finally went down. Your answer was the turning point!!!

    for ( int i = 0; i < basin.DY; i++ ){
           XDate dato(1995,9,i,0,0,0); //date
           double x = (double)dato;
            //double x =  i;     
           double y =  basin.Qsim[i];     
           double y2 = basin.Qobs[i];     
            list->Add( x, y );     
            list2->Add( x, y2 );
    }
    //set the XAXis to date type
    myPane->XAxis->Type = AxisType::Date;

here is the constructor for the Xdate type for c++ from sourceforge dot net documentation/html/M_ZedGraph_XDate__ctor_3.htm. XDate (int year, int month, int day, int hour, int minute, double second)

I have also found a detailed example on this link http://www.c-plusplus.de/forum/viewtopic-var-t-is-186422-and-view-is-next.html with the following code

        /// ZedGraph Kurve //////////
private: void CreateGraph( ZedGraphControl ^zgc )
{
   GraphPane ^myPane = zgc->GraphPane;

   // Set the titles and axis labels
   myPane->Title->Text = "Gewichtskurve";
   myPane->XAxis->Title->Text = "Tag";
   myPane->YAxis->Title->Text = "Gewicht in Kg";


   // Make up some data points from the Sine function
    double x,y;
   PointPairList ^list = gcnew PointPairList();
   for ( int i=0; i<36; i++ )
   {
     x = (double) gcnew XDate( 1995, 5, i+11 );
      y = Math::Sin( (double) i * Math::PI / 15.0 );
      list->Add( x, y );
   }

   // Generate a blue curve with circle symbols, and "My Curve 2" in the legend
       LineItem ^myCurve = myPane->AddCurve( "Trainingskurve", list, Color::Blue,
       SymbolType::Circle );

       XDate ^xdatum = gcnew XDate ( 1995, 1, 1);
       xdatum->AddDays ( 1 );

       myPane->XAxis->Type = AxisType::Date;
Jjunju Em
Great, glad I helped a bit. You should either accept mine or yours answer to mark this question as solved.
Gacek