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

📄 dialchart.jsp

📁 JFreeChart开发全攻略,JFreeChart开发全攻略
💻 JSP
字号:
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="org.jfree.chart.JFreeChart,
                 org.jfree.chart.servlet.ServletUtilities,
                 org.jfree.data.general.DefaultValueDataset,
                 org.jfree.experimental.chart.plot.dial.*,
                 java.awt.*,
                 org.jfree.ui.StandardGradientPaintTransformer,
                 org.jfree.ui.GradientPaintTransformType"%>
                 
<%
//创建数据集
DefaultValueDataset hoursDataset = new DefaultValueDataset(6D);
DefaultValueDataset dataset2 = new DefaultValueDataset(15D);

//设置钟表图形属性
DialPlot dialplot = new DialPlot();
dialplot.setView(0.0D, 0.0D, 1.0D, 1.0D);
dialplot.setDataset(0, hoursDataset);
dialplot.setDataset(1, dataset2);
SimpleDialFrame simpledialframe = new SimpleDialFrame();
simpledialframe.setBackgroundPaint(Color.lightGray);
simpledialframe.setForegroundPaint(Color.darkGray);
dialplot.setDialFrame(simpledialframe);
//设置图形背景
DialBackground dialbackground = new DialBackground(Color.yellow);
dialbackground.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
dialplot.setBackground(dialbackground);
StandardDialScale standarddialscale = new StandardDialScale(0.0D, 12D, 90D, -360D);
standarddialscale.setFirstTickLabelVisible(false);
standarddialscale.setMajorTickIncrement(1);
//设置表刻度和数字离中心的半径
standarddialscale.setTickRadius(0.90D);
//设置数字离开表盘的距离
standarddialscale.setTickLabelOffset(0.1D);
standarddialscale.setTickLabelFont(new Font("宋体", 0, 14));
dialplot.addScale(0, standarddialscale);
StandardDialScale standarddialscale1 = new StandardDialScale(0.0D, 60D, 90D, -360D);
standarddialscale1.setVisible(false);
standarddialscale1.setMajorTickIncrement(5D);
standarddialscale1.setTickRadius(0.68D);
standarddialscale1.setTickLabelOffset(0.15D);
standarddialscale1.setTickLabelFont(new Font("宋体", 0, 14));
dialplot.addScale(1, standarddialscale1);

//设置时针的指针
org.jfree.experimental.chart.plot.dial.DialPointer.Pointer pointer = new org.jfree.experimental.chart.plot.dial.DialPointer.Pointer(0);
pointer.setRadius(0.5D);
dialplot.addLayer(pointer);
dialplot.mapDatasetToScale(1, 1);

//设置分针的指针
org.jfree.experimental.chart.plot.dial.DialPointer.Pointer pointer1 = new org.jfree.experimental.chart.plot.dial.DialPointer.Pointer(1);
pointer1.setRadius(0.7D);
dialplot.addLayer(pointer1);

//设置刻度中间的圆圈的大小
DialCap dialcap = new DialCap();
dialcap.setRadius(0.05D);
dialplot.setCap(dialcap);

//根据刻度图形建立JFreeChart对象
JFreeChart jfreechart = new JFreeChart(dialplot);
//设置图形的标题
jfreechart.setTitle("刻度图示例——钟表图");
		
String filename = ServletUtilities.saveChartAsPNG(jfreechart, 300, 300, null, session);
String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
%>
<img src="<%= graphURL %>" width="300" height="300" border="0" usemap="#<%= filename %>"> 

⌨️ 快捷键说明

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