柱状图源代码(python柱状图代码)
admin 发布:2022-12-19 19:06 119
今天给各位分享柱状图源代码的知识,其中也会对python柱状图代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
python如何将柱状图变为饼图
1. 源程序代码 importnumpyasnpimportmatplotlib.pyplotasplt Emp_data=np.loadtxt('Employedpopulation.csv',delimiter=",",usecols=(1,2,3,4,
2. 调整柱状图的宽度,平移后柱显示的位置¶ importnumpyasnpimportmatplotlib.pyplotasplt Emp_data=np.loadtxt('Employedpopulation.csv',delimiter=",",usecol
在VB中使用VBA生成柱形图表怎么实现?
可以生成图表,图表中的数据源用下面的代码在A7:G13位置sheet2的表A1:B5
在指定的位置图(子)
设置AB =范围(“A7: G13)'生成图表位置
设为BBB = ActiveSheet.ChartObjects.Add(0,0,0,0)
bbb.Chart.ChartType = xlColumnClustered的柱形图
bbb.Chart。数据源SetSourceData来源:=表(“Sheet2的”)范围(“A1:B5”)'
BBB
= ab.Top
左= ab.Left,
。的宽度= ab.Width
高度= ab.Height
尾与
尾子
用jsp怎样生成柱状图,饼状图,折线图
jsp生成柱状图,饼状图,折线图可以借助于jfreechart。
1、柱状图的生成源码:
/**
* 生产柱状图
* @version 1.0
* @since
*/
@SuppressWarnings("serial")
public class PillarServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
// 使用普通数据集
DefaultCategoryDataset chartDate = new DefaultCategoryDataset();
// 增加测试数据,第一个参数是访问量,最后一个是时间,中间是显示用不考虑
chartDate.addValue(55, "访问量", "2010-01");
chartDate.addValue(65, "访问量", "2010-02");
chartDate.addValue(59, "访问量", "2010-03");
chartDate.addValue(156, "访问量", "2010-04");
chartDate.addValue(452, "访问量", "2010-05");
chartDate.addValue(359, "访问量", "2010-06");
try {
// 从数据库中获得数据集
DefaultCategoryDataset data = chartDate;
// 使用ChartFactory创建3D柱状图,不想使用3D,直接使用createBarChart
JFreeChart chart = ChartFactory.createBarChart3D(
"网站月访问量统计", // 图表标题
"时间", // 目录轴的显示标签
"访问量", // 数值轴的显示标签
data, // 数据集
PlotOrientation.VERTICAL, // 图表方向,此处为垂直方向
// PlotOrientation.HORIZONTAL, //图表方向,此处为水平方向
true, // 是否显示图例
true, // 是否生成工具
false // 是否生成URL链接
);
// 设置整个图片的背景色
chart.setBackgroundPaint(Color.PINK);
// 设置图片有边框
chart.setBorderVisible(true);
Font kfont = new Font("宋体", Font.PLAIN, 12); // 底部
Font titleFont = new Font("宋体", Font.BOLD, 25); // 图片标题
// 图片标题
chart.setTitle(new TextTitle(chart.getTitle().getText(), titleFont));
// 底部
chart.getLegend().setItemFont(kfont);
// 得到坐标设置字体解决乱码
CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setRangeCrosshairVisible(true);
categoryplot.setRangeCrosshairPaint(Color.blue);
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
barrenderer.setBaseItemLabelFont(new Font("宋体", Font.PLAIN, 12));
barrenderer.setSeriesItemLabelFont(1, new Font("宋体", Font.PLAIN, 12));
CategoryAxis domainAxis = categoryplot.getDomainAxis();
/*------设置X轴坐标上的文字-----------*/
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
/*------设置X轴的标题文字------------*/
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
/*------设置Y轴坐标上的文字-----------*/
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
/*------设置Y轴的标题文字------------*/
numberaxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
/*------这句代码解决了底部汉字乱码的问题-----------*/
chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
// 生成图片并输出
ChartUtilities.writeChartAsJPEG(response.getOutputStream(), 1.0f,
chart, 500, 300, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
2、生成饼状统计图:
/**
* 生成饼状统计图
* @version 1.0
* @since
*/
@SuppressWarnings("serial")
public class CakeServlet extends HttpServlet {
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
// 默认数据类型
DefaultPieDataset dataType = new DefaultPieDataset();
// 数据参数 内容,数量
dataType.setValue("IE6", 156);
dataType.setValue("IE7", 230);
dataType.setValue("IE8", 45);
dataType.setValue("火狐", 640);
dataType.setValue("谷歌", 245);
try {
DefaultPieDataset data = dataType;
// 生成普通饼状图除掉 3D 即可
// 生产3D饼状图
PiePlot3D plot = new PiePlot3D(data);
JFreeChart chart = new JFreeChart(
"用户使用的浏览器类型", // 图形标题
JFreeChart.DEFAULT_TITLE_FONT, // 标题字体
plot, // 图标标题对象
true // 是否显示图例
);
// 设置整个图片的背景色
chart.setBackgroundPaint(Color.PINK);
// 设置图片有边框
chart.setBorderVisible(true);
// 配置字体
Font kfont = new Font("宋体", Font.PLAIN, 12); // 底部
Font titleFont = new Font("宋体", Font.BOLD, 25); // 图片标题
// 图片标题
chart.setTitle(new TextTitle(chart.getTitle().getText(), titleFont));
// 底部
chart.getLegend().setItemFont(kfont);
ChartUtilities.writeChartAsJPEG(response.getOutputStream(), 1.0f,
chart, 500, 300, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
3、柱状分布统计图:
/**
* 柱状分布统计图
* @version 1.0
* @since
*/
@SuppressWarnings("serial")
public class ParagraphsServlet extends HttpServlet {
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
DefaultCategoryDataset dataTime = new DefaultCategoryDataset();
// 这是一组数据
dataTime.addValue(52, "0-6", "2010-1-1");
dataTime.addValue(86, "6-12", "2010-1-1");
dataTime.addValue(126, "12-18", "2010-1-1");
dataTime.addValue(42, "18-24", "2010-1-1");
// 这是一组数据
dataTime.addValue(452, "0-6", "2010-1-2");
dataTime.addValue(96, "6-12", "2010-1-2");
dataTime.addValue(254, "12-18", "2010-1-2");
dataTime.addValue(126, "18-24", "2010-1-2");
// 这是一组数据
dataTime.addValue(256, "0-6", "2010-1-3");
dataTime.addValue(86, "6-12", "2010-1-3");
dataTime.addValue(365, "12-18", "2010-1-3");
dataTime.addValue(24, "18-24", "2010-1-3");
try {
DefaultCategoryDataset data = dataTime;
// 使用ChartFactory创建3D柱状图,不想使用3D,直接使用createBarChart
JFreeChart chart = ChartFactory.createBarChart3D(
"网站时间段访问量统计",
"时间",
"访问量",
data,
PlotOrientation.VERTICAL,
true,
false,
false
);
// 设置整个图片的背景色
chart.setBackgroundPaint(Color.PINK);
// 设置图片有边框
chart.setBorderVisible(true);
Font kfont = new Font("宋体", Font.PLAIN, 12); // 底部
Font titleFont = new Font("宋体", Font.BOLD, 25); // 图片标题
// 图片标题
chart.setTitle(new TextTitle(chart.getTitle().getText(), titleFont));
// 底部
chart.getLegend().setItemFont(kfont);
// 得到坐标设置字体解决乱码
CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
categoryplot.setDomainGridlinesVisible(true);
categoryplot.setRangeCrosshairVisible(true);
categoryplot.setRangeCrosshairPaint(Color.blue);
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
BarRenderer barrenderer = (BarRenderer) categoryplot.getRenderer();
barrenderer.setBaseItemLabelFont(new Font("宋体", Font.PLAIN, 12));
barrenderer.setSeriesItemLabelFont(1, new Font("宋体", Font.PLAIN, 12));
CategoryAxis domainAxis = categoryplot.getDomainAxis();
/*------设置X轴坐标上的文字-----------*/
domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11));
/*------设置X轴的标题文字------------*/
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
/*------设置Y轴坐标上的文字-----------*/
numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12));
/*------设置Y轴的标题文字------------*/
numberaxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
/*------这句代码解决了底部汉字乱码的问题-----------*/
chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12));
ChartUtilities.writeChartAsJPEG(response.getOutputStream(), 1.0f,
chart, 500, 300, null);
} catch (Exception es) {
es.printStackTrace();
}
}
}
关于柱状图源代码和python柱状图代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
相关推荐
- 05-09网页代码,网页代码快捷键
- 05-07pb超级报表源代码(pb报表工具)[20240507更新]
- 05-07简历源代码可以上传照片的简单介绍[20240507更新]
- 05-07广告切换源代码免费下载(广告切换源代码免费下载安装)[20240507更新]
- 05-06单页网站的代码(完整的网页代码)[20240506更新]
- 05-06阁楼网源代码(阁楼是什么网站)[20240506更新]
- 05-06个人主页图片代码(个人主页图片代码怎么弄)[20240506更新]
- 05-06提取微信名片代码(微信名片信息提取)[20240506更新]
- 05-06php后台权限管理代码(php管理员权限)[20240506更新]
- 05-06付费观看代码php(付费观看代码)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接