如何在可视C ++控制台应用程序中使用zedgraph.dll? [英] how to use zedgraph.dll in a visual c++ console application?

查看:121
本文介绍了如何在可视C ++控制台应用程序中使用zedgraph.dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我使用Visual Studio,Visual C ++ 6和Visual C ++ 2008进行即时编程,这是一个计算数学方程式的控制台应用程序,我想用zedgraph.dll绘制响应,但我做不到.

如何在控制台项目的Visual C ++ 2008中使用zedgraph.dll(绘制图形功能的dll)?我无法将这些dll加载为参考.

在devloper的Wiki中,有一个控制台示例,但它在C#中,并且它们使用简单的添加引用"来添加控制台.和c ++没有这个功能,您能帮我吗?

解决方案

Vielen Dank!好的,谢谢,但是我已经在VS C ++ 2008中创建了一个控制台应用程序项目,然后单击project-> Properties ...--> Framework and reference.并且有:

具有按钮添加新引用..."的框
具有添加路径..."和删除路径"文本的按钮.

如果单击第一个,则只有一个对话框,显示项目",其他都没有.

如果单击添加路径...",则会出现一个对话框,显示添加参考搜索路径"和浏览"按钮.

这仅对于-win32控制台应用程序是一个问题,因为我已经使用-CLR控制台应用程序完成了您的解决方案,并且效果很好!

非常感谢!


构建VS 2008 C ++控制台应用程序确实非常简单.创建一个控制台应用程序项目.在项目属性对话框中,选择公共属性",然后选择框架和参考".您将必须添加System.Drawing,System.Data和ZedGraph.前两个是从".NET"寄存器中添加的.对于最后一个,您必须更改为浏览"寄存器,并同时添加您的ZedGraph dll.

这是进入应用程序主要功能所在文件的源代码(此代码替换了主要文件中的所有内容):

 //  ConsoleZedGraph.cpp:主项目文件.

#include " 

使用 命名空间系统;
使用 命名空间 System :: Collections;
使用 命名空间 System :: Data;
使用 命名空间 System :: Drawing;
使用 命名空间 System :: Drawing :: Imaging;
使用 命名空间 ZedGraph;

 void  CreateGraph(String ^ fileName);

 int  main(array< System ::  String  ^> ^ args)
{
    字符串^ fileName;
    如果(长度>   0 )
    {
        fileName = args [ 0 ];
    }
    其他
    {
        fileName = " ;
        // 控制台:: WriteLine(您必须提供图形文件名!"); 
        返回 -1;
    }
    CreateGraph(fileName);
    返回  0 ;
}

