⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showoilcan.java

📁 加入Jfreechart1.05直接运行即可.(立体圆柱表示水位效果)使用Jfreechart实现的层叠圆柱体效果.
💻 JAVA
字号:
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Paint;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.GradientPaintTransformType;
import org.jfree.ui.RefineryUtilities;
import org.jfree.ui.StandardGradientPaintTransformer;

import demo.CylinderRenderer;



/**
 * A simple demonstration application showing how to create a vertical 3D bar
 * chart using data from a {@link CategoryDataset}.
 * 
 */
public class ShowOilcan extends ApplicationFrame
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * A custom renderer that returns a different color for each item in a
	 * single series.
	 */
	static class CustomCylinderRenderer extends StackedCylinderRenderer
	{

		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		/** The colors. */
		private Paint[] colors;

		/**
		 * Creates a new renderer.
		 * 
		 * @param colors
		 *            the colors.
		 */
		public CustomCylinderRenderer()
		{
			
		}
		public CustomCylinderRenderer(double xOff,double yOff)
		{
			super(xOff,yOff);
		}

		/**
		 * Returns the paint for an item. Overrides the default behaviour
		 * inherited from AbstractSeriesRenderer.
		 * 
		 * @param row
		 *            the series.
		 * @param column
		 *            the category.
		 * 
		 * @return The item color.
		 */
		public Paint getItemPaint(int row, int column)
		{
			return this.colors[row];
		}

		/**
		 * @return the colors
		 */
		public Paint[] getColors()
		{
			return colors;
		}

		/**
		 * @param colors
		 *            the colors to set
		 */
		public void setColors(Paint[] colors)
		{
			this.colors = colors;
		}
	}
	
	
	/**
	 * Creates a new demo.
	 * 
	 * @param title
	 *            the frame title.
	 */
	public ShowOilcan(final String title)
	{

		super(title);

		final CategoryDataset dataset = createDataset();
		final JFreeChart chart = createChart(dataset);

		// add the chart to a panel...
		final ChartPanel chartPanel = new ChartPanel(chart);
		chartPanel.setPreferredSize(new java.awt.Dimension(450, 560));
		setContentPane(chartPanel);

	}

	/**
	 * Creates a sample dataset.
	 * 
	 * @return a sample dataset.
	 */
	private CategoryDataset createDataset()
	{
		DefaultCategoryDataset result = new DefaultCategoryDataset();
//        result.addValue(90.3, "油罐 (entry)", "a");
//        result.addValue(30.3, "油罐 (entry)", "a");
//        
//        result.addValue(27.2, "油罐 (empty)", "油罐");
//        
//        return (CategoryDataset) result;
        
        
		final double[][] data = new double[][] { 
				{ 45.5D },
				{ 12.2D },
				//{ 10.0D }

		
		// {-5.0, -7.0, 14.0, -3.0},
		// {6.0, 17.0, -12.0, 7.0},
		// {7.0, 15.0, 11.0, 0.0},
		// {-8.0, -6.0, 10.0, -9.0},
		// {9.0, 8.0, 0.0, 6.0},
		// {-10.0, 9.0, 7.0, 7.0},
		// {11.0, 13.0, 9.0, 9.0},
		// {-3.0, 7.0, 11.0, -10.0}
		};

		return DatasetUtilities.createCategoryDataset("Series ", "",
				data);

	}

	/**
	 * Creates a chart.
	 * 
	 * @param dataset
	 *            the dataset.
	 * 
	 * @return The chart.
	 */
	private JFreeChart createChart(final CategoryDataset dataset)
	{

		final JFreeChart jfreechart = ChartFactory.createBarChart3D(
				"油罐号", // chart title
				"温度:35C    密度:22.2    液位高度:15.3米    重量:1523Kg", // domain axis label
				"高度(m)", // range axis label
				dataset, // data
				PlotOrientation.VERTICAL, // orientation
				true, // include legend
				true, // tooltips
				false // urls
				);

		// final CategoryPlot plot = chart.getCategoryPlot();
		// final CategoryAxis axis = plot.getDomainAxis();
		// axis.setCategoryLabelPositions(
		// CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 8.0)
		// );
		// final BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();
		// renderer.setDrawBarOutline(false);
		//        
		// return chart;
		
		jfreechart.setBackgroundPaint(Color.WHITE);
		CategoryPlot categoryplot = jfreechart.getCategoryPlot();
		
//		CustomCylinderRenderer renderer = new CustomCylinderRenderer(20.0,30.0);
		CustomCylinderRenderer renderer = new CustomCylinderRenderer(20.0,25.0);
		
//		KeyToGroupMap map = new KeyToGroupMap("G1");
//		map.mapKeyToGroup("油罐 (entry)", "G1");
//		map.mapKeyToGroup("油罐 (empty)", "G1");
		
//		renderer.setseries
		

		
		Paint[] cylinderColors = new Paint[categoryplot.getDataset()
				.getRowCount()];

		// Sets colors for series 
//		Vector colors = chartDataObject.getSeriesColors();
		
//		for (int i = 0; i < categoryplot.getDataset().getRowCount(); i++)
//		{
//			cylinderColors[i] = new GradientPaint(0f, 0f, Color.white, 0f, 0f,
//					Color.yellow);
//			renderer.setSeriesPaint(i, Color.blue);
//		}
		
		cylinderColors[0] = new GradientPaint(0f, 0f, Color.WHITE, 0f, 0f,Color.YELLOW);
		cylinderColors[1] = new GradientPaint(0f, 0f, Color.WHITE, 0f, 0f,Color.WHITE);
		renderer.setSeriesOutlinePaint(1, Color.BLACK);
//		cylinderColors[2] = new Color(255,255,255,128);
		
		renderer.setColors(cylinderColors);

		renderer
				.setGradientPaintTransformer(new StandardGradientPaintTransformer(
						GradientPaintTransformType.CENTER_HORIZONTAL));
		
		renderer.setOutlinePaint(Color.gray);
		renderer.setOutlineStroke(new BasicStroke(0.3f));
		renderer.setMaximumBarWidth(0.3D); // set cylinder width
		
//		renderer.set
		
		categoryplot.setRenderer(renderer);

		categoryplot.setOutlinePaint(null);
		categoryplot.setForegroundAlpha(0.8f);		// set plot's alpha
		categoryplot.setBackgroundPaint(Color.WHITE);
		categoryplot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
		categoryplot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
		
		NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis(); 
		numberaxis.setRange(0.0D, 100.0); // set fix asix range 0.0--300.0(设置坐标轴显示最大固定长度)
//		numberaxis.setFixedAutoRange(200D);  //can see two


		// Tooltipps
//		if (chartDataObject.isTooltipps())
//			renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator(
//					"{1}({0}) = {2}", NumberFormat.getInstance()));
//
//		NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
//		numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
//		numberaxis.setTickMarkPaint(Color.black);

		// set gridlines
//		if (chartDataObject.isGridX())
//		{
//			categoryplot.setDomainGridlinesVisible(true);
//			categoryplot.setDomainGridlinePaint(chartDataObject.getGridColor());
//
//		} else
//		{
//			categoryplot.setDomainGridlinesVisible(false);
//		}
//		
//		if (chartDataObject.isGridY())
//		{
//			categoryplot.setRangeGridlinesVisible(true);
//			categoryplot.setRangeGridlinePaint(chartDataObject.getGridColor());
//		} else
//		{
//			categoryplot.setRangeGridlinesVisible(false);
//		}
		return jfreechart;

	}

	// ****************************************************************************
	// * JFREECHART DEVELOPER GUIDE *
	// * The JFreeChart Developer Guide, written by David Gilbert, is available
	// *
	// * to purchase from Object Refinery Limited: *
	// * *
	// * http://www.object-refinery.com/jfreechart/guide.html *
	// * *
	// * Sales are used to provide funding for the JFreeChart project - please *
	// * support us so that we can continue developing free software. *
	// ****************************************************************************

	/**
	 * Starting point for the demonstration application.
	 * 
	 * @param args
	 *            ignored.
	 */
	public static void main(final String[] args)
	{

		final ShowOilcan demo = new ShowOilcan("3D Oilcan view tmp");
		demo.pack();
		RefineryUtilities.centerFrameOnScreen(demo);
		demo.setVisible(true);

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -