ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  TextBox ambiguous symbol in chartdir.h
Posted by Nicole on Mar-13-2012 17:36
Hi,

I tried compiling my code with chartdir, however, I got hundreds of errors stating that:

C:\\chartdir_cpp_win32\\ChartDirector\\include\\chartdir.h(731) : error C2872: 'TextBox' :
ambiguous symbol
1>        could be 'C:\\chartdir_cpp_win32\\ChartDirector\\include\\chartdir.h(697) : TextBox'
1>        or       'c:\\windows\\microsoft.net\\framework\\v2.0.50727\\system.windows.forms.dll
: System::Windows::Forms::TextBox'

I already added the path of the header files and library files in the VC++ directories. I have
also placed the chartdir dll in the same path as my executable program. Did I miss some
steps?


Thank you very much! Any help would be greatly appreciated!

  Re: TextBox ambiguous symbol in chartdir.h
Posted by Nicole on Mar-14-2012 00:04
Hi,

To add to my previous post, my program is a Win32 console application with a Windows
Form, that's why my program has CLR support. I read here
http://www.chartdir.com/forum/download_thread.php?
bn=chartdir_support&pattern=&thread=1169116346

that ChartDirector for C++ is designed to standard C++. For managed C++, ChartDirector for
.NET must be used instead. However, my code is not managed C++ but I'm getting pretty
much the same error.

Any ideas how to solve this?


Thank you very much!

  Re: TextBox ambiguous symbol in chartdir.h
Posted by Peter Kwan on Mar-14-2012 03:22
Hi Nicole,

Your code is probably C++/CLI (without using C++/CLI it would not be possible to access CLR). C++/CLI is just a new name for Managed C++. (Since VS 2005, Microsoft has change the name from Managed C++ to C++/CLI.) Like Managed C++, C++/CLI is not the same language as standard C++. For example, in standard C++, a text string is either "char *" or "std::string". In C++/CLI, if you need to interact with CLR, you would need to use "String ^". If you use a standard C++ library in C++/CLI, you may need additional code to convert between standard C++ data types and .NET data types. That's why we suggest people to use ChartDirector for .NET in a C++/CLI project.

Anyway, you can also use ChartDirector for C++ in a C++/CLI project. The issue you encountered is because ChartDirector has a class called "TextBox", and the .NET framework has a class called "System::Windows::Forms::TextBox", and your code has a line "using namespace System::Windows::Forms".  The "using namespace System::Windows::Forms" allows you to use the short form TextBox instead of the full name "System::Windows::Forms::TextBox". Later, when the compiler process the "chartdir.h" file, it sees TextBox inside (which we use to refer to the ChartDirector TextBox). But the compiler is confused if it is referring to the ChartDirector TextBox or the .NET System::Windows::Forms::TextBox. Hence the ambiguous symbol error message.

To solve the problem, you may remove the line "using namespace System::Windows::Forms". After that, if you are refering to a .NET TextBox (or any other class in that namespace), you would need to use the full name "System::Windows::Forms::TextBox". Alternatively, you may try to put the "chartdir.h" before "using namespace System::Windows::Forms". In this way, when the compiler processes the "chartdir.h", the "using namespace" is still not in effect and there would be no confusion.

Hope this can help.

Regards
Peter Kwan

  Re: TextBox ambiguous symbol in chartdir.h
Posted by Nicole on Mar-15-2012 00:24
Attachments:
Hi Peter,

Thank you for your response. I'm now able to run my program successfully. However, I'm
trying to create a simple line chart but the line does not appear. My code is as follows:

void Graph::createGraph(double* data, double* data2, int size){
XYChart *c = new XYChart(250, 250);
c->setPlotArea(30, 20, 350, 200, -1, -1, Chart::Transparent, Chart::Transparent,
Chart::Transparent);

c->xAxis()->setColors(Chart::Transparent, Chart::Transparent);
c->yAxis()->setColors(Chart::Transparent);
c->yAxis()->setLinearScale(-1, 1, 1);
c->yAxis()->addMark(0, 0x000000, "0");

c->addLineLayer(DoubleArray(data, sizeof(data)/sizeof(data[0])));
c->addLineLayer(DoubleArray(data2, sizeof(data2)/sizeof(data2[0])));

// Output the chart
    c->makeChart("graph.bmp");

//free up resources
    delete c;
}

I repeatedly call this function every second and every time the arrays data and data2
increases by 1. graph.bmp is attached below. Any ideas why the line does
not appear? Many thanks!
graph.bmp
graph.bmp

61.59 Kb

  Re: TextBox ambiguous symbol in chartdir.h
Posted by Peter Kwan on Mar-15-2012 23:52
Hi Nicole,

It is because your code always pass just 0 or 1 data point to ChartDirector, so there is no line. (You need at least 2 points to draw a line.)

