2

I'm using JFreeChart and I'd like have a Chart with one dimension only: a x-axis (that indicates milliseconds) and shapes (that rapresents events).

I created a XYLineChart and a XYPlot with hidden y-axis :

 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));

In the dataset I used a fixed y-coordinate.

I obtained this result:

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

But I'd like have something like this:

image 2

If I simply resize the Panel, the entire chart is resized (title, numbers, shapes). So I'd like resize the "grey area" only.

Obviously it's better if another and appropriate chart type exist.

Thanks a lot.

Community
  • 1
  • 1
themind24
  • 23
  • 5
  • Please edit your question to include an [sscce](http://sscce.org/) that implements one of the approaches shown [here](http://stackoverflow.com/a/10277372/230513). – trashgod May 03 '13 at 02:08

1 Answers1

0

The entire chart is resized in case its width / height is below a configurable threshold.

I have modified your example by adding the code for the ChartPanel and using the two methods ChartPanel.setMinimumDrawWidth(int) and ChartPanel.setMinimumDrawWidth(int) to set these thresholds.

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);
Uli
  • 1,390
  • 1
  • 14
  • 28
  • Does that answer your question? In such a case please mark your question as resolved. Thanks! – Uli Feb 04 '15 at 08:42