2

Since a picture is worth a thousand words, I'll show you.

This is what I have:

old

This is what I need:

new

Some code maybe useful:

private JFreeChart createChart (XYDataset dataset)
{
    ValueAxis radiusAxis = new NumberAxis ();
    radiusAxis.setTickLabelsVisible (false);

    //   Rendering serie ( handeling null values )
    DefaultPolarItemRenderer ren = new DefaultPolarItemRenderer ()
    {
        @Override
        public void drawSeries (Graphics2D g2, Rectangle2D dataArea,
            PlotRenderingInfo info, PolarPlot plot, XYDataset dataset, int seriesIndex)
        {
            boolean newPath = true;
            GeneralPath polyline = new GeneralPath ();
            int numPoints = dataset.getItemCount (seriesIndex);
            for (int i = 0 ; i < numPoints - 1 ; i++)
            {
                double theta = dataset.getXValue (seriesIndex, i);
                double radius = dataset.getYValue (seriesIndex, i);
                Point p = plot.translateValueThetaRadiusToJava2D (theta, radius,
                        dataArea);
                if (p.x == 0 && p.y == 0)
                {
                    newPath = true;
                }
                else
                {
                    if (newPath)
                    {
                        polyline.moveTo (p.x, p.y);
                        newPath = false;
                    }
                    else
                    {
                        polyline.lineTo (p.x, p.y);
                    }
                }
            }
            g2.setPaint (lookupSeriesPaint (seriesIndex));
            g2.setStroke (lookupSeriesStroke (seriesIndex));
            g2.draw (polyline);
        }
    };

    // removing fill serie
    ren.setSeriesFilled (0, false);


    // custimizing angles
    PolarPlot plot = new PolarPlot (dataset, radiusAxis, ren)
    {
        @Override
        protected java.util.List refreshAngleTicks ()
        {
            java.util.List ticks = new ArrayList ();

            ticks.add (new NumberTick (0, "12AM", TextAnchor.CENTER, TextAnchor.TOP_LEFT, 0));
            ticks.add (new NumberTick (30, "2AM", TextAnchor.TOP_LEFT, TextAnchor.TOP_RIGHT, 0));
            ticks.add (new NumberTick (60, "4AM", TextAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, 0));
            ticks.add (new NumberTick (90, "6AM", TextAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, 0));
            ticks.add (new NumberTick (120, "8AM", TextAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, 0));
            ticks.add (new NumberTick (150, "10AM", TextAnchor.TOP_LEFT, TextAnchor.TOP_LEFT, 0));
            ticks.add (new NumberTick (180, "12PM", TextAnchor.CENTER, TextAnchor.TOP_LEFT, 0));
            ticks.add (new NumberTick (210, "2PM", TextAnchor.TOP_RIGHT, TextAnchor.TOP_LEFT, 0));
            ticks.add (new NumberTick (240, "4PM", TextAnchor.TOP_RIGHT, TextAnchor.TOP_LEFT, 0));
            ticks.add (new NumberTick (270, "6PM", TextAnchor.TOP_RIGHT, TextAnchor.TOP_LEFT, 0));
            ticks.add (new NumberTick (300, "8PM", TextAnchor.TOP_RIGHT, TextAnchor.TOP_LEFT, 0));
            ticks.add (new NumberTick (330, "10PM", TextAnchor.TOP_RIGHT, TextAnchor.TOP_LEFT, 0));

            return ticks;
        }
    };

    // colors..
    plot.setOutlinePaint (new Color (0, 0, 0, 0));
    plot.setBackgroundPaint (Color.white);
    plot.setRadiusGridlinePaint (Color.gray);
    ren.setShapesVisible (true);
    plot.setRadiusGridlinesVisible (true);
    plot.setAngleGridlinesVisible (true);
    plot.setAngleLabelsVisible (true);
    plot.setOutlineVisible (true);
    plot.setAngleGridlinePaint (Color.BLACK);
    plot.setRenderer (ren);

    JFreeChart chart = new JFreeChart ("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint (Color.white);
    chart.setBorderVisible (false);
    chart.setBorderPaint (Color.RED);

    // showing Label Axis ( 0 ... 20 ... 30 ...40)
    NumberAxis rangeAxis = (NumberAxis) plot.getAxis ();
    rangeAxis.setTickLabelsVisible (true);

    rangeAxis.setAxisLinePaint (Color.RED);
    return chart;
}

As you can see, I want to change Axis Line angle; I don't know how to proceed.

Thank you.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Skazi
  • 66
  • 6
  • Cross-posted [here](http://www.jfree.org/forum/viewtopic.php?f=3&t=116432). See also this [Q&A](http://stackoverflow.com/q/3458824/230513). – trashgod Mar 06 '13 at 19:23
  • You might want to highlight the difference between the two images. I am not entirely convinced there is one. – mbatchkarov Mar 06 '13 at 20:06
  • thank you for your feedback, if you notice I want to change axis line angle (in this example from 6AM to 4AM). Any ideas would be greatly appreciated – Skazi Mar 06 '13 at 23:15
  • Would `DialPlot` be appropriate? – trashgod Mar 09 '13 at 04:58

1 Answers1

0

You don't mention the used version of JFreeChart but JFreeChart 1.0.14 got some improvements for polarcharts. You can set an angle-offset via PolarPlot.setAngleOffset() which allows to start with 12am at whatever position you like.

However, the axes themselves cannot be at arbitrary angles but only at north, east, south or west. This can be set using PolarPlot.setAxisLocation().

hth,
- martin

Martin Höller
  • 2,714
  • 26
  • 44