|
Adding spreadsheet-like XY Chart to Finance Chart |
Posted by Takeshi on Jan-02-2021 17:02 |
|
Hi Peter,
Could I ask for your insightful opinion on how to draw a spreadsheet-like XY Chart and print it underneath finance chart, please?
The first image shows the data calculated in excel file and it can later be imported into program. I am wondering if I could insert the data of 'Percent Above 20Day MA' into cells and associate it to finance chart with color scales (min 0 & max 100, numbers are hidden), as highlighted in the second image which has been done by others. The timestamps have to be synchronized.
In addition, would it be possible to insert legends to the right of the XY Chart as shown in the second image as well?
I am using Qt C++ for your information please.
Thank you so much for your time.
Best Regards,
Takeshi
|
Re: Adding spreadsheet-like XY Chart to Finance Chart |
Posted by Peter Kwan on Jan-09-2021 23:32 |
|
Hi Takeshi,
Sorry for the late reply.
For your case, you can add a discrete heat map in a custom indicator. The following post has some information about a discrete heat map.
https://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&thread=1547024116#N1547084322
In brief, it is like:
FinanceChart *c = new FinanceChart(.....);
... set up FinanceChart as usual and add the main chart and indicators ...
//
// Below is an example to add the discrete heat map
//
// Assume you have 3 rows of cells
const char* labels[] = { "AAA", "BBB", "CCC" };
int labelCount = (int)(sizeof(labels)/sizeof(*labels));
// Generate some random data for testing. The number of cells per row should
// be equal to the number of visible timeStamps.
RanSeries r(999);
DoubleArray AAAData = r.getSeries(timeStamps.len - extraDays, -100, 100);
DoubleArray BBBData = r.getSeries(timeStamps.len - extraDays, -100, 100);
DoubleArray CCCData = r.getSeries(timeStamps.len - extraDays, -100, 100);
// Add an empty indicator chart
XYChart* t = c->addIndicator(75);
// Add the labels to the y-axis
t->yAxis()->setLinearScale(0, labelCount - 1, StringArray(labels, labelCount));
t->yAxis()->setIndent(true);
c->layout();
// We can use a hidden color axis to translate the cell values to colors
ColorAxis* cAxis = t->addContourLayer(DoubleArray(), DoubleArray(), DoubleArray())->colorAxis();
cAxis->setLinearScale(-100, 100);
int colors[] = { 0xff0000, 0xffffff, 0x00ff00 };
cAxis->setColorGradient(true, IntArray(colors, (int)(sizeof(colors)/sizeof(*colors))));
// All the cell data
DoubleArray allData[] = { AAAData, BBBData, CCCData };
// Use the DrawArea to draw the cells as rectangles
DrawArea* d = t->makeChart();
for (int i = 0; i < closeData.len - extraDays; ++i) {
for (int j = 0; j < (int)(sizeof(allData)/sizeof(*allData)); ++j) {
int color = cAxis->getColor(allData[j][i]);
d->rect(t->getXCoor(i - 0.5), t->getYCoor(j + 0.5), t->getXCoor(i + 0.5), t->getYCoor(j - 0.5), color, color);
}
}
... display chart as usual ...
Regards
Peter Kwan |
|