|
I need idea for make this chart.. |
Posted by Chris Kwon on Jul-04-2016 16:18 |
|
Hi,
I drew the graph attached.
I'd like to know how to add the grey line
which penetrates the design point on the graph by programming ..
Thanks,
Chris
p.s : the program made by C++(MFC)
|
Re: I need idea for make this chart.. |
Posted by Peter Kwan on Jul-04-2016 22:26 |
|
Hi Chris,
You need to provide at least two data points to create the line. The "design point" is one point you can use, in this way the line will pass through the design point. You still need to provide another point so to determine how the line should be drawn.
Once you have two points, you may consider to use the TrendLayer to create the line. It is like:
double xCoor[2];
double yCoor[2];
.... fill up the above arrays with two (x, y) coordinates ....
TrendLayer *layer = c->addTrendLayer(DoubleArray(xCoor, 2), DoubleArray(yCoor, 2), 0xbbbbbb);
layer->setLineWidth(2);
For the "design point" itself, if you need to draw that point, you can use a scatter layer to draw a circle point at that position. If you would like to draw a "ring" line in your image, you can add two scatter layers, one with a larger circle, and the other one with a smaller circle.
Hope this can help.
Regards
Peter Kwan |
Re: I need idea for make this chart.. |
Posted by Chris Kwon on Jul-05-2016 08:25 |
|
Thanks for your help, Peter.
I have another questions...
I applied your code to my code,
and then result is like this photo(attached).
(xCoor[2] = {1.06, 2.24}, yCoor[2] = {1.33, 0.45})
But, this graph is not sync with x-axis.
I used chartdirector in my code like below,
"
const char *labels[] = { "0.0", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9", "1.0",
"1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0", "2.1", "2.2", "2.3", "2.4", "2.5",
"2.6", "2.7", "2.8", "2.9", "3.0", "3.1", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9",
"4.0", "4.1", "4.2", "4.3", "4.4", "4.5", "4.6", "4.7", "4.8", "4.9", "5.0" };
...
c->xAxis()->setLabelStep(10);
...
layer->addDataSet(DoubleArray(graph01, k), 0x5588cc, approach);
// graph01~06 are made by malloc.(there are dynamic data for graph)
...
"
Is unsync caused by label setting or by my data set?
I am desperately waiting for your help (T.T)....
Thanks,
Chris
|
Re: I need idea for make this chart.. |
Posted by Peter Kwan on Jul-05-2016 18:48 |
|
Hi Chris,
If you have the end points of the line, you can use addLineLayer instead of addTrendLayer. The addTrendLayer can extend the line to the plot area border. This is useful if you do not have the end points of the line but the intermediate points. To use addLineLayer, the code is like:
LineLayer *layer = c->addLineLayer(DoubleArray(yCoor, 2), 0xbbbbbb);
layer->setXData(DoubleArray(xCoor, 2));
layer->setLineWidth(2);
Also, for your case, there should be no need to use the labels array or setLabelStep. You just need to set the x-axis scale:
// x-axis scale from 0 to 2.3, with a label every 0.2 unit and a minor tick every 0.1 unit
c->xAxis()->setLinearScale(0, 2.3, 0.2, 0.1);
Hope this can help.
Regards
Peter Kwan |
Re: I need idea for make this chart.. |
Posted by Chris Kwon on Jul-06-2016 09:30 |
|
Thanks, Peter.
It's really helpful |
Re: I need idea for make this chart.. |
Posted by Chris Kwon on Jul-20-2016 14:46 |
|
Hi,
I'd like to know how to trim the line pointed red circle.
Here's my code.(I was received your response, and applied it)
...
LineLayer *slopeLine = c->addLineLayer(DoubleArray(yCoor, 2),0xbbbbbb);
slopeLine->setXData(DoubleArray(xCoor, 2));
slopeLine->setLineWidth(2);
...
Can I set a option?
Thanks,
Chris.
|
Re: I need idea for make this chart.. |
Posted by Peter Kwan on Jul-20-2016 17:54 |
|
Hi Chris,
Try using:
c->setClipping();
Regards
Peter Kwan |
Re: I need idea for make this chart.. |
Posted by Chris Kwon on Jul-21-2016 08:30 |
|
It's really helpful. Thanks, Peter. |
Re: I need idea for make this chart.. |
Posted by Chris Kwon on Jul-28-2016 10:03 |
|
Hi, Peter.
I need your help.
I want to insert image behind graph.
I used code like this,
....
c->setPlotArea(0, 0, 750, 530, Chart::Transparent, Chart::Transparent, Chart::Transparent, Chart::Transparent);
DrawArea *pic = c->getDrawArea();
pic->loadJPG("image.jpg");
pic->resize(750, 530);
...
but, image didn't appear in chart...
And I also want to know about setting Y-axis value.
Last time, you recommended code, "... c->xAxis()->setLinearScale(-10, 30); ..."
it's really helpful. And now, I need how to fix value of Y-axis ....
Thanks,
Chris |
Re: I need idea for make this chart.. |
Posted by Peter Kwan on Jul-29-2016 03:53 |
|
Hi Chris,
The code you use should be correct. If no image appears, from experience, the most likely issue is that the image path is incorrect.
In your code, you use "image.jpg" but there is no directory. In this case, the operating system will use the "current working directory" of the running process. For example, if you use "fopen" to open a file without providing an absolute path, it will also open the file in the "current working directory".
The "current working directory" depends on how you start your application. If it is run inside Visual Studio, it may be the directory of the "project file", or the directory of the executable (which can be in the "Debug" or "Release" directory), or in some other directory, depending on how your project is configured. If you run the application by clicking the EXE from the File Explorer, the "current working directory" is usually the directory of the EXE. If you run the EXE using a batch file, the "current working directory" can be the directory of the batch file. If you run the EXE using a shortcut icon on the desktop, the "current working directory" is the "Start In" directory configured in the shortcut (which may not be the directory of the EXE).
Because the "current working directory" is frequently unpredictable (it depends on how the user starts the program), so we do not suggest to use a "relative path" for the filename. Instead, you may first detect the absolute path of your EXE, then use it to create an absolute path to the image to load the image. Alternatively, you may change the "current working directory" to the absolute path of your EXE before trying to load the image.
To test if the above is the cause of the problem, please use an absolute path to the image:
pic->loadJPG("c:\\path\\to\\image.jpg");
Alternative, you may try to fopen the image, like:
FILE *f = fopen("image.png", "rb");
assert(f != 0);
fclose(f);
If the fopen is not successful, that means the image path is incorrect.
As an alternative of using DrawArea::loadJPG, you can use other methods such as BaseChart::setBgImage, BaseChart::setWallpaper or PlotArea::setBackground. There is an example at:
http://www.advsofteng.com/doc/cdcpp.htm#background.htm
For the y-axis scale, you may use c->yAxis()->setLinearScale(.....);
Regards
Peter Kwan |
Re: I need idea for make this chart.. |
Posted by Chris Kwon on Aug-04-2016 07:56 |
|
I always thank you, Peter |
Win 7 & Win 10 compatibility |
Posted by Chris Kwon on Aug-05-2016 13:05 |
|
Hi,
I use win10, make install program and distribute colleague.
His computer used win7. His capture and my capture is attached.
When I use win7 environment and optimize at win7, it can't
sync size at win10. What should I do?...
|
Re: Win 7 & Win 10 compatibility |
Posted by Chris Kwon on Aug-05-2016 13:07 |
|
p.s : using VS2015 Community... |
Re: Win 7 & Win 10 compatibility |
Posted by Peter Kwan on Aug-05-2016 16:05 |
|
Hi Chris,
From the screen shot, the charts in Win 7 and in Win 10 are the same. The charts are of the same size and show the same contents.
However, in Win 7 it seems the Window size is smaller so it cannot contain the entire chart. Your table at the bottom is smaller too. It has smaller font size.
I am not sure how you design your layout. For your case, you may consider to use a fixed Window size and make it non-resizable. The Window size should be big enough to contain both the chart and the table.
If you must make the chart resizable, instead of using a fixed size, you can compute a chart size based on the window size. You may also need to handle the resize event in MFC, so that when the user resizes the window, your code can redraw the chart at another size.
Regards
Peter Kwan |
Re: Win 7 & Win 10 compatibility |
Posted by Chris Kwon on Aug-11-2016 13:14 |
|
I see. My Program is problem. Thank you! |
|