急!jfreechart的setAutoTickUnitSelection(false)为何无效啊

mxx123 2010-01-29 04:27:01
请大虾们帮忙解决下,
小弟在生成图标时遇到一个问题,
我想图标的横轴只显示纵轴有数据的标签,比如20060101这个日期有数据就显示,而20060106这个日期没数据就不显示。
可我图表里横轴的时间标签是把每个月平分为若干个时间点,出现了没有数据点时间也显示了横轴标签的问题。
我的代码如下

charti[i] = ChartFactory.createTimeSeriesChart("统计时间线", "月份",
"值", lineDatasets[i], true, true, true);
// 设置标题
charti[i].setTitle(new TextTitle("\"" + md + bkn[i]
+ "\"指标值示意图", new Font("雅黑", Font.BOLD, 25)));
// 设置图表部分
charti[i].setTextAntiAlias(true);

charti[i].setBackgroundPaint(Color.white);
XYPlot plot = (XYPlot) charti[i].getPlot();
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) plot
.getRenderer();
// 设置曲线是否显示数据点
xylineandshaperenderer.setBaseShapesVisible(true);
// 设置曲线显示各数据点的值
XYItemRenderer xyitem = plot.getRenderer();
xyitem.setBaseItemLabelsVisible(true);
xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
xyitem
.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));

plot.setRenderer(xyitem);
plot.getDomainAxis()
.setLabelFont(new Font("宋体", Font.BOLD, 15));
plot.getDomainAxis().setTickLabelFont(
new Font("宋体", Font.BOLD, 10));
plot.getRangeAxis().setLabelFont(new Font("宋体", Font.BOLD, 15));
plot.getRangeAxis().setTickLabelFont(
new Font("宋体", Font.BOLD, 10));
plot.getRangeAxis().setLabelAngle(1.6);

charti[i].getLegend().setItemFont(
new Font("宋体", Font.PLAIN, 10)); // 设置最底下方框内的字体(图示)
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new java.text.SimpleDateFormat(
"yyyyMMdd"));
// 关键点
axis.setAutoTickUnitSelection(false);//

axis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1));

charti[i].setAntiAlias(true);
...全文
270 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
mxx123 2010-02-01
  • 打赏
  • 举报
回复
先谢谢楼上的支持,不过我现在的是时间序列图里的,不是柱状图的啊!
sotom 2010-01-30
  • 打赏
  • 举报
回复
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="org.jfree.chart.ChartFactory"%>
<%@ page import="org.jfree.chart.JFreeChart"%>
<%@ page import="org.jfree.chart.plot.PlotOrientation"%>
<%@ page import="org.jfree.chart.servlet.ServletUtilities"%>
<%@ page import="org.jfree.data.category.DefaultCategoryDataset"%>
<%@ page import="org.jfree.data.general.DatasetUtilities"%>
<%@ page import="org.jfree.data.category.CategoryDataset"%>

<%@ page import="org.jfree.chart.renderer.category.BarRenderer3D"%>
<%@ page import="java.awt.Color"%>
<%@ page import="org.jfree.chart.plot.CategoryPlot"%>
<%@ page import="org.jfree.chart.axis.ValueAxis"%>
<%@ page import="org.jfree.chart.axis.AxisLocation"%>
<%@ page
import="org.jfree.chart.labels.StandardCategoryItemLabelGenerator"%>
<%@ page import="org.jfree.chart.axis.*"%>
<%@ page import="org.jfree.chart.axis.CategoryAxis"%>

<%
double[][] data = new double[][] { { 672, 766, 223, 540, 126 }, { 325, 521, 210, 340, 106 },
{ 332, 256, 523, 240, 526 } };
String[] rowKeys = { "苹果", "梨子", "葡萄" };
String[] columnKeys = { "北京", "上海", "广州", "成都", "深圳" };
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);

JFreeChart chart = ChartFactory.createBarChart3D("水果销量图统计", null, null, dataset, PlotOrientation.VERTICAL,
true, false, false);
chart.setBackgroundPaint(Color.WHITE);
CategoryPlot plot = chart.getCategoryPlot();

CategoryAxis domainAxis = plot.getDomainAxis();

domainAxis.setVerticalCategoryLabels(false);

//domainAxis.setVerticalCategoryLabels(true);

plot.setDomainAxis(domainAxis);

ValueAxis rangeAxis = plot.getRangeAxis();
//设置最高的一个 Item 与图片顶端的距离
rangeAxis.setUpperMargin(0.15);
//设置最低的一个 Item 与图片底端的距离
rangeAxis.setLowerMargin(0.15);
plot.setRangeAxis(rangeAxis);

BarRenderer3D renderer = new BarRenderer3D();
renderer.setBaseOutlinePaint(Color.BLACK);
//设置 Wall 的颜色
renderer.setWallPaint(Color.gray);
//设置每种水果代表的柱的颜色
renderer.setSeriesPaint(0, new Color(0, 0, 255));
renderer.setSeriesPaint(1, new Color(0, 100, 255));
renderer.setSeriesPaint(2, Color.GREEN);
//设置每个地区所包含的平行柱的之间距离
renderer.setItemMargin(0.1);
//显示每个柱的数值,并修改该数值的字体属性
renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setItemLabelsVisible(true);
plot.setRenderer(renderer);

//设置柱的透明度
plot.setForegroundAlpha(0.6f);
//设置地区、销量的显示位置
plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session);
String graphURL = request.getContextPath() + "/servlet/DisplayChart filename=" + filename;
%>
<img src="<%=graphURL%>" width=500 height=300 border=0
usemap="#<%= filename %>">


给你个能用的例子,自己对下吧。
crazylaa 2010-01-30
  • 打赏
  • 举报
回复
路过
Bleibo 2010-01-29
  • 打赏
  • 举报
回复
ding,
Bleibo 2010-01-29
  • 打赏
  • 举报
回复
顶顶顶顶顶
mxx123 2010-01-29
  • 打赏
  • 举报
回复
先自己顶下,我也设置了 axis.setAutoTickUnitSelection(false);//

axis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1));
可还是不行啊?这是咋回事啊?
内容概要:本文围绕水陆两栖无人机的任务规划与执行问题,提出了一种基于Matlab实现的智能路径规划解决方案,重点融合粒子群优化算法(PSO)与遗传算法(GA)进行三维环境下的避障路径规划。研究系统性地构建了从复杂地形建模、任务需求分析到算法设计与仿真实验的完整流程,实现了在多约束、动态障碍物等复杂环境下无人机的高效任务调度。通过对GA与PSO两种智能优化算法在路径长度、收敛速度、路径平滑度及稳定性等方面的对比分析,深入探讨了各自在无人机路径规划中的适用场景与性能差异,验证了所提方法在提升任务执行效率与安全性方面的有效性。该方案不仅适用于水陆交互通用场景,也为多模态无人系统自主导航提供了可扩展的技术框架。; 适合人群:具备一定Matlab编程能力和算法基础,从事无人机路径规划、智能优化算法研究、自动化控制或相关领域科研工作的研究生、科研人员及工程技术人员。; 使用场景及目标:①应用于水陆两栖无人机在复杂自然环境(如江河湖海与陆地交错区域)中的自主巡航与任务执行;②比较遗传算法与粒子群算法在三维动态路径规划中的优化性能,指导实际工程中算法选型;③为多约束条件下无人系统的自主决策与实时避障提供算法支持与仿真验证平台。; 阅读建议:建议读者结合提供的Matlab代码进行动手实践,重点关注两种算法的数学建模过程、适应度函数设计、参数调优策略及路径生成逻辑,通过仿真实验直观对比算法性能差异,深入理解智能优化算法在复杂路径规划问题中的应用机制与优化潜力。

67,535

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