|
FinanceChart datetime label format issue |
Posted by seo on Jan-02-2018 16:39 |
|
Hi peter,
I was formating the date time label of a finance chart with these code:
FinanceChart *m = new FinanceChart(width);
m->setDateLabelFormat("some format string");
the result is indeed what I want.
and later in my trackfinance() func, I want to get the datetime label text for the track tip, using these code, The date time value is correct, but the format is not the same as the text shown on xAxis:
//m is the FinanceChart pointer
XYChart* c = (XYChart*)m->getChart(m->getChartCount()-1);
xValue = (int)(c->getNearestXValue(mouseX));
// Draw x-axis label
std::ostringstream xlabel;
xlabel << "some text fomat CDML"
<< c->xAxis()->getFormattedLabel(xValue) << "<*/*>";
TTFText *t = d->text(xlabel.str().c_str(), "some fontname.tff", 10);
t->draw(mouseX, c->getPlotArea()->getBottomY() + c->getAbsOffsetY(),
0xffffff, Chart::Top);
t->destroy();
Do I missed something important? or should I use setMultiFormat of c->xAxis() too?
|
Re: FinanceChart datetime label format issue |
Posted by Peter Kwan on Jan-02-2018 18:29 |
|
Hi seo,
The FinanceChart.setDateLabelFormat are conditional formats. For example, the first argument is the format when the timestamp is the first timestamp of a year. So in a FinanceChart, every x-axis label can be formatted differently, and most of the x-axis labels are simply formatted as empty space. For the non-empty labels, usually people would keep the format short to avoid overcrowding the x-axis.
You probably do not want to use the x-axis labels as the track cursor label, as most of the labels will then be empty.
For the labels on the tooltip, you can use a longer more complete label format. Also, I think it is better that all labels are formatted the same way for consistency. For example, you can use:
c->xAxis()->getFormattedLabel(xValue, "yyyy/mm/dd")
If you really want the exact label on the x-axis, you can use "c->xAxis()->getLabel(xValue)", but as mentioned above, most of the labels are likely empty.
Hope this can help.
Regards
Peter Kwan |
Re: FinanceChart datetime label format issue |
Posted by seo on Jan-02-2018 20:09 |
|
Hi Peter,
For the labels on the tool tip, I do want to use a longer more complete label format. These code is good for me:
c->xAxis()->getFormattedLabel(xValue, "yyyy/mm/dd")
Actually, I have tried some code before post this question:
c->xAxis()->getFormattedLabel(xValue, "{value|yyyy/mm/dd}")
c->xAxis()->getFormattedLabel(xValue, "[{xLabel|yyyy/mm/dd}]")
and the result is not correct. As you can see, I'm a little confused about the format before.
Thanks! |
|