Time as the transverse chart (morris.js) beyond yesterday's own series (8)

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Beyond yesterday's own series(8)

Morris.js's website has detailed examples:

Pay special attention to its dependence:

<link rel="stylesheet" href="http://cdn.oesmith.co.uk/morris-0.4.3.min.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="http://cdn.oesmith.co.uk/morris-0.4.3.min.js"></script>

Put a div:

<div class="graph-container">
        The user growth within 20 days the number
        <div id="examplefirst" class="graph" style="position: relative;">
            <div id="myfirstchart" style="height: 250px;"></div>
        </div>
    </div>

script:

    <script >
    // The background to the data. 
    var data = '$data';
    data = data.replace(/&quot;/g, '"');
    var array = eval(data);
    new Morris.Line({
        xLabels: "day",
         // ID of the element in which to draw the chart.
          element: 'myfirstchart',
          // Chart data records -- each entry in this array corresponds to a point on
          // the chart.
          data: array,
          // The name of the data record attribute that contains x-values.
          xkey: 'year',
          // A list of names of data record attributes that contain y-values.
          ykeys: ['value'],
          // Labels for the ykeys -- will be displayed when you hover over the
          // chart.
          labels: ['Value']
    });
    </script>

It can show ~ as long as the attention of the plug in parameter data is an array.

Backstage data similar to:

[
    { year: '2008', value: 20 },
    { year: '2009', value: 10 },
    { year: '2010', value: 5 },
    { year: '2011', value: 5 },
    { year: '2012', value: 20 }
  ]

So the background query I made of cyclic query mode, I think it must be a better way to find out all the needs of data at a time. Under the first implementation of (hibernate):

Action: Note circulation part of the query, only in a day each time, if the amount is too much may affect the database performance

        // Y shaft end time processing:  20130201 23:59:59:999
        Date endDate = WXDateUtil.getTodayLastTime();
        // The default Y axis start time 20 days ago to now
        Date beginDate = WXDateUtil.getBeforeDays(endDate, 20);
        // The list of Y point in time axis
        List<Date> dateList = new ArrayList<Date>();
        // First put the start time
        Date midDate = beginDate;
        while(endDate.after(midDate)){
            dateList.add(midDate);
            // The next day
            midDate = WXDateUtil.getNextDay(midDate);
        }
        // Put the end of time
        dateList.add(endDate);
        JSONArray array = new JSONArray();
        if(dateList.size() > 0){
            for (int i = 0; i <dateList.size() - 1; i++) {
                long count = clientService.getCountByTypeAndTime(0, dateList.get(i), dateList.get(i+1));
                JSONObject object = new JSONObject();
                object.put("year", WXDateUtil.dateToStr(dateList.get(i+1), "yyyy-MM-dd" ));
                object.put("value", count);
                array.add(object);
            }
        }
        context.put("data", array.toJSONString());

Processing time of Util package:

public class WXDateUtil {


    private static final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd";

    /**
     * The date type into a string representation. 
     *
     * @param Date date
     * @param DateFormat date format, such as "yyyy/MM/dd", "yyyy year MM month DD"
     * @return Date string
     */
    public static String toLocaleString(Date date, String dateFormat) {
        if (date == null) {
            return "";
        }

        if (StringUtil.isBlank(dateFormat)) {
            return new SimpleDateFormat(DEFAULT_DATE_FORMAT).format(date);
        }

        return new SimpleDateFormat(dateFormat).format(date);
    }

    /**
     * The date type conversion into "yyyy/MM/dd/" string form. 
     *
     * @param date
     * @return Date string
     */
    public static String toLocaleString(Date date) {
        return toLocaleString(date, null);
    }

    /**
     * After obtaining the sysdate+hours time
     *
     * @param Hours earlier or later time
     * @return After sysdate+hours time
     */
    public static Date getSysDate(int hours) {
        Calendar time = Calendar.getInstance();

        time.add(Calendar.HOUR, hours);

        return time.getTime();
    }

    /**
     * Method: time difference
     *
     * @param firstDate
     * @param lastDate
     */
    public static int getTimeIntervalDays(Date firstDate, Date lastDate) {
        long intervals = lastDate.getTime() - firstDate.getTime() + (60 * 1000);

        if (intervals > 0) {
            long daysd = intervals / (24 * 60 * 60 * 1000);

            return new Long(daysd).intValue();
        }

        return 0;
    }

    /**
     * Method: small time
     *
     * @param firstDate
     * @param lastDate
     */
    public static int getTimeIntervalHours(Date firstDate, Date lastDate) {
        long intervals = lastDate.getTime() - firstDate.getTime() + (60 * 1000);

        if (intervals > 0) {
            long longHours = (intervals / (60 * 60 * 1000)) % 24;

            return new Long(longHours).intValue();
        }

        return 0;
    }

    /**
     * Method: minute difference
     *
     * @param firstDate
     * @param lastDate
     */
    public static int getTimeIntervalMins(Date firstDate, Date lastDate) {
        long intervals = lastDate.getTime() - firstDate.getTime() + (60 * 1000);

        if (intervals > 0) {
            long longMins = (intervals / (60 * 1000)) % 60;

            return new Long(longMins).intValue();
        }

        return 0;
    }

    /**
     * Method: parse date
     *
     * @param date
     * @param dateformat
     */
    public static Date parseDate(String date, String dateformat) {
        SimpleDateFormat sdf = new SimpleDateFormat(dateformat);

        try {
            return sdf.parse(date);
        } catch (ParseException e) {
            return null;
        }
    }

