By look it at your FAQ, it is said that it is possible to change the chart color by overriding the "getItemPaint" method. I am trying to do that for creating a custom XYBlockRenderer ; however, overriding the method does nothing.
So, thanks to github, I looked at the code of XYBlockRenderer , and I saw something weird in the "drawItem" method :
Code: Select all
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state,
Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
int series, int item, CrosshairState crosshairState, int pass) {
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
double z = 0.0;
if (dataset instanceof XYZDataset) {
z = ((XYZDataset) dataset).getZValue(series, item);
}
Paint p = this.paintScale.getPaint(z); =====> By doing that, behaviour cannot be modified by user : the block renderer will always take the corresponding color in the lookup.
According to me, to respect the use of "getItemPaint", XYBlockRenderer should have a method like this :
Code: Select all
/**
* Daivy Merlijs (08-05-2017)
* XYBlockRenderer should use this function instead of using directly the paintscale, so user can override if he wants and modify the behaviour.
* @param series the series index
* @param item the item index
*/
@Override
public Paint getItemPaint(int series, int item)
{
return this.paintScale.getPaint(((XYZDataset) this.getPlot().getDataset()).getZValue(series, item));
}
Code: Select all
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state,
Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset,
int series, int item, CrosshairState crosshairState, int pass) {
double x = dataset.getXValue(series, item);
double y = dataset.getYValue(series, item);
double z = 0.0;
double transX = domainAxis.valueToJava2D(x, dataArea,
plot.getDomainAxisEdge());
double transY = rangeAxis.valueToJava2D(y, dataArea,
plot.getRangeAxisEdge());
if (dataset instanceof XYZDataset) {
z = ((XYZDataset) dataset).getZValue(series, item);
}
Paint p = this.getItemPaint(series, item); =====> By doing that, behaviour user can modifiy the behaviour by overriding the getItemPaint method.
}