如何根据已知数据,使用java来生成柱状图、和曲线图啊

flowerworm 2003-07-30 04:01:41
如何根据已知数据,使用java来生成柱状图、和曲线图啊
例如 小明成绩98 班级最高分110 平均分90 满分120
来生成柱状图,
最好请给出例子?
...全文
207 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xqi8 2003-07-30
  • 打赏
  • 举报
回复
用jfreechart
runnersun 2003-07-30
  • 打赏
  • 举报
回复
可以自己写chart和pole的类,就是封装一个数据接口
WAPQQ 2003-07-30
  • 打赏
  • 举报
回复
public static String generateXYChart(String section, HttpSession session, PrintWriter pw) {
String filename = null;
try {
// Retrieve list of WebHits
WebHitDataSet whDataSet = new WebHitDataSet();
ArrayList list = whDataSet.getDataByHitDate(section);

// Throw a custom NoDataException if there is no data
if (list.size() == 0) {
System.out.println("No data has been found");
throw new NoDataException();
}

// Create and populate an XYSeries Collection
XYSeries dataSeries = new XYSeries(null);
Iterator iter = list.listIterator();
int currentPosition = 0;
while (iter.hasNext()) {
WebHit wh = (WebHit)iter.next();
dataSeries.add(wh.getHitDate().getTime(),wh.getHitCount());
currentPosition++;
}
XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);

// Create tooltip and URL generators
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.UK);
TimeSeriesToolTipGenerator ttg = new TimeSeriesToolTipGenerator(
sdf, NumberFormat.getInstance());
TimeSeriesURLGenerator urlg = new TimeSeriesURLGenerator(
sdf, "pie_chart.jsp", "series", "hitDate");

// Create the chart object
ValueAxis timeAxis = new HorizontalDateAxis("");
NumberAxis valueAxis = new VerticalNumberAxis("");
valueAxis.setAutoRangeIncludesZero(false); // override default
XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis);
StandardXYItemRenderer sxyir = new StandardXYItemRenderer(
StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES,
ttg, urlg);

sxyir.setDefaultShapeFilled(true);
plot.setRenderer(sxyir);
JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.setBackgroundPaint(java.awt.Color.white);

// Write the chart image to the temporary directory
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);

// Write the image map to the PrintWriter
ChartUtilities.writeImageMap(pw, filename, info);
pw.flush();

} catch (NoDataException e) {
System.out.println(e.toString());
filename = "public_nodata_500x300.png";
} catch (Exception e) {
System.out.println("Exception - " + e.toString());
e.printStackTrace(System.out);
filename = "public_error_500x300.png";
}
return filename;
}
flowerworm 2003-07-30
  • 打赏
  • 举报
回复
请问jfreechart是什么呀,怎么找到阿
boat2002w 2003-07-30
  • 打赏
  • 举报
回复
用jfreechart
bpudaye 2003-07-30
  • 打赏
  • 举报
回复
1.jfreechart
2.svg
3.office excel地一个插件
4.柱状图可以自己用表格画,我画过,三个循环就搞定
dingdi 2003-07-30
  • 打赏
  • 举报
回复
可以把数据放在数组里,然后在去取呀?
eg:
import java.applet.*;
import java.awt.*;

public class Zhu extends Applet
{
int x1,y1,x2,y2,x3=11,a1;
Font font;
int a[]={29,39,5,87,9,10,33,56,0,54,5,98,73,26,57,18,96,42,34,99};
Graphics gg;

public void init()
{
x1=getSize().width;
y1=getSize().height;//获取窗空的初值
a1=a.length;//获取数组的长度
}

public boolean mouseDown(Event event,int x,int y)
{
if((x-10)<=0||x>=(20*a1+10))//鼠标的范围出届
{}
else//鼠标在规定范围
{
x3=x;
x2=(x-10)/20+1;
y2=a[(x-10)/20];
}
repaint();
return true;
}

public boolean mouseDrag(Event event, int x, int y)
{
if((x-10)<=0)//鼠标的范围出届
{
x2=0;
y2=a[0];
}
else if(x>=(20*a1+10))
{
x2=a1;
y2=a[a1-1];
}
else//鼠标在规定范围
{
x3=x;
x2=(x-10)/20+1;
y2=a[(x-10)/20];
}
repaint();
return true;
}

public void paint(Graphics g)
{
g.drawLine(10,10,10,y1);
g.drawLine(0,y1-20,x1-10,y1-20);
g.drawLine(10,10,5,15);
g.drawLine(10,10,15,15);
g.drawLine(x1-10,y1-20,x1-15,y1-25);
g.drawLine(x1-10,y1-20,x1-15,y1-15);//划坐标
g.setFont(font);
g.setColor(Color.red);
g.drawLine(x3,10,x3,y1-20);//随鼠标的线
g.drawString("(0,0)",10,y1-10);
g.drawString("y",20,20);
g.drawString("x",x1-20,y1-5);//标坐标
g.drawString("x="+x2,50,20);
g.drawString("y="+y2,50,40);//显示数字
for(int i=0;i<=a1;i++)//用循环来划柱状图
{
g.setColor(Color.blue);
g.fillRect(10+20*i,y1-3*a[i]-20,20,3*a[i]);
}
}
}
丞相 2003-07-30
  • 打赏
  • 举报
回复
用jfreechart吧

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