Setting a point as a different color in XY plot

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Stellios

Setting a point as a different color in XY plot

Post by Stellios » Tue Aug 13, 2002 1:39 am

I have a timeseries (XY plot), and I want to set at certain positions in the time series a small box or something characteristic in a different color as an indicator, is that possible?

josh

Re: Setting a point as a different color in XY plot

Post by josh » Tue Aug 13, 2002 2:59 pm

i did this. it requires alteration of xyplot. i first created a method called setClickedPeak:

public void setClickedPeak(double value){
mouseClicked=true;
clickedX=value;
XYDataset data=this.getDataset();
if(data.getItemCount(0)<1)
return;
int mostAccurateIndex=0;
double mostAccurateValue=1.0;
for(int i=0;i<data.getItemCount(0);i++){
Double D=(Double)data.getXValue(0,i);
double accuracy=Math.abs((D.doubleValue()-clickedX)/D.doubleValue()); //compute formula

if(accuracy<mostAccurateValue){
mostAccurateValue=accuracy;
mostAccurateIndex=i;
}//if
}//for
clickedX=((Double)data.getXValue(0,mostAccurateIndex)).doubleValue();
}

not sure if that diplayed properly, but you can copy and paste and format it to read it if not. then in the draw method add the code between the "////////JPD" lines:

int seriesCount = data.getSeriesCount();
for (int series=0; series<seriesCount; series++) {
int itemCount = data.getItemCount(series);
for (int item=0; item<itemCount; item++) {

//////////////////////////////JPD
if(mouseClicked&&((Double)data.getXValue(series,item)).doubleValue()==clickedX){
mouseClicked=false;
this.setSeriesPaint(new Paint[] { Color.yellow});
}
else this.setSeriesPaint(new Paint[]{Color.green});
////////////////////////////////JPD

Shape tooltipArea = renderer.drawItem(g2, dataArea, info, this,
(ValueAxis)horizontalAxis,
(ValueAxis)verticalAxis,
data, series, item,
transRangeZero, crosshairInfo);

i change one peak to yellow (the "selected" peak) and the other are green. the next time the chart redraws this peak will be yellow.

i have this set up where i can manually call setClickedPeak, where you have to do a xyplot.propertyChange(null) to get the chart to redraw. to get a peak to change by itself when clicked just add a setClickedPeak call in the handleClick method in XYPlot. confusing enough?

Stellios

Re: Setting a point as a different color in XY plot

Post by Stellios » Thu Aug 15, 2002 6:54 am

Cool, thanks - will try it ASAP. What I did for now is an overlaid chart with XYPlot and a chart.SignalChart and stuck Up Arrows at the points I wanted to highlight.

Locked