JFreeChart chart = ChartFactory.createTimeSeriesChart("", "date", "bmi", lineDataset, true, true, true);
//增加标题
chart.setTitle(new TextTitle("XXXBMI指数", new Font("隶书", Font.ITALIC, 15)));
chart.setAntiAlias(true);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setAxisOffset(new RectangleInsets(10,10,10,10));//图片区与坐标轴的距离
plot.setOutlinePaint(Color.PINK);
plot.setInsets(new RectangleInsets(15,15,15,15));//坐标轴与最外延的距离
// plot.setOrientation(PlotOrientation.HORIZONTAL);//图形的方向 , 包括坐标轴 。
AxisSpace as = new AxisSpace();
as.setLeft(25);
as.setRight(25);
plot.setFixedRangeAxisSpace(as);
chart.setPadding(new RectangleInsets(5,5,5,5));
chart.setNotify(true);
// 设置曲线是否显示数据点
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();
xylineandshaperenderer.setBaseShapesVisible(true);
// 设置曲线显示各数据点的值
XYItemRenderer xyitem = plot.getRenderer();
xyitem.setBaseItemLabelsVisible(true);
xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_LEFT));
xyitem.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
plot.setRenderer(xyitem);
//显示
ChartFrame frame = new ChartFrame("try1", chart);
frame.pack();
frame.setVisible(true);
}
}
怎么用java做柱形图?。。?/h2>首先要有jfreechart.jar和jcommon-1.0.12.jar两个包然后在web.xml配置
servlet
servlet-nameDisplayChart/servlet-name
servlet-classorg.jfree.chart.servlet.DisplayChart/servlet-class
/servlet
servlet-mapping
servlet-nameDisplayChart/servlet-name
url-pattern/DisplayChart/url-pattern
/servlet-mapping
最后是jsp代码:
%@ page contentType="text/html;charset=GBK"%
%@ page import="org.jfree.chart.ChartFactory,
org.jfree.chart.JFreeChart,
org.jfree.chart.plot.PlotOrientation,
org.jfree.chart.servlet.ServletUtilities,
org.jfree.data.category.CategoryDataset,
org.jfree.data.general.DatasetUtilities"%
%
double[][] data = https://www.04ip.com/post/new double[][] {{1310}, {720}, {1130}, {440}};
String[] rowKeys = {"猪肉", "牛肉","鸡肉", "鱼肉"};
String[] columnKeys = {""};
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
JFreeChart chart = ChartFactory.createBarChart3D("广州肉类销量统计图", "肉类",
"销量",
dataset,
PlotOrientation.VERTICAL,
true,
false,
false);
String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session);
String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
%
img src="/images/defaultpic.gif"
java 柱状图系统配置与实例ChartDirector除了一个英文件的帮助以外,也没有再提供Java DOC形式的文档,为了方便,写以下一个例子说明使用ChartDirector生成柱状图的方法.jsp方式实质与JAVA方式没有区别,这里是我从JSP中取的代码(JSP改起来方便,不过手动)
代码如下:
%@ page language="java" contentType="text/Html; charset=UTF-8"
pageEncoding="UTF-8" import="ChartDirector.*;"%
%
request.setCharacterEncoding("UTF-8");
//以两个系列数据为例
double[] data = https://www.04ip.com/post/{185, 156, 179.5, 211, 123};
double[] data1 = {55, 76, 34.5, 88, 43};
//数据列名
String[] labels = {"一月", "二月", "三月", "四月", "五月"};
//生成图片大小 250 x 250
XYChart c = new XYChart(550, 350);
//图标题
c.addTitle("第一个图","",15);
推荐阅读
- 在抖音直播刷b站,b站直播刷礼物主播能拿多少
- chatGpT机器人简笔画,太空机器人简笔画
- flashplayer苹果iOS,flashplayer苹果手机版下载
- python字符串输出字母,python字符串怎么输出
- 微信支付java代码 javaweb微信支付功能
- 电源线怎么接显卡接口好看,显卡3个8pin接口要接几根电源线
- sqlserver内存配置文件,sqlserver内存数据库
- ppt怎么添加链接,ppt怎么做超链接
- C语言中的函数的作用 c语言中函数的应用