Pie and marks

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

Pie and marks

Post by Dmitry » Tue Aug 18, 2009 11:55 am

Image

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

Dmitry

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

Re: Pie and marks

Post by Yeray » Fri Aug 21, 2009 11:06 am

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,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

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

Re: Pie and marks

Post by Dmitry » Sun Aug 23, 2009 9:13 pm

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

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

Re: Pie and marks

Post by Yeray » Wed Aug 26, 2009 11:18 am

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());

        pie1.add(300, "first");
        pie1.add(5, "second");
        pie1.add(2, "third");
        pie1.add(3, "fourth");
        pie1.add(4, "fifth");

        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,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

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

Re: Pie and marks

Post by Dmitry » Wed Aug 26, 2009 1:29 pm

ok.
I hope next release will be with bugfix

Post Reply