Page 1 of 1
ColorGrid SeriesMouseListener
Posted: Mon Oct 13, 2008 2:48 pm
by 7669521
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
Posted: Mon Oct 13, 2008 3:06 pm
by narcis
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.
Posted: Tue Oct 14, 2008 12:00 pm
by 7669521
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.
Posted: Wed Oct 15, 2008 11:20 am
by Marc
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
Posted: Fri Oct 17, 2008 1:23 pm
by 7669521
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.
Posted: Fri Oct 17, 2008 2:16 pm
by narcis
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.
Posted: Sun Oct 19, 2008 3:36 pm
by 7669521
That worked. Thank You for the quick responses.