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

📄 bardemo1.jsp

📁 自己写的jfreechart demo
💻 JSP
字号:
<%@ page language="java" pageEncoding="GBK"%>

<%@ page import="java.awt.Font"%>
<%@ page import="java.awt.Color"%>

<%@ page import="org.jfree.chart.ChartFactory" %>
<%@ page import="org.jfree.chart.JFreeChart" %>
<%@ page import="org.jfree.chart.title.*" %>
<%@ page import="org.jfree.chart.plot.*" %>
<%@ page import="org.jfree.chart.axis.*" %>
<%@ page import="org.jfree.chart.plot.PlotOrientation" %>
<%@ page import="org.jfree.chart.servlet.ServletUtilities" %>
<%@ page import="org.jfree.data.category.DefaultCategoryDataset" %>
<%
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(610, "北京", "猪肉");
dataset.addValue(220, "北京", "牛肉");
dataset.addValue(530, "北京", "鸡肉");
dataset.addValue(340, "北京", "鱼肉");


JFreeChart chart = ChartFactory.createBarChart3D("肉类销量统计图","肉类","销量",dataset,PlotOrientation.VERTICAL,
false,
false,
false);

Font font = new Font("SimSun", 10, 20); 
TextTitle textTitle = chart.getTitle();
textTitle.setFont(font);
textTitle.setPaint(Color.BLUE);

//绘图对象
CategoryPlot plot = chart.getCategoryPlot();

//图X轴Domain(CategoryAxis)
CategoryAxis domainAxis = plot.getDomainAxis();

domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 4.0));
//X轴上的文字
domainAxis.setTickLabelFont(new Font("宋体", Font.PLAIN, 12));
domainAxis.setTickLabelPaint(Color.BLUE);

//X轴的标题文字
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 15));
domainAxis.setLabelPaint(Color.BLUE);
plot.setDomainAxis(domainAxis);

//图Y轴Range(ValueAxis)
ValueAxis valueAxis =plot.getRangeAxis();

//Y轴上的文字
valueAxis.setTickLabelFont(new Font("宋体", Font.PLAIN, 12));
valueAxis.setTickLabelPaint(Color.BLUE);

//Y轴的标题文字
valueAxis.setLabelFont(new Font("宋体", Font.PLAIN, 15));
valueAxis.setLabelPaint(Color.BLUE);

String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session);
String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
%>
<img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#<%= filename %>">

⌨️ 快捷键说明

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