Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. <h:form id="form">
  2. <p:poll interval="3" update="votes" autoStart="true"/>
  3. <p:chart id="votes" type="bar" model="#{chartView.barModel}"
  4. style="width:400px;height:300px"/>
  5. </h:form>
  6.  
  7. @SessionScoped
  8. @ManagedBean
  9. public class ChartView implements Serializable {
  10.  
  11. private BarChartModel barModel;
  12.  
  13. @PostConstruct
  14. public void init() {
  15. createBarModels();
  16. }
  17. public BarChartModel getBarModel() {
  18. return barModel;
  19. }
  20.  
  21. private BarChartModel initBarModel() {
  22. BarChartModel model = new BarChartModel();
  23.  
  24. ChartSeries boys = new ChartSeries();
  25. boys.setLabel("Boys");
  26. int random1 = (int)(Math.random() * 200);
  27. int random2 = (int)(Math.random() * 200);
  28. int random3 = (int)(Math.random() * 200);
  29. boys.set("2004", random1);
  30. boys.set("2005", random2);
  31. boys.set("2006", random1);
  32. boys.set("2007", random2);
  33. boys.set("2008", random3);
  34.  
  35. model.addSeries(boys);
  36.  
  37. return model;
  38. }
  39.  
  40. private void createBarModels() {
  41. createBarModel();
  42. }
  43.  
  44. private void createBarModel() {
  45. barModel = initBarModel();
  46.  
  47. barModel.setTitle("Bar Chart");
  48. barModel.setLegendPosition("ne");
  49.  
  50. Axis xAxis = barModel.getAxis(AxisType.X);
  51. xAxis.setLabel("Gender");
  52.  
  53. Axis yAxis = barModel.getAxis(AxisType.Y);
  54. yAxis.setLabel("Births");
  55. yAxis.setMin(0);
  56. yAxis.setMax(200);
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement