急急急!请教各位大侠,用jfreeChart作曲线的时候,如果能使X座标的月份不重复出现呀?

alaxing 2004-12-28 07:03:58
我现在往jfreeChart里传入数据200401 200402 200403 200404四个月的数据,可
画出来的曲线的横座标会是

200312 200401 200401 200402 200402 200403 200403 200404 200404

如何使横坐标只显示四个月份呢?

要如何设置呢?头疼,哪里有文档下呀?
...全文
158 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
华生豆 2005-01-11
  • 打赏
  • 举报
回复
你用的曲线图还是柱状图,柱状图每个柱的宽度都可以定义的,曲线图也没发现有这个问题,我觉得可能是你数据源每次没有进行初始化,是不是第一次3个月,第二次就6个月,一直增加呢~~~

我做的一个如果只传一个值过去,就只会有一个点的啊~~~
tps1980 2005-01-11
  • 打赏
  • 举报
回复
JFreeChart的相关的介绍书籍和文档不多,我也不过刚接触了一个月左右,你还是多看看他的有关API吧!
alaxing 2005-01-05
  • 打赏
  • 举报
回复
谢谢谢谢tps1980,你的代码解决了我以前用数字做横轴时会出现小数的问题!!
没有文档,查不到坐标的设置方法,不知道哪里有这方面详细的描述!
我传的数据是没错的,比如显示三个月,我就只传了三行的数据,没有重复!
后来我又发现当图片比较小时,它显示没问题,当图片比较大里,他就会自动重复月分,除非我传入更多月份的数据!
请问一下,ymm兄:
这个是因为你没有定义他的底边,如果你设定的是月线的话,你应加一条无条底边,让他加12条记录,这样的话,你就可以看到一个完整的图啦
请问一下如何加无条底边呀!!


ymm 2005-01-04
  • 打赏
  • 举报
回复
这个是因为你没有定义他的底边,如果你设定的是月线的话,你应加一条无条底边,让他加12条记录,这样的话,你就可以看到一个完整的图啦
fengfengjunjun 2005-01-04
  • 打赏
  • 举报
回复
jfrrchart的文档是要钱的

还有,这个肯定是你在处理她的数据源的时候没有处理好,要不不会出现这种问题的。
我就用这个的啊
要显示几个月就几个月,一点问题都没有 的

看一下你的datasource
tps1980 2005-01-04
  • 打赏
  • 举报
回复
这个问题肯定是这位朋友的数据源没处理好,数据的处理,一般都是数据源的问题.下面给出一个例子,你可以看看,这才是正确的数据源的处理啊

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardLegend;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.LineAndShapeRenderer;
import org.jfree.data.CategoryDataset;
import org.jfree.data.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.labels.ItemLabelPosition;
/**
* A simple demonstration application showing how to create a line chart using data from a
* {@link CategoryDataset}.
*/
public class LineChartDemo1 extends ApplicationFrame {

/**
* Creates a new demo.
*
* @param title the frame title.
*/
public LineChartDemo1(final String title) {
super(title);
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new Dimension(500, 270));
setContentPane(chartPanel);
}

/**
* Creates a sample dataset.
*
* @return The dataset.
*/
private CategoryDataset createDataset() {

// row keys...
final String series1 = "A厂";
final String series2 = "B厂";
final String series3 = "C厂";

// column keys...
final String type1 = "一季度";
final String type2 = "二季度";
final String type3 = "三季度";
final String type4 = "四季度";

// create the dataset...
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();

dataset.addValue(10, series1, type1);
dataset.addValue(15, series1, type2);
dataset.addValue(18, series1, type3);
dataset.addValue(11, series1, type4);

dataset.addValue(17, series2, type1);
dataset.addValue(22, series2, type2);
dataset.addValue(13, series2, type3);
dataset.addValue(25, series2, type4);

dataset.addValue(7, series3, type1);
dataset.addValue(13, series3, type2);
dataset.addValue(19, series3, type3);
dataset.addValue(28, series3, type4);

return dataset;

}

/**
* Creates a sample chart.
*
* @param dataset a dataset.
*
* @return The chart.
*/
private JFreeChart createChart(final CategoryDataset dataset) {

// create the chart...
final JFreeChart chart = ChartFactory.createLineChart(
"折线图示例1", // chart title
null, // domain axis label
"利润", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
true, // include legend
true, // tooltips
false // urls
);

// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
final StandardLegend legend = (StandardLegend) chart.getLegend();
legend.setDisplaySeriesShapes(true);
legend.setShapeScaleX(1.5);
legend.setShapeScaleY(1.5);
//legend.setTitle("示例");
legend.setDisplaySeriesLines(true);

chart.setBackgroundPaint(Color.lightGray);

final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.white);
plot.setRangeGridlinePaint(Color.black);

// customise the range axis...
final double aa;
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
rangeAxis.setAutoRangeIncludesZero(true);

final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setDrawShapes(true);
renderer.setShapesFilled(true);
renderer.setPositiveItemLabelPosition(new ItemLabelPosition());
renderer.setNegativeItemLabelPosition(new ItemLabelPosition());

return chart;
}

/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(final String[] args) {

final LineChartDemo1 demo = new LineChartDemo1("Line Chart Demo");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);

}

}

你可以把代码拷下来运行一下,看看.
alaxing 2005-01-03
  • 打赏
  • 举报
回复
没人回答呀??

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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