Idea to distinguish items in XYBlockRenderer

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
ekta1994
Posts: 26
Joined: Fri May 12, 2017 8:06 am
antibot: No, of course not.

Idea to distinguish items in XYBlockRenderer

Post by ekta1994 » Fri May 12, 2017 6:00 pm

I want to distinguish the blocks of XYZDataset renderer via XYBlockRenderer. Please see, they already have z values by which they get color. But what I need is something like adding label to each block, like a simple alphabet for labelling every block. Semantically I can say adding categories. Any ideas on how can this be done? Label generator does not exist for block renderer.

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Idea to distinguish items in XYBlockRenderer

Post by John Matthews » Sat May 13, 2017 1:18 am

If you're using a GrayPaintScale . Why not consider adding a splash of contrasting color for the problem range in a custom PaintScale?

ekta1994
Posts: 26
Joined: Fri May 12, 2017 8:06 am
antibot: No, of course not.

Re: Idea to distinguish items in XYBlockRenderer

Post by ekta1994 » Sat May 13, 2017 7:52 am

My use case is just labelling blocks in lets say three categories A,B,C. They already have some colors and adding some more to them may make them tough for user to comprehend. That's why something simple like a small text label I am searching . However, an example of you suggestion will be helpful.

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Idea to distinguish items in XYBlockRenderer

Post by John Matthews » Sun May 14, 2017 12:39 am

An org.jfree.chart.annotations.XYAnnotation might be another possibility.

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Re: Idea to distinguish items in XYBlockRenderer

Post by david.gilbert » Sun May 14, 2017 8:13 am

Item label support wasn't added to the renderer, I'm not sure why...but you can easily add it like this:

https://github.com/jfree/jfreechart/com ... 65e41b63b4
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

ekta1994
Posts: 26
Joined: Fri May 12, 2017 8:06 am
antibot: No, of course not.

Re: Idea to distinguish items in XYBlockRenderer

Post by ekta1994 » Wed May 31, 2017 1:09 pm

How to add annotations in graph plot when the renderer used is XY Block Renderer (XYZ dataset). I tried using plot.addAnnotation(x1,y1,x2,y2,stroke,color). But nothing i can see.

MrJack
Posts: 13
Joined: Thu May 18, 2017 3:41 pm
antibot: No, of course not.

Re: Idea to distinguish items in XYBlockRenderer

Post by MrJack » Wed May 31, 2017 3:22 pm

What david was saying is to override this methode like this :

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);
         double xx0 = domainAxis.valueToJava2D(x + this.xOffset, dataArea,
                 plot.getDomainAxisEdge());
         double yy0 = rangeAxis.valueToJava2D(y + this.yOffset, dataArea,
                 plot.getRangeAxisEdge());
         double xx1 = domainAxis.valueToJava2D(x + this.blockWidth
                 + this.xOffset, dataArea, plot.getDomainAxisEdge());
         double yy1 = rangeAxis.valueToJava2D(y + this.blockHeight
                 + this.yOffset, dataArea, plot.getRangeAxisEdge());
         Rectangle2D block;
         PlotOrientation orientation = plot.getOrientation();
         if (orientation.equals(PlotOrientation.HORIZONTAL)) {
             block = new Rectangle2D.Double(Math.min(yy0, yy1),
                     Math.min(xx0, xx1), Math.abs(yy1 - yy0),
                     Math.abs(xx0 - xx1));
         }
         else {
             block = new Rectangle2D.Double(Math.min(xx0, xx1),
                     Math.min(yy0, yy1), Math.abs(xx1 - xx0),
                     Math.abs(yy1 - yy0));
         }
         g2.setPaint(p);
         g2.fill(block);
         g2.setStroke(new BasicStroke(1.0f));
         g2.draw(block);
 
         if (isItemLabelVisible(series, item)) {
             drawItemLabel(g2, orientation, dataset, series, item, 
                     block.getCenterX(), block.getCenterY(), y < 0.0);
         }

         int datasetIndex = plot.indexOf(dataset);
         double transX = domainAxis.valueToJava2D(x, dataArea,
                 plot.getDomainAxisEdge());
         double transY = rangeAxis.valueToJava2D(y, dataArea,
                 plot.getRangeAxisEdge());        
         updateCrosshairValues(crosshairState, x, y, datasetIndex,
                 transX, transY, orientation);
 
         EntityCollection entities = state.getEntityCollection();
         if (entities != null) {
             addEntity(entities, block, dataset, series, item, 
                     block.getCenterX(), block.getCenterY());
         }
 
}
And after use the annotation.
David correct me if I'm wrong ^^

Locked