2010-10-17 115 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;