如何使用 C++ 绘制带有日期轴的图表和 ZedGraph?

发布于 2024-09-28 11:53:52 字数 881 浏览 3 评论 0原文

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

以下代码取自以下位置的 C# 示例: http://zedgraph.org/wiki/index.php?title=教程:Date_Axis_Chart_Demo 。请参阅我的评论以及文本 //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;

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 at
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 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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

拒绝两难 2024-10-05 11:53:52

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

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

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;
江南月 2024-10-05 11:53:52

谢谢加塞克。
就这样最后就这样下去了。你的回答是转折点!

    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 (intyear,intmonth,intday,inthour,intmin,doublesecond)

我还在此链接上找到了详细的示例 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;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文