Workaround for Error in area charts w/stairs w/origin

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
Miguel
Newbie
Newbie
Posts: 10
Joined: Mon Feb 14, 2011 12:00 am

Workaround for Error in area charts w/stairs w/origin

Post by Miguel » Fri Feb 18, 2011 1:11 pm

Hello

Some weeks ago I found a bug and reported to TeeCharts, they are working on it but I need a workaround, the problem is as follows: If you create an area chart with stairs and set the origin on the max value (to see it up side down) the chart doesn't shows fine.

What could be a workaround for this problem? I need an upside down stairs chart, or something like it

Thanks in advance :)

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

Re: Workaround for Error in area charts w/stairs w/origin

Post by Yeray » Mon Feb 21, 2011 3:14 pm

Hi Miguel,

You could use a Bar3D serie sinstead of using an Area series with stairs:

Code: Select all

    private void initChart() {
        tChart1.getAspect().setView3D(false);

        com.steema.teechart.styles.Area area1 = new com.steema.teechart.styles.Area(tChart1.getChart());
        area1.fillSampleValues();

        area1.setUseOrigin(false);
        area1.setOrigin(area1.getMinYValue() + Math.round((area1.getMaxYValue() - area1.getMinYValue()) / 2));
        area1.setUseOrigin(true);
        area1.setStairs(true);

        com.steema.teechart.styles.Bar3D bar1 = new com.steema.teechart.styles.Bar3D(tChart1.getChart());
        bar1.setDataSource(area1);
        bar1.getMarks().setVisible(false);
        bar1.setBarWidthPercent(100);

        for (int i=0; i<bar1.getCount(); i++)
        {
            bar1.getOffsetValues().setValue(i, area1.getOrigin());
        }

        area1.setActive(false);
        tChart1.getAxes().getLeft().setMinMax(bar1.getYValues().getMinimum() - tChart1.getAxes().getLeft().getMinimumOffset(), bar1.getYValues().getMaximum() + tChart1.getAxes().getLeft().getMaximumOffset());
    }
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

Miguel
Newbie
Newbie
Posts: 10
Joined: Mon Feb 14, 2011 12:00 am

Re: Workaround for Error in area charts w/stairs w/origin

Post by Miguel » Fri Feb 25, 2011 6:54 pm

Hi Yeray, I have a problem with this solution, when I zoom horizontally the first (most left) Bar doesn't show up, do you know how to fix that?

Thanks for the workaround though

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

Re: Workaround for Error in area charts w/stairs w/origin

Post by Yeray » Mon Feb 28, 2011 3:36 pm

Hi Miguel,

I've seen that, if you scroll a chart with a Bar series, each bar disappears when half bar is out of the bar (only in the left side of the chart). I've added it to the wish list to be enhanced in future releases (TJ71015425).
To reproduce it you only need a Bar series and scroll a little bit:

Code: Select all

        tChart1.getAspect().setView3D(false);

        com.steema.teechart.styles.Bar bar1 = new com.steema.teechart.styles.Bar(tChart1.getChart());
        bar1.fillSampleValues(6);
TeeChart1.png
TeeChart1.png (15.9 KiB) Viewed 23457 times
TeeChart2.png
TeeChart2.png (15.74 KiB) Viewed 23452 times
could you please confirm if this is what you are experiencing?
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

Miguel
Newbie
Newbie
Posts: 10
Joined: Mon Feb 14, 2011 12:00 am

Re: Workaround for Error in area charts w/stairs w/origin

Post by Miguel » Mon Feb 28, 2011 9:07 pm

Hello Yeray

Yes, that's what I'm experiencing :)

My problem is that I can't wait for a future release :( Is there another way to get an up side down stairs area chart? or to add the feature myself by editing the source code? maybe regarding the bug TJ71015368 (the source of all of the conversation :)

Thanks again!

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

Re: Workaround for Error in area charts w/stairs w/origin

