Pie and marks

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Dmitry
Newbie
Posts: 54
Joined: Mon Jul 27, 2009 12:00 am
Contact:

Pie and marks

How can i do that marks don't put over each other?

Dmitry

Yeray
Posts: 8752
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Pie and marks

Hi Dmitry,

We are finding some problems in 3D that we are trying to solve but in 2D it seems to work fine:

Code: Select all

``````public void doMarks()
{
com.steema.teechart.styles.SeriesMarksPosition sMarkPos =
new com.steema.teechart.styles.SeriesMarksPosition();

chart1.repaint();

sMarkPos.height = chart1.getGraphics3D().textHeight("H") + 2;
int yDisp = sMarkPos.height + 5;

int[] xPos = new int[pieSeries.getCount()];
int[] yPos = new int[pieSeries.getCount()];
for (int i = 0; i < pieSeries.getCount(); i++)
{
xPos[i] = pieSeries.getMarks().getPositions().getPosition(i).leftTop.x;
yPos[i] = pieSeries.getMarks().getPositions().getPosition(i).getBounds().y;
}

for (int i = 0; i < pieSeries.getCount(); i++)
{
sMarkPos = new com.steema.teechart.styles.SeriesMarksPosition();
sMarkPos.custom = true;
sMarkPos.height = chart1.getGraphics3D().textHeight("H") + 2;

if ((i>0) && (Math.abs(yPos[i] - yPos[i-1]) < yDisp)
&& (Math.abs(xPos[i] - xPos[i-1]) <
chart1.getGraphics3D().textWidth(pieSeries.getMarkText(i-1))))
xPos[i] = xPos[i] + chart1.getGraphics3D().textWidth(pieSeries.getMarkText(i-1));

sMarkPos.leftTop.setLocation(xPos[i],yPos[i]);
sMarkPos.width = chart1.getGraphics3D().textWidth(pieSeries.getMarkText(i)) + 5;

pieSeries.getMarks().getPositions().setPosition(i, sMarkPos);
}

chart1.repaint();
} ``````
Best Regards,
 Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) Please read our Bug Fixing Policy

Dmitry
Newbie
Posts: 54
Joined: Mon Jul 27, 2009 12:00 am
Contact:

Re: Pie and marks

This problem is for 2d too.
What will i do with this code?
Dmitry

Yeray
Posts: 8752
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Pie and marks

Hi Dmitry,

Here you have a simple example of how you could move the marks. As you'll see, when this application is started, some marks overlap the others but clicking the button we calculate new positions moving them more to the right-bottom until there is enough space to draw them:

Code: Select all

``````    Pie pie1;

private void initChart() {
commander1.setChart(tChart1.getChart());

tChart1.getAspect().setView3D(false);

pie1 = new Pie(tChart1.getChart());

tChart1.getAspect().setOrthogonal(false);
tChart1.getAspect().setElevation(280);
tChart1.getAspect().setRotation(0);
}

public void doMarks()
{
Rectangle R1,R2;
for (int i=0; i<pie1.getCount()-1; i++)
{
for (int j=0; j<pie1.getCount()-1; j++)
{
if (j!=i)
{
com.steema.teechart.styles.SeriesMarksPosition mp1 = pie1.getMarks().getPositions().getPosition(i);
com.steema.teechart.styles.SeriesMarksPosition mp2 = pie1.getMarks().getPositions().getPosition(j);

R1 = mp1.getBounds();
R2 = mp2.getBounds();
while   (  (R1.getLeft() > R2.getLeft()
&& R1.getLeft() < R2.getRight())
|| (R1.getRight() > R2.getLeft()
&& R1.getRight() < R2.getRight())
|| (R1.getTop() > R2.getBottom()
&& R1.getTop() < R2.getTop())
|| (R1.getBottom() > R2.getTop()
&& R1.getBottom() < R2.getBottom()) )
{
mp1.custom = true;
mp1.leftTop.x = mp1.leftTop.x + 2;
mp1.leftTop.y = mp1.leftTop.y + 2;
mp1.arrowTo.x = mp1.leftTop.x + 2;
mp1.arrowTo.y = mp1.leftTop.y + 2;
R1 = mp1.getBounds();
R2 = mp2.getBounds();
}
tChart1.repaint();
}
}
}
}

@Action
public void ButtonClick() {
doMarks();
}``````
Best Regards,
 Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) Please read our Bug Fixing Policy

Dmitry
Newbie
Posts: 54
Joined: Mon Jul 27, 2009 12:00 am
Contact:

Re: Pie and marks

ok.
I hope next release will be with bugfix