2010-10-17 113 views
1

我已经成功地使用C++示例项目来使用ZedGraph从我的C++项目中绘制图形。然而,C++的Date轴没有例子。如何使用C++和ZedGraph绘制日期轴的图形?

以下代码取自在 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; 
+0

那你就带一堆C#代码,试图改变周围的符号,并使其工作?这是不可能发生的。你需要得到一个真正的C++例子并使用它。 – Puppy 2010-10-17 15:14:04

+0

它看起来像ZedGraph只能在托管代码中使用,所以我重新标记为这样。 – 2010-10-17 15:50:19

回答

0

谢谢Gacek。 这是它最终如何下降。你的答案是转折点!

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点网的文件/ HTML/M_ZedGraph_XDate__ctor_3.htm的Xdate类型C++的构造函数。 XDate(INT年,月整型,诠释天,诠释小时,分整型,双秒)

我还发现这个链接的详细例子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; 
+0

太棒了,很高兴我帮了一下。你应该接受我的或你的答案来标记这个问题已解决。 – Gacek 2010-10-27 10:39:22

0

也许C++有一些与匿名变量有关的问题?
尝试在将其转换为double之前先创建一个XDate对象。

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