Post by Yeray » Tue Mar 01, 2011 4:12 pm

Hi Miguel,

In the meanwhile, a workaround could be to draw manually the hidden portion of the bar:

Code: Select all

        tChart1.addChartPaintListener(new ChartPaintListener() {

            @Override
            public void axesPainting(ChartDrawEvent e) {
            }

            @Override
            public void chartPainted(ChartDrawEvent e) {
                for(int i=0;i<bar1.getCount()-1;i++)
                {
                    int right = bar1.calcXPos(i+1);

                    if (tChart1.getAxes().getBottom().getMinimum()>bar1.getXValues().getValue(i) && (right > tChart1.getChart().getChartRect().getLeft()))
                    {
                        tChart1.getGraphics3D().getBrush().setColor(bar1.getColor());
                        tChart1.getGraphics3D().getPen().setColor(bar1.getPen().getColor());
                        
                        int left = tChart1.getChart().getChartRect().getLeft();
                        int top = Math.max(bar1.calcYPos(i), tChart1.getChart().getChartRect().getTop());
                        int bottom = tChart1.getAxes().getLeft().calcPosValue(bar1.getOffsetValues().getValue(0));
                        
                        tChart1.getGraphics3D().rectangle(left, top, right, bottom);
                        break;
                    }
                }
            }

            @Override
            public void chartPainting(ChartDrawEvent e) {
            }

            @Override
            public void seriesPainting(ChartDrawEvent e) {
            }

            @Override
            public void seriesPainted(ChartDrawEvent e) {
            }
        });
The code above works for a Bar Series with BarWidhPercent = 100.
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

Miguel
Newbie
Newbie
Posts: 10
Joined: Mon Feb 14, 2011 12:00 am

Re: Workaround for Error in area charts w/stairs w/origin

Post by Miguel » Tue Mar 01, 2011 9:39 pm

