1

我已成功使用 C++ 示例项目从我的 C++ 项目中使用 ZedGraph 绘制图形。但是,没有 C++ 的日期轴示例。

以下代码取自 http://zedgraph.org/wiki/index.php?title=Tutorial:Date_Axis_Chart_Demo中的 C# 示例。请查看我对文本的评论 //JEM// 以了解我的问题出在哪里

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

        >  //JEM //This line above doesn't 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 doesn't work even if I change it to the
    //syntax that C++ understands, that is,
    myPane->XAxis->Type = AxisType->Date;
4

2 回答 2

0

也许 C++ 对匿名变量有一些问题?
尝试先创建一个XDate对象,然后再将其转换为双精度。

XDate date = new XDate( 1995, 5, i+11 );
double x = (double)date;
于 2010-10-17T15:21:01.003 回答
0

谢谢加塞克。这就是它最终下降的方式。你的回答是转折点!!!

    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;

这是来自 sourceforge dot net documentation/html/M_ZedGraph_XDate__ctor_3.htm 的 C++ 的 Xdate 类型的构造函数。XDate (int year, int month, int day, int hour, int minute, double second)

我还在此链接http://www.c-plusplus.de/forum/viewtopic-var-t-is-186422-and-view-is-next.html上找到了一个详细示例, 代码如下

        /// 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;
于 2010-10-23T17:48:31.803 回答