In the DoubleArray function, the second argument is the number of data points. In the sample code, we use sizeof(data)/sizeof(data[0])), which is the number of data points, assuming "data" is an array. In your case, "data" is not an array. It is a pointer to double. So sizeof(data)/sizeof(data[0])) is not the number of data points. It is likely to be always equal to 0 in 32-bit machine, or 1 in 64-bit machines.

Instead of using DoubleArray(data, sizeof(data)/sizeof(data[0])), please use DoubleArray(data, size). (I assume the "size" parameter in your code refers to the number of data points.

Hope this can help.

Regards
Peter Kwan

  Re: TextBox ambiguous symbol in chartdir.h
Posted by Nicole on Mar-16-2012 00:18
Hi Peter,

Thank you for your reply. Yes, size is the number of data points and I used
DoubleArray(data, size). However, the graph still yields no line. I debugged my program and
even if the size is more than 1, no line was still produced.

I'm confused as to why is this so? Thanks!

  Re: TextBox ambiguous symbol in chartdir.h
Posted by Nicole on Mar-16-2012 00:45
Hi Peter,

I changed size into sizeof(data) and the lines have appeared. Many thanks!

  Re: TextBox ambiguous symbol in chartdir.h
Posted by nicole on Apr-16-2012 19:53
Attachments:
Hi Peter,

I have another issue. The graph that I'm getting is weird and it's not changing even if my
data has already changed. For instance, my data for the red line is:
-0.0088849043720395371
-0.043786772227572379
-0.015817622179468971
-0.0020933454514215355
-0.0024853477637182819
               :
               :

For the green line is: 0.11234950377605199
0.11260215324992726
0.19310948173193851
0.26661353478174643
0.23364427856551370
               :
               :
But my graph is always like the picture I've uploaded. My code is the same as the one I
posted earlier in this thread. Instead of using arrays, I'm passing vectors to this function
and thus the DoubleArray function receives the pointer to the array as shown below:

void Graph::createGraph(double* data, double* data2, int size){
....
c->addLineLayer(DoubleArray(data, sizeof(data)));
c->addLineLayer(DoubleArray(data2, sizeof(data)));
....
}

If I use size (the size of the vector), I get no line at all. Any ideas?

Thank you very much!
graph.bmp
graph.bmp

43.93 Kb

  Re: TextBox ambiguous symbol in chartdir.h
Posted by Peter Kwan on Apr-17-2012 03:47
Hi nicole,

In your code, the sizeof(data) is not correct.

According to C++ standard, the sizeof(data) means the size of "data" in bytes. In your case, data is a pointer to double. In 32-bit machine, the size of a pointer is 4 bytes. In 64-bit machine, the size of a pointer is 8 bytes. In any case, it is a constant, and is not the size of your array.

Because your code uses a size that is completely unrelated to the size of your array, and is a constant, so it is possible your chart will not change.

To solve the problem, please use the size of your array instead.

In your createGraph subroutine, you have an argument called "size". As you have not shown how "size" is obtained, I can determined if "size" is the size of your array, or some other things. If you think the "size" is the size of the array, you may check using the following method:

char temp[1024];
sprintf(temp, "Size = %d, First = %d, Last = %d", size, data2[0], data2[size - 1]);
c->addTitle(temp, "arial.ttf", 8);

With the above code, you can see the "size" variable in your chart, as well as the first and the last data point. You can then determine if the "size" is really the size of your array.

If the above still does not solve the problem, would you mind to attach a chart with the above "addTitle" line to help me diagnose the problem?

Regards
Peter Kwan

  Re: TextBox ambiguous symbol in chartdir.h
Posted by nicole on Apr-17-2012 10:55
Attachments:
Hi Peter,

Thanks for your reply. The size being passed as parameter is the size of the vector. The
code for calling the create graph function is where svr.faceArousal and svr.faceValence
are vectors :

graph.createGraph(&svr.faceArousal[0], &svr.faceValence[0], svr.faceArousal.size());

I think you're right, size should be used instead of sizeof(data), there were no lines being
created because the image is not being overwritten so the size is always 1.

Moreover, as you suggested, I also tried adding the title, but the contents of the data is
weird as shown in the attached image.

        for(int i=0; i<size; i++)
    printf("array = %f %f\\n", data[i], data2[i]);

c->addLineLayer(DoubleArray(data, size));
c->addLineLayer(DoubleArray(data2, size));

char temp[1024];
sprintf(temp, "Size = %d, First = %d, Last = %d", size, data[0], data[size - 1]);
c->addTitle(temp, "arial.ttf", 8);
// Output the chart
        c->makeChart("graph.bmp");

As seen from the code, I'm printing the contents of the array and all its contents are
correct but in the image generated, it's not the same anymore.

Also, the graph I'm getting is not changing because it's not getting overwritten. Any
ideas why this is so?

Thank you so much for your help!
graph.bmp
graph.bmp

43.81 Kb

  Re: TextBox ambiguous symbol in chartdir.h
Posted by nicole on Apr-17-2012 11:02
Attachments:
Hi again,

My bad. The contents in the title is weird because my data is a double. The contents are
correct now as show in the image attached. The only problem is the image is not getting
overwritten in the subsequent iterations; thus, the same graph is shown all the time.


THanks!
graph.bmp
graph.bmp

43.81 Kb

  Re: TextBox ambiguous symbol in chartdir.h
Posted by Peter Kwan on Apr-17-2012 23:26
Hi nicole,

Are you creating a new XYChart object for the updated chart, or are your code simply adding more and more layers to the same XYChart? In ChartDirector, if you have outputted the chart, it cannot accept any more data. You would need to create a new XYChart object if you would like to modify the data.

To check if the chart has in fact been updated, you may use the following code:

sprintf(temp, "Time = %d", time());
c->addText(0, 15, temp, "arial.ttf", 8);
sprintf(temp, "graph%d.bmp", time());
c->makeChart(temp);

The above code includes a timestamp in your chart, and it also creates uses a unique file name each time. This can help to check if new images are created (you should see many "graphxxxxxxx.bmp" files). This can also help to determine if a new chart object is created each time, or if you are outputing the same chart more than once. If you are outputting the same chart more than once, each time there will be an additional c->addText with different timestamps, and you should be multiple timestamps overlapped in the same place, probably resulting in an unreadable timestamp.

Please let me know what is the result.

Regards
Peter Kwan

  Re: TextBox ambiguous symbol in chartdir.h
Posted by nicole on Apr-18-2012 18:18
Attachments:
Hi Peter,

I'm creating a new XYChart object everytime the function is called. My complete code is
as follows:


void Graph::createGraph(double* data, double* data2, int size){


XYChart *c = new XYChart(280, 160);
// Set the plotarea at (30, 20) and of size 200 x 200 pixels
c->setPlotArea(30, 20, 280, 120, -1, -1, Chart::Transparent, Chart::Transparent,
Chart::Transparent);

c->xAxis()->setColors(Chart::Transparent, Chart::Transparent);
c->yAxis()->setColors(Chart::Transparent);
c->yAxis()->setLinearScale(-1, 1, 1);
c->yAxis()->addMark(0, 0x000000, "0");

for(int i=0; i<size; i++)
printf("array = %f %f\\n", data[i], data2[i]);

        c->addLineLayer(DoubleArray(data, size));
c->addLineLayer(DoubleArray(data2, size));

char temp[1024];
sprintf(temp, "Time = %d", time(NULL));
c->addText(0, 15, temp, "arial.ttf", 8);
sprintf(temp, "graph%d.bmp", time(NULL));

// Output the chart
        c->makeChart(temp);

        //free up resources
        delete c;

}

I tried the code you suggested, and it generated various images with the correct graph
as attached below. Does this mean that I can't have the same file name everytime I call
this function? Because before my code is just c->makeChart("graph.bmp"); resulting to
no images being generated after the first run?

Thank you very much!
graph1334743915.bmp
graph1334743915.bmp

43.81 Kb
graph1334743918.bmp
graph1334743918.bmp

43.90 Kb
graph1334743922.bmp
graph1334743922.bmp

43.97 Kb
graph1334743926.bmp
graph1334743926.bmp

43.98 Kb
graph1334743931.bmp
graph1334743931.bmp

43.99 Kb

  Re: TextBox ambiguous symbol in chartdir.h
Posted by Peter Kwan on Apr-19-2012 00:21
Hi nicole,

In your case, it looks like a file sharing issue. I suspect after ChartDirector creates the chart "graph.bmp", you have another program or another part of your code that uses the file "graph.bmp". This other program or code "locked" the file. (You probably know that a file may not be modified if another program or code is accessing the file. Just opening the image file to see it may already locked the file, depending on which program you use to open the file.) Another possibility is that your program somehow has the access right to create a new file, but not to modify an existing file.

To diagnose or solve the problem. you may try the followings:

(a) Please writing a line of code to delete the file first (eg. use the standard C function "remove"), and double check for error return and if the file is really deleted, before asking ChartDirector to create the file again. If you cannot even delete the file, the file may be "locked" by some other code, or there may be security issue.

(b) Alternatively, you can create a file with a new file name every time, and at the same delete the previous file (so that any time, there is only one image file in your hard disk).

(c) Instead of using makeChart, you may use standard C functions to create the file, like:

//output chart in memory
MemBlock b = c->makeChart(Chart::BMP);

//save the output as a file
FILE *f = fopen("graph.bmp", "wb");
fwrite(b.data, b.len, 1, f);
fclose(f);

With the above code, the file is created with your own code, which is standard C. You can than trace your code to determine why the file "graph.bmp" cannot be overwritten.

Regards
Peter Kwan

  Re: TextBox ambiguous symbol in chartdir.h
Posted by nicole on Apr-20-2012 19:21
Hi Peter,

It appears that my program really is locking the files; thus, it cannot be overwritten.
Creating new files solved my problem, however, I still cannot delete the previous ones
created.

Anyways, thank you very much for your time and help! Really appreciate it!