jfreechart

设定y轴的显示格式
public static JFreeChart createChart(CategoryDataset categoryDataset) { 
        // 创建JFreeChart对象:ChartFactory.createLineChart  
        JFreeChart jfreechart = ChartFactory.createLineChart("Antibody Titration", // 标题  
                "Antibody dilution (X1000)", // categoryAxisLabel (category轴,横轴,X轴标签)  
                "OD 450", // valueAxisLabel(value轴,纵轴,Y轴的标签)  
                categoryDataset, // dataset  
                PlotOrientation.VERTICAL, true, // legend  
                false, // tooltips  
                false); // URLs  
        // 使用CategoryPlot设置各种参数。以下设置可以省略。  
        CategoryPlot plot = (CategoryPlot)jfreechart.getPlot(); 
        // 背景色 透明度  
        plot.setBackgroundAlpha(0.5f); 
        //设置网格横线颜色   
        plot.setBackgroundPaint(Color.white); 
        plot.setRangeGridlinePaint(Color.black); 
        // 前景色 透明度  
        plot.setForegroundAlpha(1.0f); 

//获得操作y轴的方式
        NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis();
        //设置纵坐标值的间距为0.5
        numberaxis.setTickUnit(new NumberTickUnit(0.50));
        //设置纵坐标值范围为0-4
        numberaxis.setRangeWithMargins(0, 4);
//设定y轴的显示方式,0.00,0.00%,0,0%对应11.11,11.11%,11,11%
        DecimalFormat de = new DecimalFormat("0.00");
        numberaxis.setNumberFormatOverride(de);
//
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        // 其他设置 参考 CategoryPlot类  
        LineAndShapeRenderer renderer = (LineAndShapeRenderer)plot.getRenderer(); 
        renderer.setBaseShapesVisible(true); // series 点(即数据点)可见  
        renderer.setBaseLinesVisible(true); // series 点(即数据点)间有连线可见  
        renderer.setUseSeriesOffset(true); // 设置偏移量  
        renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); 
        renderer.setBaseItemLabelsVisible(false); 
        return jfreechart; 
    }

你可能感兴趣的:(jfreechart)