无效 CreateGraph(String ^ fileName)
{
    // 创建GraphPane实际上就是您要做的
    // 在控制台应用程序中使用ZedGraph时
    RectangleF rect = RectangleF( 0  0  640  480 );
    GraphPane ^ myPane = gcnew GraphPane(rect," " " );

    // 设置标题和轴标签
    myPane-> Title-> Text = L " ;
    myPane-> XAxis->标题->文本= L " ;
    myPane-> YAxis->标题->文本= L " ;
    myPane-> Y2Axis->标题->文本= L " ;

    // 基于Sine函数组成一些数据点
    PointPairList ^ list = gcnew PointPairList();
    PointPairList ^ list2 = gcnew PointPairList();
     for ( int  i =  0 ; i <   36 ; i ++)
    {
         double  x =( double )i *  5 . 0 ;
         double  y = Math :: Sin(( double )i * Math :: PI/ 15 . 0 )*  16 . double  y2 = y *  13 . 5  ;
        list-> Add(x,y);
        list2-> Add(x,y2);
    }

    // 生成带有菱形符号的红色曲线,并在图例中显示"Alpha" 
    LineItem ^ myCurve = myPane-> AddCurve(L " ,
        列表,颜色::红色,符号类型::钻石);
    // 用白色填充符号
    myCurve-> Symbol-> Fill = gcnew Fill(Color :: White);

    // 生成带有圆形符号的蓝色曲线,并在图例中显示"Beta" 
    myCurve = myPane-> AddCurve(L " ,
        list2,Color :: Blue,SymbolType :: Circle);
    // 用白色填充符号
    myCurve-> Symbol-> Fill = gcnew Fill(Color :: White);
    // 将此曲线与Y2轴相关联
    myCurve-> IsY2Axis =  true ;

    // 显示x轴网格
    myPane-> XAxis-> MajorGrid-> IsVisible =  true ;

    // 将Y轴缩放为红色
    myPane-> YAxis-> Scale-> FontSpec-> FontColor = Color :: Red;
    myPane-> YAxis-> Title-> FontSpec-> FontColor = Color :: Red;
    // 关闭相反的线,以使Y线不会出现在Y2轴上
    myPane-> YAxis-> MajorTic-> IsOpposite =  false ;
    myPane-> YAxis-> MinorTic-> IsOpposite =  false ;
    // 不显示Y零线
    myPane-> YAxis-> MajorGrid-> IsZeroLine =  false ;
    // 对齐Y轴标签,使它们与该轴齐平
    myPane-> YAxis-> Scale-> Align = AlignP :: Inside;
    // 手动设置轴范围
    myPane-> YAxis-> Scale-> Min = -30;
    myPane-> YAxis-> Scale-> Max =  30 ;

    // 启用Y2轴显示
    myPane-> Y2Axis-> IsVisible =  true ;
    // 将Y2轴缩放为蓝色
    myPane-> Y2Axis-> Scale-> FontSpec-> FontColor = Color :: Blue;
    myPane-> Y2Axis-> Title-> FontSpec-> FontColor = Color :: Blue;
    // 关闭相反的抽签,以使Y2抽签不会显示在Y轴上
    myPane-> Y2Axis-> MajorTic-> IsOpposite =  false ;
    myPane-> Y2Axis-> MinorTic-> IsOpposite =  false ;
    // 显示Y2轴网格线
    myPane-> Y2Axis-> MajorGrid-> IsVisible =  true ;
    // 对齐Y2轴标签,使其与轴齐平
    myPane-> Y2Axis-> Scale-> Align = AlignP :: Inside;

    // 用渐变填充轴背景
    myPane->图表->填充= gcnew Fill(Color :: White,Color :: LightGray, 45  .0f);

    位图^ bm = gcnew位图( 1  1 );
    Graphics ^ g = Graphics :: FromImage(bm);
    myPane-> AxisChange(g);
    // 检索图像
    图片^ img = myPane-> GetImage();
    // 将图片另存为PNG 
    img-> Save(fileName,ImageFormat :: Png); // ,ImageFormat :: Bmp); 
} 



给出了winforms C ++应用程序的源代码以及ZedGraph网站上的说明,提出此解决方案并不是什么大问题.

享受! :cool:

曼弗雷德(Manfred)


Hello, im programming with visual studio, visual c++ 6 and visual c++ 2008 a console aplication that compute mathematical equations and I want to plot the response with zedgraph.dll, but i can`t to do it.

How can I to use zedgraph.dll (a dll that plot graphic functions) in visual c++ 2008 in a console project? I can´t load these dll how a reference.

In the wiki from devloper there is an example of a console but it is in C# and they use the easy "add reference" and c++ doe´snt have this, can you help me?

解决方案

Vielen Dank! Aufwiederschreiben.


Ok thank you, but I have created a console application project in VS C++ 2008, and then click project-->Properties...-->Framework and references. And there are:

A box with a button "Add New Reference..."
Buttons with "Add Path..." and "Remove Path" text.

If I click the first there is only a dialog that says "Projects" and nothing else.

If I click "Add Path..." appears a dialog that says "add reference search path" and a "Browse" button.

This is a problem only with a -win32 console application- because I have done your solution with -CLR console application- and it works great!

Thank you very much!


Building a VS 2008 C++ console application is really quite straight forward. Create a console application project. In the project properties dialog select "Common Properties" and then "Framework and References". You''ll have to add System.Drawing, System.Data, and ZedGraph. The first two are added from the ".NET" register. For the last one you''ll have to change to the "Browse" register and add your ZedGraph dll also.

Here is the source code that goes into the file where your applications main function was (this code replaces everything in the main file):

// ConsoleZedGraph.cpp : main project file.

#include "stdafx.h"

using namespace System;
using namespace System::Collections;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Drawing::Imaging;
using namespace ZedGraph;

void CreateGraph(String^ fileName);

int main(array<System::String ^> ^args)
{
    String^ fileName;
    if(args->Length > 0)
    {
        fileName = args[0];
    }
    else
    {
        fileName = "C:\\temp\\TestGraph.png";
        //Console::WriteLine("You have to supply a filename for your graph!");
        return -1;
    }
    CreateGraph(fileName);
    return 0;
}

void CreateGraph(String^ fileName)
{
    // Create a GraphPane is really all you have to do
    // when using ZedGraph in a console application
    RectangleF rect = RectangleF( 0, 0, 640, 480 );
    GraphPane ^myPane = gcnew GraphPane( rect, "Überschrift", "X Titel", "Y Titel" );

    // Set the titles and axis labels
    myPane->Title->Text = L"Zwei Kurven in einem Graphen";
    myPane->XAxis->Title->Text = L"Zeit, Tage";
    myPane->YAxis->Title->Text = L"Wert A";
    myPane->Y2Axis->Title->Text = L"Wert B";

    // Make up some data points based on the Sine function
    PointPairList ^list = gcnew PointPairList();
    PointPairList ^list2 = gcnew PointPairList();
    for ( int i = 0; i < 36; i++ )
    {
        double x = (double)i * 5.0;
        double y = Math::Sin( (double)i * Math::PI / 15.0 ) * 16.0;
        double y2 = y * 13.5;
        list->Add( x, y );
        list2->Add( x, y2 );
    }

    // Generate a red curve with diamond symbols, and "Alpha" in the legend
    LineItem ^myCurve = myPane->AddCurve( L"Eins",
        list, Color::Red, SymbolType::Diamond );
    // Fill the symbols with white
    myCurve->Symbol->Fill = gcnew Fill( Color::White );

    // Generate a blue curve with circle symbols, and "Beta" in the legend
    myCurve = myPane->AddCurve( L"Zwei",
        list2, Color::Blue, SymbolType::Circle );
    // Fill the symbols with white
    myCurve->Symbol->Fill = gcnew Fill( Color::White );
    // Associate this curve with the Y2 axis
    myCurve->IsY2Axis = true;

    // Show the x axis grid
    myPane->XAxis->MajorGrid->IsVisible = true;

    // Make the Y axis scale red
    myPane->YAxis->Scale->FontSpec->FontColor = Color::Red;
    myPane->YAxis->Title->FontSpec->FontColor = Color::Red;
    // turn off the opposite tics so the Y tics don't show up on the Y2 axis
    myPane->YAxis->MajorTic->IsOpposite = false;
    myPane->YAxis->MinorTic->IsOpposite = false;
    // Don't display the Y zero line
    myPane->YAxis->MajorGrid->IsZeroLine = false;
    // Align the Y axis labels so they are flush to the axis
    myPane->YAxis->Scale->Align = AlignP::Inside;
    // Manually set the axis range
    myPane->YAxis->Scale->Min = -30;
    myPane->YAxis->Scale->Max = 30;

    // Enable the Y2 axis display
    myPane->Y2Axis->IsVisible = true;
    // Make the Y2 axis scale blue
    myPane->Y2Axis->Scale->FontSpec->FontColor = Color::Blue;
    myPane->Y2Axis->Title->FontSpec->FontColor = Color::Blue;
    // turn off the opposite tics so the Y2 tics don't show up on the Y axis
    myPane->Y2Axis->MajorTic->IsOpposite = false;
    myPane->Y2Axis->MinorTic->IsOpposite = false;
    // Display the Y2 axis grid lines
    myPane->Y2Axis->MajorGrid->IsVisible = true;
    // Align the Y2 axis labels so they are flush to the axis
    myPane->Y2Axis->Scale->Align = AlignP::Inside;

    // Fill the axis background with a gradient
    myPane->Chart->Fill = gcnew Fill( Color::White, Color::LightGray, 45.0f );

    Bitmap^ bm = gcnew Bitmap( 1, 1 );
    Graphics^ g = Graphics::FromImage( bm );
    myPane->AxisChange( g );
    // Retrieve the image
    Image^ img = myPane->GetImage();
    // Save image as PNG
    img->Save(fileName, ImageFormat::Png);//, ImageFormat::Bmp);
}



Given the source code for the winforms C++ application and the instructions on the ZedGraph website it wasn''t to big a problem to come up with this solution.

Enjoy! :cool:

Manfred


这篇关于如何在可视C ++控制台应用程序中使用zedgraph.dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