Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted

Vielen Dank! Aufwiederschreiben.
 
Share this answer
 
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!
 
Share this answer
 
v2
Comments
Manfred Rudolf Bihy 29-Dec-10 17:39pm    
I'm glad that I could help you and that you finally got it working. I wish you successful coding! :)
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):

C#
// 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
 
Share this answer
 
v2
Comments
Alain Rist 29-Dec-10 2:41am    
The question is tagged C++ so your answer is irrelevant, even if efficient.
Manfred Rudolf Bihy 29-Dec-10 5:08am    
@Alan: My solution is C++, if you would have looked at the code you should have noticed. So WTF are you talking about?
Aescleal 29-Dec-10 7:33am    
Doesn't look like C++ to me either - at least anything that conforms to any C++ standard I've read recently.
Manfred Rudolf Bihy 29-Dec-10 8:17am    
Ok, whatever you say, it's a visual studio C++ console project, it compiles, runs and produces the expected output. Which part doesn't look like C++ if you care to elaborate?
Do I need to zip the Solution and send it to you? I don't have any problem doing that. :)
Aescleal 29-Dec-10 15:40pm    
It doesn't compile with a C++ compiler - the definition of main is non-standard to start with as is all the bollocks with the ^ operator.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900