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):
#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";
return -1;
}
CreateGraph(fileName);
return 0;
}
void CreateGraph(String^ fileName)
{
RectangleF rect = RectangleF( 0, 0, 640, 480 );
GraphPane ^myPane = gcnew GraphPane( rect, "Überschrift", "X Titel", "Y Titel" );
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";
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 );
}
LineItem ^myCurve = myPane->AddCurve( L"Eins",
list, Color::Red, SymbolType::Diamond );
myCurve->Symbol->Fill = gcnew Fill( Color::White );
myCurve = myPane->AddCurve( L"Zwei",
list2, Color::Blue, SymbolType::Circle );
myCurve->Symbol->Fill = gcnew Fill( Color::White );
myCurve->IsY2Axis = true;
myPane->XAxis->MajorGrid->IsVisible = true;
myPane->YAxis->Scale->FontSpec->FontColor = Color::Red;
myPane->YAxis->Title->FontSpec->FontColor = Color::Red;
myPane->YAxis->MajorTic->IsOpposite = false;
myPane->YAxis->MinorTic->IsOpposite = false;
myPane->YAxis->MajorGrid->IsZeroLine = false;
myPane->YAxis->Scale->Align = AlignP::Inside;
myPane->YAxis->Scale->Min = -30;
myPane->YAxis->Scale->Max = 30;
myPane->Y2Axis->IsVisible = true;
myPane->Y2Axis->Scale->FontSpec->FontColor = Color::Blue;
myPane->Y2Axis->Title->FontSpec->FontColor = Color::Blue;
myPane->Y2Axis->MajorTic->IsOpposite = false;
myPane->Y2Axis->MinorTic->IsOpposite = false;
myPane->Y2Axis->MajorGrid->IsVisible = true;
myPane->Y2Axis->Scale->Align = AlignP::Inside;
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 );
Image^ img = myPane->GetImage();
img->Save(fileName, ImageFormat::Png);
}
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