如何在jfree中从日志10切换到日志2 [英] How to switch from log 10 to log 2 in jfree

查看:44
本文介绍了如何在jfree中从日志10切换到日志2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JFree生成图表.以下是供您参考的图像.在图像中可见,当前比例基于10,因此x轴比例中有10,100,1000.可以将其更改为log2.因此,在log 2的情况下,可以看到2,4,8,16,32,64等.LogarithmicAxis.java类正用于呈现x轴.

I am using JFree to generate my chart. Below is the image for your reference. As visible in image current scale is based on 10 so 10,100,1000 are there in x-axis scale. Would it possible to change it to log 2. So in case of log 2 point would be visible 2,4,8,16,32, 64 and so on. Class LogarithmicAxis.java is being used for rendering x-axis.

请让我知道是否可能

下面的代码生成log 2比例尺,但是我不能垂直设置x轴点,这对我来说很重要.

Below code generate log 2 scale but I am not able to set x-axis point vertically which is very important for me.

public class TestHello {

/** @see http://stackoverflow.com/a/10353270/230513 */
private static void createFrame() {
    int N=22;
    XYSeries series = new XYSeries("Series");
    for (int i = 0; i <= N; i++) {
        System.out.println(Math.pow(2, i));
        Random r = new Random();
        double randomInt = r.nextInt(100) + 1;
        series.add(Math.pow(2, i),randomInt);
    }


    NumberAxis yAxis = new NumberAxis("Y");
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    LogAxis xAxis = new LogAxis("X");
    xAxis.setBase(2);
    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setVerticalTickLabels(true);




      JFreeChart chart = ChartFactory.createXYLineChart(
                "Text", "x", "y", new XYSeriesCollection(series),
                PlotOrientation.VERTICAL, true, true, false);
        final XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setDomainAxis(xAxis);
        plot.setRangeAxis(yAxis);

        final Marker start = new ValueMarker(60.0);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setLegendLine(new Line2D.Double(-20.0D, 0.0D, 20.0D, 0.0D));

        Shape square = new Rectangle2D.Double(-2.0, -2.0, 3.0, 3.0);
        renderer.setSeriesShape(0, square);
        plot.setRenderer(renderer);
        plot.addRangeMarker(start);

    JFrame frame = new JFrame("LogAxis Test");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(new ChartPanel(chart));
    frame.pack();
    frame.setVisible(true);
}

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            createFrame();
        }
    });
}

}

推荐答案

尝试使用 LogAxis 类而不是 LogarithmicAxis 类(出于历史原因,有两个)并在设置轴时调用 axis.setBase(2.0).

Try using the LogAxis class rather than the LogarithmicAxis class (there are two, for historical reasons) and call axis.setBase(2.0) when you set up the axis.

这篇关于如何在jfree中从日志10切换到日志2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