Page 1 of 1

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

Posted: Fri Feb 18, 2011 1:11 pm
by 15358545
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 :)

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

Posted: Mon Feb 21, 2011 3:14 pm
by yeray
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());
    }

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

Posted: Fri Feb 25, 2011 6:54 pm
by 15358545
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

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

Posted: Mon Feb 28, 2011 3:36 pm
by yeray
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 26821 times
TeeChart2.png
TeeChart2.png (15.74 KiB) Viewed 26816 times
could you please confirm if this is what you are experiencing?

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

Posted: Mon Feb 28, 2011 9:07 pm
by 15358545
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!

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

Posted: Tue Mar 01, 2011 4:12 pm
by yeray
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.

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

Posted: Tue Mar 01, 2011 9:39 pm
by 15358545
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' ?

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

Posted: Wed Mar 02, 2011 11:14 am
by yeray
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.

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

Posted: Wed Mar 02, 2011 1:01 pm
by 15358545
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

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

Posted: Wed Mar 02, 2011 2:08 pm
by 15358545
Yeray, the rectangle shows up when I keep the mouse pressed down on the plot :s that's weird

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

Posted: Wed Mar 02, 2011 9:52 pm
by 15358545
Any ideas for get this to work? :?

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

Posted: Thu Mar 03, 2011 4:11 pm
by yeray
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());

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

Posted: Thu Apr 14, 2011 10:27 am
by Marc
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