我希望
如果数据全0那0坐标还能在xy轴交界处,而不是水平显示全0数据,还是在最下面显示!不知道应该怎么修改啊
/* ------------------
* BarChartDemo4.java
* ------------------
* (C) Copyright 2003-2005, by Object Refinery Limited.
*
*/import java.awt.Color;
import java.awt.GradientPaint;import javax.swing.JPanel;import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;/**
* A bar chart with only two bars - here the 'maxBarWidth' attribute in the
* renderer prevents the bars from getting too wide.
*/
public class BarChartDemo4 extends ApplicationFrame { /**
* Creates a new demo instance.
*
* @param title the frame title.
*/
public BarChartDemo4(String title) { super(title); CategoryDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel); } /**
* Returns a sample dataset.
*
* @return The dataset.
*/
private static CategoryDataset createDataset() {
// row keys...
String series1 = "First";
// column keys...
String category1 = "Category 1";
String category2 = "Category 2";
// create the dataset...
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(0, series1, category1);
dataset.addValue(0, series1, category2);
return dataset;
}
/**
* Creates a sample chart.
*
* @param dataset the dataset.
*
* @return The chart.
*/
private static JFreeChart createChart(CategoryDataset dataset) {
// create the chart...
JFreeChart chart = ChartFactory.createBarChart3D(
"Bar Chart Demo", // chart title
"Category", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL,
true, // include legend
true, // tooltips?
false // URLs?
); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart...
chart.setBackgroundPaint(new Color(0xBBBBDD)); // get a reference to the plot for further customisation...
CategoryPlot plot = (CategoryPlot) chart.getPlot();
// set the range axis to display integers only...
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines...
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setDrawBarOutline(false);
renderer.setMaximumBarWidth(0.10);
// set up gradient paints for series...
GradientPaint gp0 = new GradientPaint(
0.0f, 0.0f, Color.blue,
0.0f, 0.0f, Color.lightGray
);
GradientPaint gp1 = new GradientPaint(
0.0f, 0.0f, Color.green,
0.0f, 0.0f, Color.lightGray
);
renderer.setSeriesPaint(0, gp0);
renderer.setSeriesPaint(1, gp1);
rangeAxis.setAutoTickUnitSelection(false);
// NumberTickUnit nt= new NumberTickUnit(0);
// rangeAxis.setTickUnit(nt);
//
// rangeAxis.setFixedAutoRange(0);
// OPTIONAL CUSTOMISATION COMPLETED.
return chart;
}
/**
* Creates a panel for the demo (used by SuperDemo.java).
*
* @return A panel.
*/
public static JPanel createDemoPanel() {
JFreeChart chart = createChart(createDataset());
return new ChartPanel(chart);
}
/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) { BarChartDemo4 demo = new BarChartDemo4("Bar Chart Demo 4");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true); }}
如果数据全0那0坐标还能在xy轴交界处,而不是水平显示全0数据,还是在最下面显示!不知道应该怎么修改啊
/* ------------------
* BarChartDemo4.java
* ------------------
* (C) Copyright 2003-2005, by Object Refinery Limited.
*
*/import java.awt.Color;
import java.awt.GradientPaint;import javax.swing.JPanel;import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.NumberTickUnit;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;/**
* A bar chart with only two bars - here the 'maxBarWidth' attribute in the
* renderer prevents the bars from getting too wide.
*/
public class BarChartDemo4 extends ApplicationFrame { /**
* Creates a new demo instance.
*
* @param title the frame title.
*/
public BarChartDemo4(String title) { super(title); CategoryDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel); } /**
* Returns a sample dataset.
*
* @return The dataset.
*/
private static CategoryDataset createDataset() {
// row keys...
String series1 = "First";
// column keys...
String category1 = "Category 1";
String category2 = "Category 2";
// create the dataset...
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(0, series1, category1);
dataset.addValue(0, series1, category2);
return dataset;
}
/**
* Creates a sample chart.
*
* @param dataset the dataset.
*
* @return The chart.
*/
private static JFreeChart createChart(CategoryDataset dataset) {
// create the chart...
JFreeChart chart = ChartFactory.createBarChart3D(
"Bar Chart Demo", // chart title
"Category", // domain axis label
"Value", // range axis label
dataset, // data
PlotOrientation.VERTICAL,
true, // include legend
true, // tooltips?
false // URLs?
); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart...
chart.setBackgroundPaint(new Color(0xBBBBDD)); // get a reference to the plot for further customisation...
CategoryPlot plot = (CategoryPlot) chart.getPlot();
// set the range axis to display integers only...
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines...
BarRenderer renderer = (BarRenderer) plot.getRenderer();
renderer.setDrawBarOutline(false);
renderer.setMaximumBarWidth(0.10);
// set up gradient paints for series...
GradientPaint gp0 = new GradientPaint(
0.0f, 0.0f, Color.blue,
0.0f, 0.0f, Color.lightGray
);
GradientPaint gp1 = new GradientPaint(
0.0f, 0.0f, Color.green,
0.0f, 0.0f, Color.lightGray
);
renderer.setSeriesPaint(0, gp0);
renderer.setSeriesPaint(1, gp1);
rangeAxis.setAutoTickUnitSelection(false);
// NumberTickUnit nt= new NumberTickUnit(0);
// rangeAxis.setTickUnit(nt);
//
// rangeAxis.setFixedAutoRange(0);
// OPTIONAL CUSTOMISATION COMPLETED.
return chart;
}
/**
* Creates a panel for the demo (used by SuperDemo.java).
*
* @return A panel.
*/
public static JPanel createDemoPanel() {
JFreeChart chart = createChart(createDataset());
return new ChartPanel(chart);
}
/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) { BarChartDemo4 demo = new BarChartDemo4("Bar Chart Demo 4");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true); }}
解决方案 »
- JAVA接口一个重要的优点就是它们限制了对象之间的交互?
- java ireport4.0.2打印在线等....
- 为什么无法找到资源文件?
- jdk1.6支持泛型 为什么在MyEclipse7.0中显示 parameterized types are only available if source level is 1.5
- Cokie在企业内部使用是否合适,如果不合适的话,可以采取什么其他办法
- 求读取证书文件信息的源代码示例
- 高分求救高手:实际项目问题
- layout用null好像很舒服
- 三百分求一反编译器
- java问题???
- swing 界面中文显示乱码
- JFreeChart画折线图零刻度在Y轴的中间的问题
并且
rangeAxis.setUpperBound(10.0);
否则虽然是0,0的柱子还是显示的很高!
并且
rangeAxis.setUpperBound(10.0);
否则虽然是0,0的柱子还是显示的很高!
并且
rangeAxis.setUpperBound(10.0);
否则虽然是0,0的柱子还是显示的很高!
numberaxis.setRange(0.0, maximum);maximum就是你后台定的参数。