0

I am creating JFreeChart as follows (see below). On the x axis I need to show around 1000 ticks. So, that's why I am putting JFreeChart into the JScrollPane. When I try to set the WIDTH of a chart panel to 2000, the plot is not sized proportionally. Is there any way to define the WIDTH of a plot (XYPlot).

    XYDataset dataset = createData(data);
    JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new Dimension(2000, this.height));
    JScrollPane scrl = new JScrollPane(chartPanel);     
    scrl.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 
    scrl.setViewportView(chartPanel);
    scrl.setPreferredSize(new Dimension(this.width, this.height));
    this.add(scrl);
Klausos Klausos
  • 15,308
  • 51
  • 135
  • 217

1 Answers1

0

So far I found an answer that helped solving the problem. However, maybe there is a better solution:

// The first step is to avoid scaling up a small chart.
// The value of "MaximumDrawWidth" should be large, for instance 4000
chartPanel.setMaximumDrawWidth(4000);  
// The second step is to set the width of a chart panel.
chartPanel.setPreferredSize(new Dimension(2000,this.height));
Klausos Klausos
  • 15,308
  • 51
  • 135
  • 217
  • [Don't use `setPreferredSize()` when you really mean to override `getPreferredSize()`](http://stackoverflow.com/q/7229226/230513). – trashgod Mar 25 '14 at 21:36