ColorGrid SeriesMouseListener

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
McMClark
Newbie
Newbie
Posts: 4
Joined: Mon Oct 13, 2008 12:00 am

ColorGrid SeriesMouseListener

Post by McMClark » Mon Oct 13, 2008 2:48 pm

I'm trying to receive click events when a user clicks on my color grid. I need to know where in the grid the click occurred so that I can display details relating to that cell. I've added a SeriesMouseListener and a ChartMouseListener, neither of which seems fire at any time. What steps do i need to take to receive those click events?

Thank you

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Mon Oct 13, 2008 3:06 pm

Hi McMClark,

Thanks for reporting. I could reproduce the issue here and added it (TJ71013450) to the defect list to be fixed for next releases.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

McMClark
Newbie
Newbie
Posts: 4
Joined: Mon Oct 13, 2008 12:00 am

Post by McMClark » Tue Oct 14, 2008 12:00 pm

narcis wrote:Hi McMClark,

Thanks for reporting. I could reproduce the issue here and added it (TJ71013450) to the defect list to be fixed for next releases.
Thank You. Any information on when a fix will go out for this? We're dependent on the colorgrid for an upcoming project and will have to find another solution if a fix isn't made soon.

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

Post by Marc » Wed Oct 15, 2008 11:20 am

Hello,

Re. Maintenance release
We will announce it shortly

To resolve the SeriesClick problem, if you are compiling from TeeChart code you can add the following method to the ColorGrid class (com\steema\teechart\styles\ColorGrid.java):

Code: Select all

public int clicked(int X, int Y)
{
  int i, tmpResult = -1;
  double tmpDecAmount;
  int Result = -1;
  int zIndex = -1;
  double XPos = super.getHorizAxis().calcPosPoint(X);
  double YPos = super.getVertAxis().calcPosPoint(Y);
  if (this.centered)
  {
    tmpDecAmount = 0.5;
  }
  else
  {
    tmpDecAmount = 0.0;
  }
  if (!this.getIrregularGrid())
  {
    double YDif = (YPos + tmpDecAmount) - this.getZValues().getMinimum();
    if (YDif >= 0f)
    {
      i = (int)(YDif);
    }
    else
    {
      i = -1;
    }
    if ((i >= 0) && (i < this.getNumZValues()))
    {
      zIndex = i;
    }
    if (zIndex != -1)
    {
      double XDif = (XPos + tmpDecAmount) - this.getXValues().getMinimum();
      if (XDif >= 0f)
      {
        i = (int)(XDif);
      }
      else
      {
        i = -1;
      }
      if ((i >= 0) && (i < this.getNumXValues()))
      {
        tmpResult = this.getIndex(i + 1, zIndex + 1);
      }
    }
    return tmpResult;
  }
  if (super.getXValues().getCount() > 0)
  {
    int num = this.getNumZValues() - 1;
    i = 0;
    if (num >= i)
    {
      num++;
      do
      {
        if (((  (this.getZValues().getValue(i) - tmpDecAmount) <= YPos) 
                && ((this.getZValues().getValue(i + 1) - tmpDecAmount) > YPos)) 
                || (((i == (this.getNumZValues() - 1))) && (((this.getZValues().getValue(i) - tmpDecAmount)) >= YPos)))
        {
          zIndex = i;
          break;
        }
        i++;
      }
      while (i != num);
    }
    if (zIndex != -1)
    {
      int num2 = this.getNumXValues() - 1;
      i = 0;
      if (num2 < i)
      {
        return Result;
      }
      num2++;
      do
      {
        if ((((this.getXValues().getValue(i * this.getNumZValues()) - tmpDecAmount) <= XPos) 
          && ((this.getXValues().getValue((i + 1) * this.getNumZValues()) - tmpDecAmount) > XPos)) || (((i == (this.getNumXValues() - 1))) 
          && (((this.getXValues().getValue(i * this.getNumZValues()) - tmpDecAmount)) >= XPos)))
        {
          return (zIndex + (i * this.getNumZValues()));
        }
        i++;
      }
      while (i != num2);
    }
  }
  return Result;
}
Regards,
Marc Meumann
Steema Support

McMClark
Newbie
Newbie
Posts: 4
Joined: Mon Oct 13, 2008 12:00 am

Post by McMClark » Fri Oct 17, 2008 1:23 pm

well, I must be doing something wrong, I still get no click events. Here's my code. I did add the click method to the colorgrid class. I know I'm using the right JAR b/c the new method is callable from the code that references it.

ColorGrid cg = new ColorGrid(tChart1.getChart());
cg.addSeriesMouseListener(new ColorGridMouseAdapter());

class ColorGridMouseAdapter extends SeriesMouseAdapter
{

@Override
public void seriesClicked(SeriesMouseEvent arg0) {
System.out.println(arg0.getValueIndex());
}

@Override
public void seriesEntered(SeriesMouseEvent arg0) {
super.seriesEntered(arg0);
}

@Override
public void seriesExited(SeriesMouseEvent arg0) {
super.seriesExited(arg0);
}
}

thanks for your help.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Fri Oct 17, 2008 2:16 pm

Hi McMClark,

It works fine for us here using this code:

Code: Select all

        ColorGrid colorGrid1 = new ColorGrid(myChart.getChart());
        colorGrid1.fillSampleValues();

        myChart.addMouseListener(new java.awt.event.MouseListener() {
            public void mouseClicked(MouseEvent e) {
                myChartMouseListened(e);
            }
            public void mouseEntered(MouseEvent e) {
            }
            public void mouseExited(MouseEvent e) {
            }
            public void mousePressed(MouseEvent e) {
            }
            public void mouseReleased(MouseEvent e) {
            }
        });
And implementing the event like this:

Code: Select all

    private void myChartMouseListened(java.awt.event.MouseEvent e) {
        int index = myChart.getSeries(0).clicked(e.getX(),e.getY());
        myChart.getHeader().setText(String.valueOf(index));
    }
Could you please check if that works for you?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

McMClark
Newbie
Newbie
Posts: 4
Joined: Mon Oct 13, 2008 12:00 am

Post by McMClark » Sun Oct 19, 2008 3:36 pm

That worked. Thank You for the quick responses.

Post Reply