List of usage examples for org.jfree.chart.renderer.xy XYLineAndShapeRenderer clone
@Override public Object clone() throws CloneNotSupportedException
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getDailyIntegratedStats(Session s) throws CloneNotSupportedException { JFreeChart chart;/*from w w w . j av a 2 s .co m*/ List<DailyStatsModel> stats = (new SafeHibList<DailyStatsModel>( s.createQuery("select ds from DailyStatsModel as ds where day<? and day>=? order by day desc") .setDate(0, new Date()).setDate(1, GraphServlet.getStartDate()))).list(); TimeSeriesCollection theData = new TimeSeriesCollection(); TimeSeriesCollection theData2 = new TimeSeriesCollection(); TimeSeries users = new TimeSeries("Total Users", Day.class); theData.addSeries(users); TimeSeries regulars = new TimeSeries("Regular Members", Day.class); theData2.addSeries(regulars); int numUsers = Helpers.getGroup("Org").getNumMembers(); int numReg = Helpers.getGroup("Regular").getNumMembers(); for (DailyStatsModel ds : stats) { Day theDay = new Day(ds.getDay()); users.add(theDay, numUsers); regulars.add(theDay, numReg); numUsers -= (ds.getMailinglistsignups() + ds.getSignups() - ds.getDeletions()); numReg -= (ds.getRegupgrades() - ds.getRegdowngrades()); } chart = ChartFactory.createTimeSeriesChart("Membership", "Day", "Users", theData, true, true, true); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis axis2 = new NumberAxis("Regular Members"); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, MovingAverage.createMovingAverage(theData2, "", 14, 0)); plot.mapDatasetToRangeAxis(1, 1); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(0); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer = (XYLineAndShapeRenderer) renderer.clone(); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); plot.setRenderer(1, renderer); return chart; }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getLastLogin(Session s) throws CloneNotSupportedException { Integer numCurrentLogins = ((Long) s .createQuery("select count(*) from UserModel " + "where currentLogin is not null and currentLogin >= :date") .setDate("date", getStartDate()).uniqueResult()).intValue(); List currentStats = s/*from www.ja va2 s. c o m*/ .createSQLQuery("SELECT DATE(currentLogin) as date, count( * ) as lastLogins " + "FROM users where currentLogin is not null and currentLogin >= :date " + "GROUP BY DATE( currentLogin )") .addScalar("date", Hibernate.DATE).addScalar("lastLogins", Hibernate.INTEGER) .setDate("date", getStartDate()).list(); TimeSeriesCollection theData = new TimeSeriesCollection(); TimeSeriesCollection theData2 = new TimeSeriesCollection(); TimeSeries current = new TimeSeries("Num Latest Sign-ins", Day.class); theData.addSeries(current); TimeSeries current2 = new TimeSeries("Signed-in Users Since", Day.class); theData2.addSeries(current2); for (Object ds : currentStats) { Date date = (Date) ((Object[]) ds)[0]; Day day = new Day(date); Integer integer = (Integer) ((Object[]) ds)[1]; current.add(day, integer); numCurrentLogins -= integer.intValue(); current2.add(day, numCurrentLogins); } JFreeChart chart = ChartFactory.createTimeSeriesChart("Sign-in Recency", "Day", "Sign-ins", theData, true, true, true); XYPlot plot = (XYPlot) chart.getPlot(); NumberAxis axis2 = new NumberAxis("Users"); plot.setRangeAxis(1, axis2); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); plot.setDataset(1, theData2); plot.mapDatasetToRangeAxis(1, 1); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(0); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f)); renderer = (XYLineAndShapeRenderer) renderer.clone(); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f)); plot.setRenderer(1, renderer); return chart; }