|
Can I use .NET for VC++ .NET |
Posted by Anon on Feb-18-2010 20:07 |
|
Can I use the ChartDirector .NET version for VC++ .NET?
Any help is appreciated. |
Re: Can I use .NET for VC++ .NET |
Posted by Peter Kwan on Feb-19-2010 02:18 |
|
Hi Anon,
I am not absolutely sure the VC++ .NET you are referring to.
Microsoft Visual Studio currently supports many programming languages, like VB.NET/VB2005/VB2008, C#, C++, C++/CLI, .....
There are two languages that contains "C++" in its name. One is just called "C++". It is the standard C++. The C++ programming language is often used to write MFC programs. The other is called "C++/CLI". It is a Microsoft proprietary language that looks like C++, but is not compatible with C++. The "C++/CLI" is often used to write programs that uses the .NET framework.
If you are using standard C++, you should use "ChartDirector for C++". If you are using "C++/CLI", you should use "ChartDirector for .NET". "ChartDirector for .NET" is compatible with all CLI compliant languages, including "C++/CLI".
Hope this can help.
Regards
Peter Kwan |
Re: Can I use .NET for VC++ .NET |
Posted by Anon on Feb-19-2010 13:31 |
|
Hi Peter,
Thanks for the details.
I am using C++/CLI. Where can I find the examples/samples to use the chartdirector?
In the ChartDirector .Net help documentation, there is no samples for C++/CLI.
Thanks and Regards,
Anon |
Re: Can I use .NET for VC++ .NET |
Posted by Peter Kwan on Feb-19-2010 16:37 |
|
Hi Anon,
ChartDirector for .NET works for all CLI compliant language, including CLI/C++. However, as there are many CLI compliant languages (Microsoft has 6 CLI langauges, and there are dozens more from other parties), it is not practical for us to provide sample code for all possible CLI languages.
Anyway, provided you are familiar with CLI/C++, it is easy to port the sample code to CLI/C++ from C# code. For example, in the ChartDirectr documentation "The First Windows Forms Project from Scratch", there is a Windows Forms example in C#:
====== Start C# Code ======
//The data for the bar chart
double[] data = {85, 156, 179.5, 211, 123};
//The labels for the bar chart
string[] labels = {"Mon", "Tue", "Wed", "Thu", "Fri"};
//Create a XYChart object of size 250 x 250 pixels
XYChart c = new XYChart(250, 250);
//Set the plotarea at (30, 20) and of size 200 x 200 pixels
c.setPlotArea(30, 20, 200, 200);
//Add a bar chart layer using the given data
c.addBarLayer(data);
//Set the x axis labels using the given labels
c.xAxis().setLabels(labels);
//output the chart
winChartViewer1.Image = c.makeImage();
//include tool tip for the chart
winChartViewer1.ImageMap = c.getHTMLImageMap("clickable", "",
"title='{xLabel}: US${value}K'");
======= End C# Code =======
The same code in C++/CLI is:
====== Start C++/CLI Code ======
// The data for the bar chart
array<double> ^data = {85, 156, 179.5, 211, 123};
// The labels for the bar chart
array<String^> ^labels = {"Mon", "Tue", "Wed", "Thu", "Fri"};
// Create a XYChart object of size 250 x 250 pixels
XYChart ^c = gcnew XYChart(250, 250);
// Set the plotarea at (30, 20) and of size 200 x 200 pixels
c->setPlotArea(30, 20, 200, 200);
// Add a bar chart layer using the given data
c->addBarLayer(data);
// Set the labels on the x axis.
c->xAxis()->setLabels(labels);
// Output the chart
winChartViewer1->Image = c->makeImage();
//include tool tip for the chart
winChartViewer1->ImageMap = c->getHTMLImageMap("clickable", "",
"title='{xLabel}: US${value}K'");
======= EndC++/CLI Code =======
You can see the code is identical except a simple change in syntax. The syntax change is not specific to ChartDirector and is just general syntax change. For example, in C#, one uses "XYChart c = new XYChart(...);", while in C++ one use "XYChart ^c = gcnew XYChart(...);".
One important thing you need to note when C++/CLI in Visual Studio is that the Visual Studio may automatically reference multiple versions of the same system assembly, resulting in compilation error. (Again this is not specific to ChartDirector, but is the general method to configure Visual Studio.) You may need to delete the duplicated references automatically added by Visual Studio.
For example, ChartDirector is designed to work with all .NET versions (1.x, 2.x and 3.x). But the "netchartdir.dll" manifest must include references to a specific .NET version (this is required by .NET). So the version that is referenced in the manifest is .NET 1.0 (as it is compatible can also be used in .NET 2.x and .NET 3.x).
When creataing a C++/CLI with Visual Studio for a project that uses .NET 2.x or .NET 3.x, Visual Studio may add system references for both .NET 1.0 (as it is referenced in the ChartDirector "netchartdir.dll" manifest) and .NET 2.x or .NET 3.x. For example, there may be two "System" namespaces with duplicated symbols, one from .NET 1.x, and one from .NET 2.x or .NET 3.x. This results in compilation error. To solve the problem, you would need to select Project/Reference, and manually delete the .NET 1.0 references. (You will see two "System" references, two "System.Data" references, etc. Delete the one that is from .NET 1.x.)
Hope this can help.
Regards
Peter Kwan |
Re: Can I use .NET for VC++ .NET |
Posted by Anon on Feb-19-2010 17:05 |
|
Hi Peter,
Thanks for providing me the example and the detailed explanation.
Thanks & Regards,
Chitra |
|