我正在尝试在JscrollPane中添加ChartPanel,并仅在需要时使水平滚动条可见。当图表中的列太多时,我希望它的面板比框架更宽,并使水平滚动条可见。我还希望在图表中的条形之间有最小间隙。我发布我的代码,没有滚动条,没有条形之间的最小间隙。所以我的问题是: 如何在酒吧之间设置精确的差距? 如果在框架宽度上有太多条形表示,如何使水平滚动可见?
package view;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.SpringLayout;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
public class StatisticsPanel extends AbstractCenterPanel {
private static final long serialVersionUID = 1L;
private final ChartPanel chartPanel;
public StatisticsPanel(final Map<Calendar, Integer> cashMap) {
super();
final SimpleDateFormat df = new SimpleDateFormat("dd/MM", Locale.ITALY);
final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (Entry<Calendar, Integer> e : cashMap.entrySet()) {
dataset.setValue(e.getValue(), "Incasso", df.format(e.getKey().getTime()));
}
final JFreeChart chart = ChartFactory.createBarChart("Andamento degli incassi", "Data", "Incasso (€)", dataset, PlotOrientation.VERTICAL, false, true, false);
this.chartPanel = new ChartPanel(chart);
final SpringLayout layout = new SpringLayout();
this.setLayout(layout);
layout.putConstraint(SpringLayout.WEST, this.chartPanel, 0, SpringLayout.WEST, this);
layout.putConstraint(SpringLayout.NORTH, this.chartPanel, 0, SpringLayout.NORTH, this);
layout.putConstraint(SpringLayout.EAST, this.chartPanel, 0, SpringLayout.EAST, this);
layout.putConstraint(SpringLayout.SOUTH, this.chartPanel, 350, SpringLayout.NORTH, this);
this.add(this.chartPanel);
}
}