java - JfreeChart : changing axis line angle on polar chart

标签 java charts jfreechart

既然一张图胜过一千个字,我就给你看一下。

这就是我所拥有的:

old

这就是我需要的:

new

一些代码可能有用:

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;
}

如你所见,我想改变Axis线角度;我不知道如何继续。

谢谢。

最佳答案

您没有提到 JFreeChart 的使用版本,但 JFreeChart 1.0.14 对极坐标图进行了一些改进。您可以通过 PolarPlot.setAngleOffset() 设置角度偏移允许从凌晨 12 点在您喜欢的任何位置开始。

但是,轴本身不能是任意角度,而只能是北、东、南或西。这可以使用 PolarPlot.setAxisLocation() 设置.

第,
- 马丁

关于java - JfreeChart : changing axis line angle on polar chart,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15253159/

相关文章:

java - 如何在Java中使用v3数据Api插入YouTube channel 横幅?

java - Intellij 未检测到 Play 语法

javascript - amCharts - amMap 主页按钮方法

javascript - 按月份显示数据

charts - Google Charts 可以支持双 y 轴(v 轴)吗?

java - 如何使用 netbeans IDE 添加 jFreeChart 库?

java - 使用 RestFB 的安全性如何?

java - 如何从 jfreechart 中的盒须图中删除异常值(小圆圈)

java - 将 JFreeChart 添加到 JPanel

java - 我们可以动态添加带有 setter 和 getter 的类属性吗