我增加了一个JFreeChart转到JPanel(使用BorderLayout),而且是.巨量..我能做些什么让它变小吗?public void generateChart(){
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
//set the values of the chart
for(int i=0; i<8; i++)
{
dataset.setValue(income_array[i], "Income",
Double.toString(percent_array[i]));
}
JFreeChart chart = ChartFactory.createBarChart(
"Required Annual Income for a Variety of Interest Rates",
"Percent", "Income", dataset, PlotOrientation.VERTICAL,
false,true, false);
ChartPanel cp = new ChartPanel(chart);
chart.setBackgroundPaint(Color.white);
chart.getTitle().setPaint(Color.black);
CategoryPlot p = chart.getCategoryPlot();
p.setRangeGridlinePaint(Color.blue);
//cp.setMaximumDrawHeight(5);
//cp.setMaximumDrawWidth(5);
//cp.setZoomOutFactor(.1);
JPanel graph = new JPanel();
graph.add(cp);
middle.add(graph, BorderLayout.CENTER);}
3 回答
收到一只叮咚
TA贡献1821条经验 获得超5个赞
ChartPanel
接受 DEFAULT_WIDTH和 DEFAULT_HEIGHT*680 x 420。 指定首选 width和 height在构造函数中。 调用 setPreferredSize()显式 适当 .覆盖 getPreferredSize()以动态计算大小。 @Overridepublic Dimension getPreferredSize() { // given some values of w & h return new Dimension(w, h);}选择 布局 的容器的 ChartPanel将被添加。注意,默认布局为 JPanel是 FlowLayout,而 JFrame是 BorderLayout..作为一个具体的例子, ThermometerDemo在构造函数中同时使用首选值和 GridLayout使容器允许动态调整大小。
叮当猫咪
TA贡献1776条经验 获得超12个赞
private PieDataset updateCSFDataSet(){
DefaultPieDataset dataSet = new DefaultPieDataset();
dataSet.setValue("Clear(" + clearCount + ")" , clearCount);
dataSet.setValue("Smoky(" + smokyCount + ")", smokyCount);
dataSet.setValue("Foggy(" + foggyCount + ")", foggyCount);
dataSet.setValue("Skipped(" + skipCount + ")", skipCount);
dataSet.setValue("Unlabeled(" + unlabeledCount + ")", unlabeledCount);
return dataSet;
}
private ImageIcon createChart(String title, PieDataset dataSet){
JFreeChart chart = ChartFactory.createPieChart(
title,
dataSet,
true,
false,
false
);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
plot.setNoDataMessage("No data available");
plot.setCircular(true);
plot.setIgnoreZeroValues(true);
plot.setLabelGap(0.02);
return new ImageIcon(chart.createBufferedImage(400,300));
}添加回答
举报
0/150
提交
取消
