如何设置使用 ChartFactory.createBarChart 创建的条形图的 Y 轴范围

How to set Y axis range of of BarGraph created using ChartFactory.createBarChart

我使用以下代码使用 jfree.chart.ChartFactory 创建了一个条形图。我需要将Y轴的范围设置为0-100。如何设置最大值。

import java.io.File;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

public class BarGraph
{
    public static void main( String[ ] args )throws Exception 
    {
       final DefaultCategoryDataset dataset = new DefaultCategoryDataset( );
       dataset.addValue( 10 , "FIAT" , "Speed");
       dataset.addValue( 30 , "AUDI", "Speed");
       dataset.addValue( 20 , "FORD", "Speed");
       dataset.addValue( 50 , "BMW", "Speed");
       JFreeChart barChart = ChartFactory.createBarChart3D(
           "CAR USAGE STATISTICS", 
           "Category", "Score", 
           dataset,PlotOrientation.VERTICAL, 
           true, true, false);
       int width = 380; /* Width of the image 480*/
       int height = 280; /* Height of the image 360*/ 
       File BarChart = new File( "../ELec/WebContent/img/BarChart.jpeg" ); 
       ChartUtilities.saveChartAsJPEG( BarChart , barChart , width , height   );
      }
  }

这是我得到的输出。我需要将 Y 轴最大值设置为 100:

在绘图的范围轴上调用 setRange() 以设置特定范围并关闭自动调整范围:

CategoryPlot plot = (CategoryPlot) barChart.getPlot();
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setRange(0, 100);