jfreechart折线图x轴间距设置
转发请注明出处
将背景颜色设为白色,对max/10的整数倍的刻度对应下标设为黑色,其他仍设置为白色,达到间隔显示效果,但存在一定问题,x轴范围大时显示模糊,范围小时清晰度尚可,而且改变字体也不能改善。可以尝试换成时序图的方式来绘图,具体的请看我博客的其他文章。
public static void setDomainAxis(CategoryAxis domainAxis,int max){
domainAxis.setTickLabelFont(new Font("Times New Roman", Font.ITALIC, 12));
domainAxis.setLabelFont(new Font("Times New Roman", Font.ITALIC, 12));
domainAxis.setTickMarksVisible(true); //用于显示X轴标尺
domainAxis.setTickLabelsVisible(true); //用于显示X轴标尺值
for(int i = 0; i<max; i++)
{
//设置0-max显示10个刻度,可自选
if(i%(max/10) ==0)
{
domainAxis.setTickLabelPaint(Integer.toString(i), Color.black);
}else{
domainAxis.setTickLabelPaint(Integer.toString(i), Color.white);
}
}
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45); //设置X轴45度
}