ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  addBoxWhiskerLayer2 & addCustomDataLabel & Scroll & Label everytime centered
Posted by Fabian on Sep-22-2011 02:53
Hello Peter,

could you please tell me if it is possible to set CustomDataLabel everytime centered to the visible part of a box? My chart is scrollable...

At the moment my code to add CustomDataLabel is like below:

for(i=m_iVStartIndex; i<m_iVStartIndex+m_iMaxShownV;i++)
{
   TextBox* txtbox = layer->addCustomDataLabel(0, a++, m_pAnzahl[i]);
   txtbox->setAlignment(Chart::Center);
}

If I scroll to the end of a box and the middle is out of the visible part, the DataLabel isn't visible.
How can I set the CustomDataLabel evertime centered of the visible part of a box?

  Re: addBoxWhiskerLayer2 & addCustomDataLabel & Scroll & Label everytime centered
Posted by Peter Kwan on Sep-23-2011 00:56
Hi Fabian,

One method I can think of is to specify the position where you want to add the label using a scatter layer. Normally, the center point of a box (in the y-direction) is "(boxTop + boxBottom) / 2". If in your case, it is possible for the box to scroll outside the plot area in the y-direction, you can compute the "visible center point" by bounding the top and bottom to the y-axis range.

I have include an example below. This example assumes you can scroll both along the x-direction and y-direction. (I am not too sure the variables in your code mean, so my usage of the variables may not be correct.)

//The positions of the labels
std::vector<double> labelX;
std::vector<double> labelY;

for(i=m_iVStartIndex; i<m_iVStartIndex+m_iMaxShownV;i++)
{
      labelX.push_back((std::max(minX, a - 0.35) + std::min(maxX, a + 0.35)) / 2.0);
      labelY.push_back((std::max(minY, boxTop[i]) + std::max(maxY, boxBottom[i])) / 2.0);
      ++a;
}

//Add the labels
ScatterLayer *labelLayer = c->addScatterLayer(DoubleArray(&(labelX[0]), labelX.size()), DoubleArray(&(labelY[0]), labelY.size()), "", Chart::SquareSymbol, 1, Chart::Transparent, Chart::Transparent);
labelLayer->moveFront(layer);

a = 0;  //???? is this correct ????
for(i=m_iVStartIndex; i<m_iVStartIndex+m_iMaxShownV;i++)
{
   TextBox* txtbox = labelLayer->addCustomDataLabel(0, a++, m_pAnzahl[i]);
   txtbox->setAlignment(Chart::Center);
}

Hope thi scan help.

Regards
Peter Kwan

  Re: addBoxWhiskerLayer2 & addCustomDataLabel & Scroll & Label everytime centered
Posted by Fabian on Sep-23-2011 18:59
Attachments:
Hi Peter,

thank you very much!

In my first step my xCoordinates can't scroll.
I edit your example like below and that was the solution! :-)

double index=0.0;
for(i=m_iVStartIndex; i<m_iVStartIndex+m_iMaxShownV;i++){
   labelX.push_back(index);
   labelY.push_back((std::max(dStartDate, m_pStartDate[i]) + std::min(dEndDate, m_pEndDate[i])) / 2.0);
   ++index;
}

Attached a screenshot from my chart.
Caption always centered.png