多语言展示
当前在线:1132今日阅读:75今日分享:44

jsp页面动态显示年、月、日的趋势图报表

当代社会,信息技术如此的发达,要求也越来越高了,对数据显示方便更为苛刻。   最原始的数据显示就是数据库表中的方式,但是很多不是专业的人看不懂这个表,或者是看多了觉得累,乏味,要求做成趋势图,饼状图甚至是动画的,更深得人心!  我现在要把GPS定位的位置变化做成一个趋势图,一开始接收这个项目的时候,我直接把报表做成一个表格的形式显示在页面上,但是客户觉得太过于白板,没有吸引别人的眼球,要求做一个趋势图,可以查看年月日,任意的变化图!  现在,我就会java+jsp+js来做一个趋势图报表。以下这个图标太呆板了!
工具/原料
1

Myeclipse/eclipse

2

浏览器

3

电脑

4

mysql数据库

5

Matplot3d_4_dhj_f(v1.0).jar包

下载jar包

Matplot3d_4_dhj_f(v1.0).jar  下载地址是  https://gitee.com/tanling8334/Matplot3D-for-Java你可以先把页面上两个jar包和案例代码都下载下来,好好研究研究一下

实现的功能

1、从数据库里面查询数据,然后呈现在图形上面2、可以放大和缩小3、按住鼠标不断的调整图形的视角

具体代码
1

加载类资源管理器package tanling.matplot4j.demo;import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;public class TextFileHelper {    /*     * author:@命运的信徒     * date:2019/2/19     * arm:获取路径     */   由于不能发表超过1500字的经验,代码在下方以图片的形式展示    }}

2

设置组件的字体、大小package tanling.matplot4j.demo;import java.util.Enumeration;import javax.swing.UIManager;import javax.swing.plaf.FontUIResource;import tanling.matplot_4j.comment.SysConstents;public class UIUtil {    public static void initGlobalFont(){        //设置各个组件的字体        FontUIResource fontUIResource = new FontUIResource(SysConstents.DEFAULT_FONT);        //        for (Enumeration keys = UIManager.getDefaults().keys();                 keys.hasMoreElements();) {            Object key = keys.nextElement();            Object value= UIManager.get(key);            if (value instanceof FontUIResource) {                UIManager.put(key, fontUIResource);            }          }    }}

连接数据库

数据库连接池的代码package cn.com.jdbc;import java.io.InputStream;import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.Properties;import javax.sql.DataSource;import org.apache.commons.dbcp.BasicDataSourceFactory; /*** @ClassName: JdbcUtils_DBCP* @Description: 数据库连接工具类* @author: 命运的信徒* @date: 2018-10-13 **/ public class JdbcUtils_DBCP {    /**     * 在java中,编写数据库连接池需实现java.sql.DataSource接口,每一种数据库连接池都是DataSource接口的实现     * DBCP连接池就是java.sql.DataSource接口的一个具体实现     */            由于不能发表超过1500字的经验,代码在下方以图片的形式展示    }}

3d可视化代码
1

右侧鼠标伸缩大小以及观察位置的面板package cn.com.test;import java.awt.BorderLayout;import java.awt.TextArea;import javax.swing.BorderFactory;import javax.swing.JPanel;import javax.swing.JTabbedPane;import tanling.matplot_4j.comment.SysConstents;import tanling.matplot_4j.d3d.facade.MatPlot3DMgr;import tanling.matplot_4j.style.ColorHelper;public abstract class AbsContentPanel extends JPanel {    /**     *      */   由于不能发表超过1500字的经验,代码在下方以图片的形式展示 }

2

查询数据库,把数据显示在图上package cn.com.test;import java.awt.geom.Point2D;import java.util.ArrayList;import java.util.List;import tanling.matplot4j.demo.TextFileHelper;import tanling.matplot_4j.d3d.facade.MatPlot3DMgr;public class Curves2DContentPanel extends AbsContentPanel {    /**     *      */   由于不能发表超过1500字的经验,代码在下方以图片的形式展示 }

3

具体查询数据库的java代码package cn.com.test;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.List;import cn.com.jdbc.JdbcUtils_DBCP;public class Displacement {    static List listx = null;    static List listy = null;    static List listh = null;    private static Connection conn = null;    private static PreparedStatement st = null;    private static ResultSet rs = null;    public static void selectPlace(String address, String rq) {        listx=new ArrayList();        listy=new ArrayList();        listh=new ArrayList();        // 1.根据地址、当天的日期、和标准量,来计算偏移量        SimpleDateFormat sim = new SimpleDateFormat('yyyy-MM-dd');        // 2.查询数据库里当天的所有位移量        String sql = 'select * from port where StationName=? and StartTime like ? order by StartTime asc';        rq = rq + ' %';        String[] str = new String[] { address, rq };        try {            // 获取数据库连接            // 获取数据库连接            conn = JdbcUtils_DBCP.getConnection();            st = conn.prepareStatement(sql);            if (str != null) {                for (int i = 0; i < str.length; i++) {                    st.setString(i + 1, str[i]);                }            }            rs = st.executeQuery();            while (rs.next()) {                // 1.x y 三个集合                listx.add(rs.getString(8));                listy.add(rs.getString(9));                listh.add(rs.getString(10));            }        } catch (SQLException e) {            e.getStackTrace();        } finally {            try {                if (rs != null) {                    rs.close();                }                if (st != null) {                    st.close();                }                if (conn != null) {                    conn.close();                }             } catch (SQLException e) {                // TODO Auto-generated catch block                e.printStackTrace();            }        }     } }

4

鼠标事件package cn.com.test;import java.awt.Color;import java.awt.Dimension;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Observable;import java.util.Observer;import javax.swing.BorderFactory;import javax.swing.ButtonGroup;import javax.swing.JCheckBox;import javax.swing.JComponent;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JRadioButton;import javax.swing.JTextField;import tanling.matplot_4j.comment.SysConstents;import tanling.matplot_4j.d3d.base.speg.Point3D;import tanling.matplot_4j.d3d.facade.MatPlot3DMgr;import tanling.matplot_4j.style.ColorHelper;public class OptionPanel extends JPanel implements Observer {   /**     *      */   由于不能发表超过1500字的经验,代码在下方以图片的形式展示    }

5

主窗口package cn.com.test;import java.awt.BorderLayout;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.SwingUtilities;public class Test extends JFrame {        /**     *      */    private static final long serialVersionUID = 1L;    private MainPanel mainPanel;    public Test(String title) {        super(title);        this.mainPanel=new MainPanel(this);                JPanel contentPanel=new JPanel();        contentPanel.setLayout(new BorderLayout());        this.setContentPane(contentPanel);                mainPanel.setType(MainPanel.CURVES_PLANE);        contentPanel.add(mainPanel,BorderLayout.CENTER);    }     public MainPanel getMainPanel() {        return mainPanel;    }        public static void main(String[] args) {                Test jf = new Test('小栗子');                    try {                        SwingUtilities.updateComponentTreeUI(jf);        } catch (Exception e) {            e.printStackTrace();        }         jf.setDefaultCloseOperation(jf.EXIT_ON_CLOSE);        jf.setSize(1300, 820);        jf.setVisible(true);                    }    }

6

如果使用连接池的话,别忘记配置还有别忘记引入相应的jar包。

推荐信息