【问题标题】:JFreeChart: One Axis Distribution ChartJFreeChart:单轴分布图
【发布时间】:2013-05-03 00:19:05
【问题描述】:

我正在使用 JFreeChart,我想要一个只有一维的图表: x 轴(表示毫秒)和形状(表示事件)。

我创建了一个 XYLineChart 和一个带有隐藏 y 轴的 XYPlot:

 this.chart = ChartFactory.createXYLineChart(
     "","","",dataset,PlotOrientation.VERTICAL, false, true,false);

 XYPlot plot = (XYPlot) chart.getPlot();

 plot.setBackgroundPaint( Color.lightGray );
 plot.setDomainGridlinePaint( Color.white );
 plot.setRangeGridlinePaint( Color.white );
 plot.setRangeGridlinesVisible(false);
 plot.setDomainCrosshairVisible( true );
 plot.setRangeCrosshairVisible( false ); 

 NumberAxis range = (NumberAxis) plot.getRangeAxis();
 range.setVisible(false);
 range.setRange(0.0, 1.0);
 range.setTickUnit(new NumberTickUnit(0.5));

在数据集中,我使用了固定的 y 坐标。

我得到了这个结果:

image 1 http://imageshack.us/a/img46/4935/pointsuw.jpg

但我想要这样的东西:

如果我只是调整面板的大小,整个图表都会调整大小(标题、数字、形状)。 所以我只想调整“灰色区域”的大小。

显然,如果存在另一种合适的图表类型会更好。

非常感谢。

【问题讨论】:

  • 请编辑您的问题以包含一个sscce,该sscce 实现了here 中显示的方法之一。

标签: jfreechart


【解决方案1】:

如果其宽度/高度低于可配置的阈值,则会调整整个图表的大小。

我通过添加 ChartPanel 的代码并使用 ChartPanel.setMinimumDrawWidth(int)ChartPanel.setMinimumDrawWidth(int) 两种方法来设置这些阈值来修改您的示例。

this.chart = ChartFactory.createXYLineChart(
 "","","",dataset,PlotOrientation.VERTICAL, false, true,false);

XYPlot plot = (XYPlot) chart.getPlot();

plot.setBackgroundPaint( Color.lightGray );
plot.setDomainGridlinePaint( Color.white );
plot.setRangeGridlinePaint( Color.white );
plot.setRangeGridlinesVisible(false);
plot.setDomainCrosshairVisible( true );
plot.setRangeCrosshairVisible( false ); 

NumberAxis range = (NumberAxis) plot.getRangeAxis();
range.setVisible(false);
range.setRange(0.0, 1.0);
range.setTickUnit(new NumberTickUnit(0.5));

ChartPanel chartPanel = new ChartPanel(this.chart);
chart.setMinimumDrawHeight(10);
chart.setMinimumDrawWidth(10);

【讨论】:

  • 这能回答你的问题吗?在这种情况下,请将您的问题标记为已解决。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-26
  • 1970-01-01
  • 2012-12-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多