|
add a custom tooltips for HLOC |
Posted by Morning song on May-06-2015 22:04 |
|
hi Peter!
HLOC and CandleStick Layers have 4 fields(high low open close). i want to add a custom field named "change" (change = closeValue - lastCloseValue).PS C++ &QT
give me an example,Thank you !
|
Re: add a custom tooltips for HLOC |
Posted by Peter Kwan on May-07-2015 02:13 |
|
Hi Morning song,
First, compute the extra field you want to be included in the tooltip, then add the extra
field to the CandleStickLayer using addExtraField, like:
CandleStickLayer *layer = myFinanceChart->addCandleStick(.......);
layer->addExtraField(DoubleArray(myExtraField, arraySize));
Then configure the tooltip to include that field as {field0}.
layer->setHTMLImageMap("", "", "title='[mm/dd/yyyy] Op:{open|P3}, Hi:{high|P3}, Lo:
{low|P3}, Cl:{close|P3} Change:{field0|P3}'");
Hope this can help.
Regards
Peter Kwan |
Re: add a custom tooltips for HLOC |
Posted by Morning song on May-08-2015 09:00 |
|
hi peter. it's work ,but value is wrong. the stock data which i read from txt file.
In finance demo , i add this codes:
public: CandleStickLayer* addCandleStick(int upColor, int downColor)
{
addOHLCLabel(upColor, downColor, true);
CandleStickLayer *ret = m_mainChart->addCandleStickLayer(m_highData, m_lowData, m_openData,
m_closeData, upColor, downColor,0x8F8F8F);
ret->addExtraField(m_highData);// add by myself
ret->setHTMLImageMap("", "", getHLOCToolTipFormat().c_str());
if (m_highData.len - m_extraPoints > 60) {
ret->setDataGap(0);
}
if (m_highData.len > m_extraPoints) {
int expectedWidth = (m_totalWidth - m_leftMargin - m_rightMargin) / (m_highData.len - m_extraPoints);
if (expectedWidth <= 5)
ret->setDataWidth(expectedWidth + 1 - expectedWidth % 2);
}
return ret;
}
private: std::string getHLOCToolTipFormat()
{
char buffer[1024];
sprintf(buffer, "title='%s\\n Op:{open|%s}\\n Hi:{high|%s}\\n Lo:{low|%s}\\n Cl:{close|%s}\\n MyHi:{field0|%s}'",
getToolTipDateFormat(), m_generalFormat.c_str(), m_generalFormat.c_str(), m_generalFormat.c_str(),m_generalFormat.c_str(),
m_generalFormat.c_str());
return QTextCodec::codecForName("UTF-8")->fromUnicode(buffer).constData();
} |
Re: add a custom tooltips for HLOC |
Posted by Morning song on May-08-2015 09:02 |
|
picture
|
Re: add a custom tooltips for HLOC |
Posted by Peter Kwan on May-09-2015 01:14 |
|
Hi Morning,
I forgot to inform you about an important point. The extra field should be based the actual
number of candlesticks displayed on the chart.
In the FinanceChart, there is a "extraPoint" parameter. In the FinanceChart object, it is
stored as m_extraPoints. For the timeStamps and OHLC and vol data, ChartDirector will
remove the leading points and not plot them. However, for extra field, ChartDirector will not
remove leading points. It is because ChartDirector does not know the meaning of the extra
field. It can be used to label the candlesticks (like in your case), but it can also be used in
other ways (such as to be used as an additional content in the legend box, etc). So if the
extra field is used to label the candlesticks, you could would need to pass the data after
removing the leading points. So the code should be like:
ret->addExtraField(DoubleArray(m_highData.data + m_extraPoints,
std::max(0, m_highData.len - m_extraPoints));
Hope this can help.
Regards
Peter Kwan |
|