jfreecharts中不合适的x轴标签视图。

时间:2015-02-09 10:08:41

标签: java graph awt jfreechart

我的jfreechart图有问题。实际上在x轴处,该值是大数(即1500-2000)并且这些值的量也太大(即,以显着的表示法)。因此图表仅显示虚线而不是x轴处的值

public static byte[] createImageByXyChart(String str_chartLabel,
        String str_xAxisLabel, String str_yAxisLabel,
        String str_fileFormat, Integer i_height, Integer i_width,
        List<double[]> co_ordinates) throws IOException {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < co_ordinates.size(); i++) {
        double[] xy_coOrdinates = co_ordinates.get(i);
        double xCoordiate = xy_coOrdinates[0];
        double yCoordiate = xy_coOrdinates[1];
        dataset.setValue(yCoordiate, str_chartLabel, "" + xCoordiate);

}

      JFreeChart chart =
     ChartFactory.createLineChart(str_chartLabel,str_xAxisLabel,
     str_yAxisLabel, dataset);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangePannable(true);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlineStroke(new BasicStroke(1.0f));
    plot.setRangeGridlineStroke(new BasicStroke(1.0f));
    plot.setDomainGridlinePaint(Color.GRAY.brighter());
    plot.setRangeGridlinePaint(Color.GRAY.brighter());

    ChartPanel panel = new ChartPanel(chart);

    JFrame frame = new JFrame("Show chart");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);

    frame.setSize(600, 600);
    frame.setVisible(true);

    return null;
}
public static void main(String[] arg) throws Exception {

    System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@  ");
    File fileData = new File("curve.txt");

    BufferedReader br = new BufferedReader(new FileReader(fileData));
    List<double[]> co_ordinates = new ArrayList<double[]>();
    String line = null;

    while ((line = br.readLine()) != null) {

        String[] abcd = line.split(",");
        double[] xy_cor = new double[2];
        NumberFormat df = new DecimalFormat("######.####");
        xy_cor[0] = Double.parseDouble(df.format(Double
                .parseDouble(abcd[0])));
        System.out.println(xy_cor[0]);
        xy_cor[1] = Double.parseDouble(abcd[1]);

        System.out.println(Arrays.toString(xy_cor));
        co_ordinates.add(xy_cor);

    }

    br.close();



    String str_chartLaber = "Curve";
    String str_xAxisLabel = "Time(s)";
    String str_yAxisLaber = "Accelaration (mm_per__s_2)";
    String str_fileFormate = ImageFormats.JPEG;
    Integer heigth = 1800;
    Integer width = 1080;

    byte[] image_bytes = ImageUtils.createImageByXyChart(str_chartLaber,
            str_xAxisLabel, str_yAxisLaber, str_fileFormate, heigth, width,
            co_ordinates);

    }

it gives me this graph without x-axis values 输入数据是

标题

1 个答案:

答案 0 :(得分:0)

我用

XYDataset dataset ;

而不是

DefaultCategoryDataset dataset = new DefaultCategoryDataset();

XYDataset启用自动间隔,而DefaultCategoryDataset则没有。我不知道原因,但它是。