|
[Dev C++ ] output chart |
Posted by TIm on Feb-01-2013 12:51 |
|
I can compile the sample code (condlestick.cpp) without errors. But I cannot find the
output file
"candlestick.png"
My machine is running 64 bit. Both dev and chartdir are at 32 bit. Need someone
help!please
#include <cstdlib>
#include <iostream>
#include "chartdir.h"
using namespace std;
int main(int argc, char *argv[])
{
//
// Sample data for the CandleStick chart.
//
double highData[] = {2043, 2039, 2076, 2064, 2048, 2058, 2070, 2033, 2027, 2029,
2071, 2085, 2034, 2031, 2056, 2128, 2180, 2183, 2192, 2213, 2230, 2281, 2272}
;
double lowData[] = {1931, 1921, 1985, 2028, 1986, 1994, 1999, 1958, 1943, 1944,
1962, 2011, 1975, 1962, 1928, 2059, 2112, 2103, 2151, 2127, 2123, 2152, 2212}
;
double openData[] = {2000, 1957, 1993, 2037, 2018, 2021, 2045, 2009, 1959, 1985,
2008, 2048, 2006, 2010, 1971, 2080, 2116, 2137, 2170, 2172, 2171, 2191, 2240}
;
double closeData[] = {1950, 1991, 2026, 2029, 2004, 2053, 2011, 1962, 1987, 2019,
2040, 2016, 1996, 1985, 2006, 2113, 2142, 2167, 2158, 2201, 2188, 2231, 2242}
;
// The labels for the CandleStick chart
const char *labels[] = {"Mon 1", "Tue 2", "Wed 3", "Thu 4", "Fri 5", "Mon 8",
"Tue 9", "Wed 10", "Thu 11", "Fri 12", "Mon 15", "Tue 16", "Wed 17",
"Thu 18", "Fri 19", "Mon 22", "Tue 23", "Wed 24", "Thu 25", "Fri 26",
"Mon 29", "Tue 30", "Wed 31"};
// Create a XYChart object of size 600 x 350 pixels
XYChart *c = new XYChart(600, 350);
// Set the plotarea at (50, 25) and of size 500 x 250 pixels. Enable both the
// horizontal and vertical grids by setting their colors to grey (0xc0c0c0)
c->setPlotArea(50, 25, 500, 250)->setGridColor(0xc0c0c0, 0xc0c0c0);
// Add a title to the chart
c->addTitle("Universal Stock Index on Jan 2001");
// Add a custom text at (50, 25) (the upper left corner of the plotarea). Use 12
// pts Arial Bold/blue (4040c0) as the font.
c->addText(50, 25, "(c) Global XYZ ABC Company", "arialbd.ttf", 12, 0x4040c0);
// Add a title to the x axis
c->xAxis()->setTitle("Jan 2001");
// Set the labels on the x axis. Rotate the labels by 45 degrees.
c->xAxis()->setLabels(StringArray(labels, (int)(sizeof(labels) / sizeof(labels[0]
))))->setFontAngle(45);
// Add a title to the y axis
c->yAxis()->setTitle("Universal Stock Index");
// Draw the y axis on the right hand side of the plot area
c->setYAxisOnRight(true);
// Add a CandleStick layer to the chart using green (00ff00) for up candles and
// red (ff0000) for down candles
CandleStickLayer *layer = c->addCandleStickLayer(DoubleArray(highData, (int)(
sizeof(highData) / sizeof(highData[0]))), DoubleArray(lowData, (int)(sizeof(
lowData) / sizeof(lowData[0]))), DoubleArray(openData, (int)(sizeof(openData)
/ sizeof(openData[0]))), DoubleArray(closeData, (int)(sizeof(closeData) /
sizeof(closeData[0]))), 0x00ff00, 0xff0000);
// Set the line width to 2 pixels
layer->setLineWidth(2);
// Output the chart
c->makeChart("candlestick.png");
//free up resources
delete c;
return 0;
} |
Re: [Dev C++ ] output chart |
Posted by Peter Kwan on Feb-02-2013 00:57 |
|
Hi Tim,
The file will be created in the "current working directory". (This is the same for all programs when just the filename is used.)
The exact location of the "current working directory" depends on how you run the program. If you run the program from a development tool (such as Visual Studio), it depends on how your development tool or project file is configured.
If you are using the standard Visual Studio project file that comes with the ChartDirector 5.1 sample code, the "current working directory" is set to be ".\\..\\bin\\Debug" (for Debug mode) or ".\\..\\bin\\Release" (for Release mode). That means if Visual Studio project file is at "cppdemo\\candlestick", then the "current working directory" would be at "cppdemo\\bin\\Debug" or "cppdemo\\bin\\Release".
If you are using your own project file, you may refer to the documentation of your development tool to see where is the current working directory. It may be the same directory as your executable, which may be at a "Debug" or "Release" subdirectory. (The exact location depends on your development tool brand and version, and on your project configuration.)
If you are not sure where is your "current working directory", you may consider to specify an absolute path. For example:
c->makeChart("c:\\\\candlestick.png");
Note that you would need to use a directory that you can write to. (In some operating systems, some directories may be non-writable by certain users.)
Hope this can help.
Regards
Peter Kwan |
Re: [Dev C++ ] output chart |
Posted by TIm on Feb-02-2013 08:07 |
|
I set the path way as D:\\\\candlestick.png but I still cannot find the file. Is there any issues
about Dev C++ ? |
Re: [Dev C++ ] output chart |
Posted by Peter Kwan on Feb-04-2013 23:37 |
|
Hi Tim,
Instead of asking ChartDirector to save the chart a file, may be you can use your own C code to save the chart as a file. It is like:
MemBlock m = c->makeChart(Chart::PNG);
FILE *f = fopen("d:\\\\candlestick.png", "wb");
fwrite(m.data, m.len, 1, f);
fclose(f);
f = fopen("d:\\\\testing.png", "wb");
fwrite("1234567", 7, 1, f);
fclose(f);
The above code will save the chart as a PNG image to "d:\\\\candlestick.png". I have also added code to create a testing file "testing.png". This file is completely unrelated to ChartDirector, and is just to check if your program can save something to a file. If your program cannot even create "d:\\\\testing.png", then the issue is probably unrelated to ChartDirector, but is due to some configuration issue with your project or system (eg. security issue preventing the code to write to the file system - try run as Administrator).
Regards
Peter Kwan |
|