|
MFC put the data from std::vector |
Posted by Robo on Jun-09-2016 02:56 |
|
I'm try puting like this:
// The data for the bar chart
vector <double> vecConstitutive;
double *data = &vecConstitutive[0]; //copy all vector to data
and ChartDirector don't show any chart, when I try declare :
like this :
double data [193];
fcopyToArray(data); // this work
But I don't need declare size of double data.
What you advise me? |
Re: MFC put the data from std::vector |
Posted by Peter Kwan on Jun-09-2016 16:06 |
|
Hi Robo,
You can freely use std::vector or any other method to store your data. It should not matter to ChartDirector.
As I do not know your exact code, it is hard to determine what is the issue, but I can create an example for you:
vector <double> vecConstitutive;
vecConstitutive.push_back(111);
vecConstitutive.push_back(222);
vecConstitutive.push_back(333);
c->addBarLayer(DoubleArray(&(vecConstitutive[0]), vecConstitutive.size()));
You probably are already well aware of the followings, but I adds this just in case:
The code "double *data = &vecConstitutive[0];" do not copy any data. It just obtains a pointer inside the vector, and the pointer can become invalid if your change the vector (such as adding data to the vector, deleting the vector, or the vector goes out of scope). The example I provided above is OK because the vector is not changed after obtaining the pointer. Once the data are passed to ChartDirector (which will make a copy of the data), you can safely discard the vector and the pointer.
Hope this can help.
Regards
Peter Kwan |
Re: MFC put the data from std::vector |
Posted by Robo on Jun-11-2016 02:09 |
|
Thx a lot for y help.
In the labels :
c->xAxis()->setLabels(StringArray(labels, sizeof(labels)/sizeof(labels[0])));
it is posible to put vectror<string> labels1;
like above
c->xAxis()->setLabels(StringArray(&(labels1[0]), labels1.size())); it don't work |
Re: MFC put the data from std::vector |
Posted by Peter Kwan on Jun-11-2016 21:46 |
|
Ho Robo,
The StringArray uses C text string (const char *), which is standardized. The std::string is STL text string, which is different and does not have any binary standard. You need to convert them to "const char *" text string first. It is like:
//convert to const char *
vector<const char *> myTextString;
for (int i = 0; i < labels1.size(); ++i)
myTextString.push_back(labels1[i].c_str());
c->xAxis()->setLabels(StringArray(&(myTextString[0]), myTextString.size()));
Hope this can help.
Regards
Peter Kwan |
Re: MFC put the data from std::vector |
Posted by Robo on Jun-13-2016 20:20 |
|
char * tabChar = new char[ label1.size() + 1 ];
myTextString.push_back(strcpy( tabChar, label1.c_str() ));
is ok. |
|