Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h:form id="form">
- <p:poll interval="3" update="votes" autoStart="true"/>
- <p:chart id="votes" type="bar" model="#{chartView.barModel}"
- style="width:400px;height:300px"/>
- </h:form>
- @SessionScoped
- @ManagedBean
- public class ChartView implements Serializable {
- private BarChartModel barModel;
- @PostConstruct
- public void init() {
- createBarModels();
- }
- public BarChartModel getBarModel() {
- return barModel;
- }
- private BarChartModel initBarModel() {
- BarChartModel model = new BarChartModel();
- ChartSeries boys = new ChartSeries();
- boys.setLabel("Boys");
- int random1 = (int)(Math.random() * 200);
- int random2 = (int)(Math.random() * 200);
- int random3 = (int)(Math.random() * 200);
- boys.set("2004", random1);
- boys.set("2005", random2);
- boys.set("2006", random1);
- boys.set("2007", random2);
- boys.set("2008", random3);
- model.addSeries(boys);
- return model;
- }
- private void createBarModels() {
- createBarModel();
- }
- private void createBarModel() {
- barModel = initBarModel();
- barModel.setTitle("Bar Chart");
- barModel.setLegendPosition("ne");
- Axis xAxis = barModel.getAxis(AxisType.X);
- xAxis.setLabel("Gender");
- Axis yAxis = barModel.getAxis(AxisType.Y);
- yAxis.setLabel("Births");
- yAxis.setMin(0);
- yAxis.setMax(200);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement