eclipse中用JAVA代码怎么画柱形图表用jfreechart
jfreechart绘制柱状图
import java.io.File;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
/*
* 绘制柱状图
*你亮哥
* */
public class BarChart3DDemo
{
public static void main(String[] args)
{
try
{
//设置主题
ChartFactory.setChartTheme(Theme.getTheme());
//构造数据
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(100, "JAVA","1");
dataset.addValue(200, "js","1");
dataset.addValue(200, "C", "2");
dataset.addValue(300, "C", "3");
dataset.addValue(400, "HTML", "4");
dataset.addValue(400, "CSS", "5");
/*
* public static JFreeChart createBarChart3D(
* java.lang.String title, 设置图表的标题
* java.lang.String categoryAxisLabel, 设置分类轴的标示
* java.lang.String valueAxisLabel, 设置值轴的标示
* CategoryDataset dataset, 设置数据
* PlotOrientation orientation, 设置图表的方向
* boolean legend, 设置是否显示图例
* boolean tooltips,设置是否生成热点工具
* boolean urls) 设置是否显示url
*/
JFreeChart chart = ChartFactory.createBarChart3D("编程语言统计", "语言",
"学习人数", dataset, PlotOrientation.VERTICAL, true, false,
false);
//保存图表
ChartUtilities.saveChartAsPNG(new File("E:/chart/BarChart3D.png"), chart, 800, 500);
System.out.println("绘图完成");
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
===================================================================================
//一条线 有点 有数
package Test;
import java.awt.Color;
import java.awt.Font;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardXYItemLabelGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.TextAnchor;
public class try123 {
public static void main(String[] args){
//首先构造数据
TimeSeries timeSeries = new TimeSeries("BMI", Month.class);
// 时间曲线数据集合
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
// 构造数据集合
timeSeries.add(new Month(1, 2009), 45);
timeSeries.add(new Month(2, 2009), 46);
timeSeries.add(new Month(3, 2009), 1);
【java绘制图表程序代码 java绘制图表程序代码怎么写】timeSeries.add(new Month(4, 2009), 500);
timeSeries.add(new Month(5, 2009), 43);
timeSeries.add(new Month(6, 2009), 324);
timeSeries.add(new Month(7, 2009), 632);
timeSeries.add(new Month(8, 2009), 34);
timeSeries.add(new Month(9, 2009), 12);
timeSeries.add(new Month(10, 2009), 543);
timeSeries.add(new Month(11, 2009), 32);
timeSeries.add(new Month(12, 2009), 225);
lineDataset.addSeries(timeSeries);
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 , 把SQL SERVER数据库里面的书库绘制成图表的形式,类似于股票那样有XY轴,曲线显示,怎么做?。?/h2>有两种实现方式,一种就是JFreeChart的官方实例MemoryUsageDemo.java.通过一个实现java.Swing.Timer的内部类,在其监听器中将实时数据添加进TimeSeries,由于Timer是会实时执行的 , 所以这个方法倒是没有什么问题,可以参考代码 。
另一种方式就是将实时类实现Runnable接口,在其run()方法中,通过无限循环将实时数据添加进TimeSeries,下面是较简单的实现代码:
java 代码
//RealTimeChart .java
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
public class RealTimeChart extends ChartPanel implements Runnable
{
private static TimeSeries timeSeries;
private long value=https://www.04ip.com/post/0;
public RealTimeChart(String chartContent,String title,String yaxisName)
{
super(createChart(chartContent,title,yaxisName));
}
private static JFreeChart createChart(String chartContent,String title,String yaxisName){
//创建时序图对象
timeSeries = new TimeSeries(chartContent,Millisecond.class);
TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeSeries);
JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title,"时间(秒)",yaxisName,timeseriescollection,true,true,false);
XYPlot xyplot = jfreechart.getXYPlot();
//纵坐标设定
ValueAxis valueaxis = xyplot.getDomainAxis();
//自动设置数据轴数据范围
valueaxis.setAutoRange(true);
//数据轴固定数据范围 30s
valueaxis.setFixedAutoRange(30000D);
valueaxis = xyplot.getRangeAxis();
//valueaxis.setRange(0.0D,200D);
return jfreechart;
}
public void run()
{
while(true)
{
try
{
timeSeries.add(new Millisecond(), randomNum());
Thread.sleep(300);
}
catch (InterruptedException e) { }
}
}
private long randomNum()
{
System.out.println((Math.random()*20 80));
return (long)(Math.random()*20 80);
}
}
//Test.java
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
public class Test
{
/**
* @param args
*/
public static void main(String[] args)
{
JFrame frame=new JFrame("Test Chart");
RealTimeChart rtcp=new RealTimeChart("Random Data","随机数","数值");
frame.getContentPane().add(rtcp,new BorderLayout().CENTER);
frame.pack();
frame.setVisible(true);
(new Thread(rtcp)).start();
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent windowevent)
{
System.exit(0);
}
});
}
}
这两中方法都有一个问题 , 就是每实现一个图就要重新写一次,因为实时数据无法通过参数传进来,在想有没有可能通过setXXX()方式传进实时数据,那样的话就可以将实时曲线绘制类封装起来,而只需传递些参数即可 。
怎样用JAVA来实现在网页中制作柱状图JFreeChart是JAVA平台上的一个开放的图表绘制类库 。它完全使用JAVA语言编写,是为applications, applets, servlets 以及JSP等使用所设计 。JFreeChart可生成饼图(pie charts)、柱状图(bar charts)、散点图(scatter plots)、时序图(time series)、甘特图(Gantt charts)等等多种图表,并且可以产生PNG和JPEG格式的输出,还可以与PDF和EXCEL关联 。
JFreeChart的主页地址为:
在这里可以找到最新版本的JFreeChart的相关信息,如说明文档、下载连接以及示例图表等 。
JFreeChart目前是最好的java图形解决方案 , 基本能够解决目前的图形方面的需求 。
IBM文档:
Javaeye社区:
求大神指教 JFree chart 这个图表怎么做对啊 , 这个不难的,网上搜JFreeChart 3D饼图,很多例子代码的 , 封装一下,然后传递参数就行了 。
下面是我整理的代码:
package ping.chart;
import java.awt.Font;
import java.io.FileOutputStream;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
/**
* JFreeChart出生Swing形式的饼图
*
* @author LiuYanPing
*
*/
@SuppressWarnings("serial")
public class PPieChart3D extends JPanel {
public String chart_title="TEST";
private JFreeChart chart;
/**
* @author LiuYanPING
* @param title
* @param xtitle
* @param ytitle
* @param data must be String[][2];String[][1] must be integer
* @return
*/
public JPanel createPanel(String title,String [][]data) {
chart_title=title;
chart = createJFreeChart(createDataSet(data));
return new ChartPanel(chart);
}
/**
* @author LiuYanPING
* @param CHART_PATH like "./xx/"
* @param charName like "xxx.jpg"
* @return
*/
public String SaveAsPNG(String CHART_PATH,String charName)
{
FileOutputStream fos_jpg = null;
try
{
if(null==CHART_PATH) return null;
String chartName = CHART_PATHcharName;
fos_jpg = new FileOutputStream(chartName);
ChartUtilities.writeChartAsPNG(fos_jpg, chart, 500, 500, true, 10);
return chartName;
}
catch (Exception e)
{
e.printStackTrace();
return null;
}
finally
{
try
{
fos_jpg.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
privateDefaultPieDataset createDataSet(String [][]data) {
DefaultPieDataset dataset = new DefaultPieDataset();
for(int i=0;idata.length;i)
{
dataset.setValue(data[i][0],Integer.parseInt(data[i][1]));
}
return dataset;
}
privateJFreeChart createJFreeChart(DefaultPieDataset dataset) {
/**
* 构建JFreeChart
*/
// JFreeChart jfreeChart
JFreeChart jfreeChart = ChartFactory.createPieChart3D(chart_title, dataset, true, false, false);
/**
* 设置JFreeChart的属性
*/
jfreeChart.setTitle(new TextTitle(chart_title, new Font("宋体", Font.BOLD
Font.ITALIC, 20)));
return jfreeChart;
}
}
你直接调用
createPanel(String title,String [][]data)
就行了
如何使用java做统计图表//参考地址去网站下js控件java绘制图表程序代码,下面是饼图的代码java绘制图表程序代码,下图是我的代码效果
function query1(housetype,redStatisticsList,text0,cashingSum,tranferSum){
!--红包发放数据--
var myrodiusred = echarts.init(document.getElementById('mainrodius'));//ID
var redHousehold = housetype;
var redMoney = redStatisticsList;
var allMoney = 0;//总金额
$.each(redStatisticsList,function(index,item){
allMoney =allMoneyNumber(item.value);
})
optionTwo = {
title : {
text: text0,
subtext: "总金额java绘制图表程序代码:" allMoney "\n\n提现总额java绘制图表程序代码:" cashingSum "\n\n到账总额:" tranferSum,
x:'center'
},
tooltip : {
trigger: 'item',
formatter: "{a} br/{b} ({d}%)"
},
legend: {
orient: 'vertical',
left: 'left',
data: housetype
},
series : [
{
type: 'pie',
radius : '55%',
center: ['50%', '60%'],
data:redMoney,
itemStyle: {
emphasis: {
shadowBlur: 10,
shadowOffsetX: 0,
shadowColor: 'rgba(0, 0, 0, 0.5)'
}
}
}
]
};
myrodiusred.setOption(optionTwo);
}
编写一个java该程序使用drawline的方法绘制一个四行八列的表格这不是随便画
import java.awt.Graphics;
import javax.swing.JFrame;
public class Table extends JFrame {
public Table() {
setTitle("Table");
setSize(500, 500);
this.setVisible(true);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void paint(Graphics g) {
for (int i = 0; i5; i) {
g.drawLine(50, 50i * 100, 450, 50i * 100);
}
for (int i = 0; i9; i) {
g.drawLine(50i * 50, 50, 50i * 50, 450);
}
}
public static void main(String args[]) {
new Table();
}
}
关于java绘制图表程序代码和java绘制图表程序代码怎么写的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- erp系统适合女生学吗,学erp有用吗
- 面试flutter,面试最忌讳穿什么衣服
- 凌风直播运营,凌风直播运营怎么样
- java代码实现线性代数 java中如何编写线程类
- flutter调用ios原生,flutter 调用原生view
- 关于电视机怎么放ppt的信息
- Php多数据源 php大量数据处理
- jquery判断简写,Jquery判断元素是否存在
- 尼尔机械纪元用什么电脑好,尼尔机械纪元用什么电脑好用