|
About the legend... |
Posted by Cho on Feb-01-2018 09:22 |
|
Hi,
I want to display the legend as shown when the chart is first created.
Currently I am using the addlegend() function at the time of chart creation even though there is no chart data.
layer->addDataSet(DoubleArray(m_dataSeriesA, sampleSize), 0xff0000, "TEMP");
layer->addDataSet(DoubleArray(m_dataSeriesB, sampleSize), 0x0000ff, "HUMID");
But I would like to know how to display legend like this without using this function.
if (m_currentIndex < 0)
{
.....
LegendBox *b = NULL;
//b = c->addLegend2(50, 5, 3, "arialbd.ttf", 9);
b = c->addLegend(2, 2, false, "arialbd.ttf", 8);
//b->setWidth(200);
b->setBackground(Chart::Transparent, Chart::Transparent);
b->setText("{label}({field0})");
b->setFontColor(0xff0000);
b->setText("TEMP");
b->setFontColor(0x0000ff);
b->setText("HUMID");
.....
}
However, the legend is not displayed.
Then, when the chart is collected data, I want to update the data in the legend using the addlegend() function.
if (m_currentIndex > 0)
{
.......
}
Please help me.
Regards,
Cho |
Re: About the legend... |
Posted by Cho on Feb-01-2018 09:24 |
|
The legend of the chart I want is shown below.
|
Re: About the legend... |
Posted by Peter Kwan on Feb-01-2018 15:18 |
|
Hi Cho,
If you want to add legend keys without adding any layers or data sets, you can use LegendBox.addKey. To put the position of the legend on top of the plot area, and spread the keys evenly on the top edge, an example is:
//.... use setPlotArea first to set the plot area, then add the legend box on top
// Grid layout with 2 cells immediately on top of the plot area
LegendBox *b = c->addLegend(c->getPlotArea()->getLeftX(), c->getPlotArea()->getTopY(), 2, "arialbd.ttf", 8);
b->setWidth(c->getPlotArea()->getWidth());
b->setAlignment(Chart::BottomLeft);
b->setMargin(0);
b->setBackground(Chart::Transparent, Chart::Transparent);
// Add the keys
b->addKey("TEMP", 0xff0000);
b->addKey("HUMID", 0x0000ff);
See:
http://www.advsofteng.com/doc/cdcpp.htm#LegendBox.addKey.htm
Hope this can help.
Regards
Peter Kwan |
Re: About the legend... |
Posted by Cho on Feb-01-2018 16:28 |
|
Hi Peter,
Thank you very much for your help.
Regards
Cho |
|