How to create a category chart with lines to x axis?

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
jt_swanson
Posts: 18
Joined: Sat Jun 02, 2012 6:12 pm
antibot: No, of course not.

How to create a category chart with lines to x axis?

Post by jt_swanson » Sat Sep 09, 2017 10:51 pm

I'm trying to create a chart like this one:

http://www.statmethods.net/stats/images/CooksD.png

I thought I wanted a CategoryPlot, I can create all aspects of the plot except having the lines from the data values to the x axis. I have something very close just going from the MinMaxCategoryPlotDemo1 example and using only two sets of values, i.e.,

Code: Select all

      DefaultCategoryDataset dataset = new DefaultCategoryDataset();
      dataset.addValue(1.0, "First", "(50/80)");
      dataset.addValue(4.0, "First", "(60/30)");
      dataset.addValue(3.0, "First", "(60/60)");
      dataset.addValue(5.0, "First", "(70/11)");
      dataset.addValue(5.0, "First", "(70/70)");
      dataset.addValue(7.0, "First", "(80/30)");
      dataset.addValue(0.0, "Secnd", "(50/80)");
      dataset.addValue(0.0, "Secnd", "(60/30)");
      dataset.addValue(0.0, "Secnd", "(60/60)");
      dataset.addValue(0.0, "Secnd", "(70/11)");
      dataset.addValue(0.0, "Secnd", "(70/70)");
      dataset.addValue(0.0, "Secnd", "(80/30)");
except I have circles drawn around the min and max values.

I don't have a lot of experience with the large collection of renderers available in JFreeChart so I am asking for some advice,

is it a smarter move to extend MinMaxCategoryRenderer and override drawItem, or is there a better renderer/plot type for handling the plot I am trying to create?

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: How to create a category chart with lines to x axis?

Post by paradoxoff » Sun Sep 10, 2017 6:15 pm

You could siwtch to an XYPlot. See this thread for an example.

jt_swanson
Posts: 18
Joined: Sat Jun 02, 2012 6:12 pm
antibot: No, of course not.

Re: How to create a category chart with lines to x axis?

Post by jt_swanson » Sun Sep 10, 2017 6:23 pm

Thanks,

My first attempt at extending MinMaxCategoryRenderer ran into the problem that drawItem uses a lot of private variables, so using it as a template for an alternate method doesn't seem practical.

I'll have a look at XYPlot.

I did get a partial workaround by creating basically a null icon, and using that for the min value. But the next plot I need to make can have positive and negative values, so not sure my workaround can handle that case.

Code: Select all

   public class EmptyIcon implements Icon
   {
      public EmptyIcon() {}

      public int getIconHeight()
      {
        return 0;
      }

      public int getIconWidth()
      {
        return 0;
      }

      public void paintIcon(Component c, Graphics g, int x, int y)
      {
         g.drawRect( 0, 0, 0, 0 );
      }
   }

      Icon emptyIcon = new EmptyIcon();

      renderer.setMinIcon( emptyIcon );

jt_swanson
Posts: 18
Joined: Sat Jun 02, 2012 6:12 pm
antibot: No, of course not.

Re: How to create a category chart with lines to x axis?

Post by jt_swanson » Mon Sep 11, 2017 5:16 pm

I decided not to use XYPlot as the basis for this, as I need a CategoryPlot. I ended up extending drawItem from a copy of MinMaxCategoryRenderer where I changed the variables to protected. I think I can possibly make it simpler than that, since none of the private variables appear to be used anywhere but in drawItem and some like objectIcon have getters.

Locked