    /**
     * Comparison of date is greater than the current date
     */
    public static boolean afterNow(Date date) {
        if (date == null) {
            return false;
        }

        Calendar nowCar = Calendar.getInstance();
        Calendar car = Calendar.getInstance();

        car.setTime(date);

        return car.after(nowCar);
    }

    /*
     * Check whether the early days
     */
    public static boolean afterDays(Date date, int day) {
        if (date == null) {
            return false;
        }

        Calendar levelDay = Calendar.getInstance();
        Calendar createDay = Calendar.getInstance();

        createDay.setTime(date);
        createDay.add(Calendar.DATE, day);

        if (createDay.after(levelDay)) {
            return true;
        } else {
            return false;
        }
    }

    public static String getIconPathDay(){
        GregorianCalendar now;
        String year, day, month, hour;
        now = new GregorianCalendar();
        year = String.valueOf(now.get(Calendar.YEAR));
        month = (now.get(Calendar.MONTH) + 1) <10 ? "0" + String.valueOf(now.get(Calendar.MONTH) + 1) : String.valueOf(now.get(Calendar.MONTH) + 1);
        day = String.valueOf(now.get(Calendar.DAY_OF_MONTH));
        StringBuilder sb = new StringBuilder();
        sb.append(year).append("/");
        sb.append(month).append("/");
        sb.append(day).append("/");
        return sb.toString();
    }

    /*
     * Check whether the early hours
     */
    public static boolean afterHours(Date date, int hours) {
        if (date == null) {
            return false;
        }

        Calendar levelDay = Calendar.getInstance();
        Calendar createDay = Calendar.getInstance();

        createDay.setTime(date);
        createDay.add(Calendar.HOUR, hours);

        if (createDay.after(levelDay)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Get the current system date
     */
    public static Date getCurrentTime() {
        return new Date();
    }

    /**
     * How much time before the return time, seconds can be negative
     *
     * @param when
     * @param seconds
     */
    public static Date addTime(Date when, int seconds) {
        Calendar c = Calendar.getInstance();

        c.setTime(when);
        c.add(Calendar.SECOND, seconds);

        return c.getTime();
    }

    /**
     * @param date
     * @param pattern "yyyy-MM-dd HH:mm:ss.SSS"
     * @return
     */
    public static String dateToStr(Date date, String pattern) {
        if (pattern == null) {
            pattern = "yyyy-MM-dd HH:mm:ss.SSS";
        }
        DateFormat ymdhmsFormat = new SimpleDateFormat(pattern);

        return ymdhmsFormat.format(date);
    }

    /**
     * @param str
     * @param pattern "yyyy-MM-dd HH:mm:ss.SSS"
     * @return
     * @throws ParseException
     */
    public static Date strToDate(String str, String pattern) {
        if (pattern == null) {
            pattern = "yyyy-MM-dd HH:mm:ss.SSS";
        }
        DateFormat ymdhmsFormat = new SimpleDateFormat(pattern);
        try {
            return ymdhmsFormat.parse(str);
        } catch (ParseException e) {
            return null;
        }
    }

    /**
     * Get the date
     *
     * @date 2009-2-20
     */
    public static Date getToday() {
        Calendar ca = Calendar.getInstance();
        return ca.getTime();
    }

    /**
     * @date 2009-2-20
     */
    public static Date mkDate(int year, int month, int date) {
        Calendar ca = Calendar.getInstance();
        ca.set(year, month - 1, date);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        sdf.format(ca.getTime());
        return ca.getTime();
    }

    /**
     * <li></li>
     *
     * @param date1
     * @param date2 <li></li>
     */
    public static boolean compareTwoDate(Date date1, Date date2) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd HH:mm");
        return simpleDateFormat.format(date1).equals(simpleDateFormat.format(date2));
    }

    /**
     * <li></li>
     *
     * @param date1
     * @param date2 <li></li>
     */
    public static boolean compareTwoDateDay(Date date1, Date date2) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        return simpleDateFormat.format(date1).equals(simpleDateFormat.format(date2));
    }
    
    /**
     * Gets the file name in the file path, similar to Linux, the basename command
     * @param path
     * @return
     */
    public static String getFileName(String path){
        String str[] = path.split("/");
        return str[str.length-1];
        
    }
    
    /**
     * The last time the Date has today
     * @return 23:59:59
     */
    public static Date getTodayLastTime(){
        Calendar cal = Calendar.getInstance(); // represents right now, i.e. today's date
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MILLISECOND, 999); // credit to f1sh
        return cal.getTime();
    }
            
    /**
     * The specified date pushed back a few days of the date of
     * @param date
     * @param N days
     * @return
     */
    public static Date getBeforeDays(Date date, int n){
        Long dateTime = date.getTime() - n*24*60*60*1000;
        return new Date(dateTime);
    }
    
    /**
     * The specified date pushed back the date of 1 days
     * @param date
     * @return
     */
    public static Date getNextDay(Date date){
        Long dateTime = date.getTime() + 24*60*60*1000;
        return new Date(dateTime);
    }
    
    /**
     * 
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(getToday());
        
    }
}

Then know the hibernate query count way:

Reference resources:

Example:

    public long getCountByTypeAndTime(int type, Date beginTime, Date endTime) {

        Criteria criterion = this.getSession().createCriteria(ClientDO.class);
        if(type!= 0){
            criterion.add(Restrictions.eq("type", type));
        }
        if (beginTime != null) {
            criterion.add(Restrictions.ge("createTime", beginTime));
        }
        if (endTime != null) {
            criterion.add(Restrictions.le("createTime", endTime));
        }
        
        return (Long)criterion.setProjection(Projections.rowCount()).uniqueResult();
        
    }




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Harrison at November 18, 2013 - 6:59 AM