Hi Yeray, the last code doesn't work for me (maybe because I'm using Bar3D) :(

Do you know where, on the source code, can I deactivate the default 'half out bar disappearance' ?

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

Re: Workaround for Error in area charts w/stairs w/origin

Post by Yeray » Wed Mar 02, 2011 11:14 am

Hi Miguel,

The workaround proposed works for me in the example I posted some posts above.
The complete example would be this:

Code: Select all

    com.steema.teechart.styles.Bar3D bar1;
    private void initChart() {
        tChart1.getAspect().setView3D(false);

        com.steema.teechart.styles.Area area1 = new com.steema.teechart.styles.Area(tChart1.getChart());
        area1.fillSampleValues();

        area1.setUseOrigin(false);
        area1.setOrigin(area1.getMinYValue() + Math.round((area1.getMaxYValue() - area1.getMinYValue()) / 2));
        area1.setUseOrigin(true);
        area1.setStairs(true);

        bar1 = new com.steema.teechart.styles.Bar3D(tChart1.getChart());
        bar1.setDataSource(area1);
        bar1.getMarks().setVisible(false);
        bar1.setBarWidthPercent(100);

        for (int i=0; i<bar1.getCount(); i++)
        {
            bar1.getOffsetValues().setValue(i, area1.getOrigin());
        }

        area1.setActive(false);
        tChart1.getAxes().getLeft().setMinMax(bar1.getYValues().getMinimum() - tChart1.getAxes().getLeft().getMinimumOffset(), bar1.getYValues().getMaximum() + tChart1.getAxes().getLeft().getMaximumOffset());

        tChart1.addChartPaintListener(new ChartPaintListener() {

            @Override
            public void axesPainting(ChartDrawEvent e) {
            }

            @Override
            public void chartPainted(ChartDrawEvent e) {
                for(int i=0;i<bar1.getCount()-1;i++)
                {
                    int right = bar1.calcXPos(i+1);

                    if (tChart1.getAxes().getBottom().getMinimum()>bar1.getXValues().getValue(i) && (right > tChart1.getChart().getChartRect().getLeft()))
                    {
                        tChart1.getGraphics3D().getBrush().setColor(bar1.getColor());
                        tChart1.getGraphics3D().getPen().setColor(bar1.getPen().getColor());

                        int left = tChart1.getChart().getChartRect().getLeft();
                        int top = Math.max(bar1.calcYPos(i), tChart1.getChart().getChartRect().getTop());
                        int bottom = tChart1.getAxes().getLeft().calcPosValue(bar1.getOffsetValues().getValue(0));

                        tChart1.getGraphics3D().rectangle(left, top, right, bottom);
                        break;
                    }
                }
            }

            @Override
            public void chartPainting(ChartDrawEvent e) {
            }

            @Override
            public void seriesPainting(ChartDrawEvent e) {
            }

            @Override
            public void seriesPainted(ChartDrawEvent e) {
            }
        });
    }
If you still have problems with it don't hesitate to let us know.
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

Miguel
Newbie
Newbie
Posts: 10
Joined: Mon Feb 14, 2011 12:00 am

Re: Workaround for Error in area charts w/stairs w/origin

Post by Miguel » Wed Mar 02, 2011 1:01 pm

Hi Yeray, I implemented the code with another series plotted (as I have several on my project) and the result is the attachment, it doesn't work for me :( the fisrt left bar doesn't show up
Attachments
Sin título.png
Example
Sin título.png (18.75 KiB) Viewed 23394 times

Miguel
Newbie
Newbie
Posts: 10
Joined: Mon Feb 14, 2011 12:00 am

Re: Workaround for Error in area charts w/stairs w/origin

Post by Miguel » Wed Mar 02, 2011 2:08 pm

Yeray, the rectangle shows up when I keep the mouse pressed down on the plot :s that's weird

Miguel
Newbie
Newbie
Posts: 10
Joined: Mon Feb 14, 2011 12:00 am

Re: Workaround for Error in area charts w/stairs w/origin

Post by Miguel » Wed Mar 02, 2011 9:52 pm

Any ideas for get this to work? :?

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

Re: Workaround for Error in area charts w/stairs w/origin

Post by Yeray » Thu Mar 03, 2011 4:11 pm

Hi Miguel,

I've only set the Brush and the Pen color to draw the bar portions manually. Assigning the whole bar brush could fix the problem.
Change the following in the example above:

Code: Select all

                        tChart1.getGraphics3D().setBrush(bar1.getBrush());
                        //tChart1.getGraphics3D().getBrush().setColor(bar1.getColor());
                        //tChart1.getGraphics3D().getPen().setColor(bar1.getPen().getColor());
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

Marc
Site Admin
Site Admin
Posts: 1209
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Workaround for Error in area charts w/stairs w/origin

Post by Marc » Thu Apr 14, 2011 10:27 am

Hello,

This issue, id TJ71015368, is resolved for inclusion in the next maintenance release.

The problem does not occur in SWT but does occur in Swing although the same underlying graphics calls/libraries are used.

If you wish to apply the fix pending receipt of the maintenance release this is the required modification:

In TeeChart's Graphics3DAWT.java unit, replace the following line:

Code: Select all

  /**
   * Draws a Rectangle (Rectangle r).
   *
   * @param r Rectangle
   */
  public void rectangle(Rectangle r) {
with

Code: Select all

  private Rectangle invertNegativeRect(Rectangle r)
  {
      if (r.width < 0)
      {
          int tmpL=r.getLeft();
          r.setLeft(r.getRight());
          r.setRight(tmpL);
      }
      if (r.height < 0)
      {
          int tmpT=r.getTop();
          r.setTop(r.getBottom());
          r.setBottom(tmpT);
      }
      return r;
  }

  /**
   * Draws a Rectangle (Rectangle r).
   *
   * @param r Rectangle
   */
  public void rectangle(Rectangle r) {
    r=invertNegativeRect(r);  //TJ71015368
Regards,
Marc Meumann
Steema Support

Post Reply