JFreechart 笔记一

来源:互联网 发布:c语言判断质数 编辑:程序博客网 时间:2024/06/15 18:19


//1.折线图的Y轴如何自定义步长

JFreeChart chart = ChartFactory.createLineChart(

"材料价格曲线图", //折线图名称 

"期间", // 横坐标名称 

"平均价格", // 纵坐标名称

dataSet, // 数据 

PlotOrientation.VERTICAL, // 水平显示图像 

true, // include legend

true, // tooltips 

false // urls ); 


chart.setBackgroundPaint(new Color(231, 237, 242)); 

CategoryPlot categoryPlot = chart.getCategoryPlot(); 

**NumberAxis numAxis = (NumberAxis) categoryPlot.getRangeAxis(); 

numAxis.setTickUnit(new NumberTickUnit(1000));//设置Y轴间隔**


// X轴如何自定义步长 

NumberAxis domainAxis = (NumberAxis) categoryplot.getDomainAxis(); 

domainAxis.setTickLabelFont(new Font("", Font.PLAIN, 12)); 

domainAxis.setTickMarksVisible(true);// 標尺 

domainAxis.setUpperMargin(0.001); 

domainAxis.setLowerMargin(0); 

double unitT; 

if (dataXzE - dataXzS == 10) { 

unitT = 1d; 

else if (

dataXzE == 0) { unitT = 10d; 

else { 

unitT = (dataXzE - dataXzS) / 6d; 

} 


NumberTickUnit ntuT = new NumberTickUnit(unitT); 

domainAxis.setTickUnit(ntuT);




0 0