package com.miracle.chart;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.openflashchart.chart.Chart;
import org.openflashchart.component.Labels;
import org.openflashchart.component.Title;
import org.openflashchart.component.X_Axis;
import org.openflashchart.component.Y_Axis;
import org.openflashchart.elements.Line;
import org.openflashchart.elements.Line_Dot;
public class ShowChart extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Chart chart = new Chart();
Title title = new Title();
title.setText("Online User Count");
title.setStyle("{color: #736AFF;font-size: 30px;}");
X_Axis x_axis = new X_Axis();
x_axis.setColour("#FF0000");
List x_axisLabels = new ArrayList();
Labels labels = new Labels();
Y_Axis y_axis = new Y_Axis();
y_axis.setColour("#00FF00");
y_axis.setMax(100);
y_axis.setSteps(10);
Line line = new Line("My name is Line");
line.setColour("#CCDDEE");
line.setDot__size(10);
line.setFont__size(12);
line.setWidth(4);
//DB connection
String Driver = "com.mysql.jdbc.Driver";
String URL = "jdbc:mysql://10.5.16.40/tdlive?useUnicode=true&autoReconnect=true&characterEncoding=UTF-8";
String USERNAME = "liuhy";
String PASSWORD = "liuhy";
Connection conn = null;
ResultSet rs = null;
String sql = "SELECT dataTime,currentUserCount,totalConnection,channelId,sceneId FROM userCount ORDER BY dataTime DESC LIMIT 10";
try {
Class.forName(Driver);
conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
PreparedStatement pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
int i = 0;
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
Object [] value = new Object[10];
while(rs.next()){
x_axisLabels.add(df.format(rs.getTimestamp("dataTime")));
value[i] = rs.getInt("currentUserCount");
i++;
}
line.setValues(value);
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e2) {
e2.printStackTrace();
}
labels.setLabels(x_axisLabels);
x_axis.setLabels(labels);
chart.setTitle(title);
chart.setLine(line);
chart.setX_Axis(x_axis);
chart.setY_Axis(y_axis);
response.getWriter().write(chart.createChart());
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
a-small-project.zip_open
共1个文件
txt:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 32 浏览量
2022-09-23
12:41:52
上传
评论
收藏 1KB ZIP 举报
温馨提示
利用open flash chart 创建报表
资源推荐
资源详情
资源评论
收起资源包目录
a-small-project.zip (1个子文件)
a small project.txt 3KB
共 1 条
- 1
资源评论
小波思基
- 粉丝: 70
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功