public DCharts createChart( List<FuelSpendMonthlyCostBean> fuelSpendMonthlyCostBeanList, BigDecimal grandTotal) { // Deciding Ticks e.g. .5, 1, 1.5, 2, 2.5 ... etc String label = "Total Fuel Spend"; String grandTotalAmount = df.format(Double.parseDouble(grandTotal.toString())); title = "Total Fuel Spend for the last " + fuelSpendMonthlyCostBeanList.size() + " Month(s): R" + grandTotalAmount; float tickInterval = Float.parseFloat("350000"); Object minTickValue = 0; BigDecimal highestTotal = BigDecimal.ZERO; for (FuelSpendMonthlyCostBean FuelSpendMonthlyCostBean : fuelSpendMonthlyCostBeanList) { if (FuelSpendMonthlyCostBean.getMonthlyAmountSpend().compareTo(highestTotal) > 0) { highestTotal = FuelSpendMonthlyCostBean.getMonthlyAmountSpend(); } } if (highestTotal.compareTo(new BigDecimal("350000")) < 0) { tickInterval = Float.parseFloat("50000"); // minTickValue=5000; } else if (highestTotal.compareTo(new BigDecimal("600000")) < 0) { tickInterval = Float.parseFloat("100000"); // minTickValue=10000; } List<Object> totalList = new ArrayList<>(); List<Object> monthList = new ArrayList<>(); // Get Objects of Data for (FuelSpendMonthlyCostBean fuelSpendMonthlyCostBean : fuelSpendMonthlyCostBeanList) { totalList.add(fuelSpendMonthlyCostBean.getMonthlyAmountSpend()); // Truncate the Names monthList.add(fuelSpendMonthlyCostBean.getMonth()); } Object[] totalListArray = totalList.toArray(new Object[totalList.size()]); Object[] monthListArray = monthList.toArray(new Object[monthList.size()]); final BarChart barChart = new BarChart(); DCharts dBarChart = barChart.buildBarChart( totalListArray, monthListArray, tickInterval, label, minTickValue, title); dBarChart.setWidth("600px"); dBarChart.setHeight("300px"); dBarChart.show(); // USEFUL Statement // dBarChart.setMarginBottom(10); // dBarChart.setMarginLeft(10); // dBarChart.setMarginRight(10); // dBarChart.setMarginTop(-3); // dBarChart.getOptions().setTitle(""); return dBarChart; }
// private VerticalLayout overallPlotLayout; public ProtOverviewLineChart(ComparisonProtein[] comparisonProteins, int width) { this.setHeight("100%"); this.initLineChart(); this.setWidthUndefined(); if (comparisonProteins.length == 1) { height = 110; } else { height = (comparisonProteins.length * 90) + 20; } this.setStyleName(Reindeer.LAYOUT_WHITE); DataSeries dataSeries = new DataSeries(); DataSeries dataSeries2 = dataSeries.newSeries(); DataSeries dataSeries1 = dataSeries.newSeries(); for (ComparisonProtein cp : comparisonProteins) { if (cp == null) { continue; } if (cp.getCellValue() < 0) { dataSeries1.add(cp.getComparison().getComparisonHeader(), cp.getCellValue() * 100); } dataSeries2.add(cp.getComparison().getComparisonHeader(), cp.getCellValue() * 100); } this.setHeight(height + "px"); VerticalLayout ticksLayout = new VerticalLayout(); ticksLayout.setWidth("80px"); ticksLayout.setHeight((height - 30) + "px"); ticksLayout.setStyleName(Reindeer.LAYOUT_WHITE); ticksLayout.setSpacing(false); ticksLayout.setMargin(new MarginInfo(false, false, false, true)); this.addComponent(ticksLayout); Label upLab = new Label("Up Reg"); upLab.setStyleName("upregchartlabel"); upLab.setHeight("30px"); ticksLayout.addComponent(upLab); ticksLayout.setComponentAlignment(upLab, Alignment.TOP_CENTER); // VerticalLayout subupLab = new VerticalLayout(); // subupLab.setStyleName(Reindeer.LAYOUT_BLUE); // subupLab.setHeight("100%"); // subupLab.setWidth("20px"); // ticksLayout.addComponent(subupLab); // ticksLayout.setExpandRatio(subupLab, 0.2f); // ticksLayout.setComponentAlignment(subupLab, Alignment.BOTTOM_CENTER); Label notLab = new Label("Not Reg"); notLab.setStyleName("notregchartlabel"); notLab.setHeight("30px"); ticksLayout.addComponent(notLab); ticksLayout.setComponentAlignment(notLab, Alignment.MIDDLE_CENTER); // VerticalLayout subdownLab = new VerticalLayout(); // subdownLab.setStyleName(Reindeer.LAYOUT_BLUE); // subdownLab.setHeight("100%"); // ticksLayout.addComponent(subdownLab); // ticksLayout.setComponentAlignment(subdownLab, Alignment.BOTTOM_CENTER); // ticksLayout.setExpandRatio(subdownLab, 0.2f); Label downLab = new Label("Down Reg"); downLab.setStyleName("downregchartlabel"); downLab.setHeight("30px"); ticksLayout.addComponent(downLab); ticksLayout.setComponentAlignment(downLab, Alignment.BOTTOM_CENTER); chart2 = new DCharts() .setDataSeries(dataSeries) .setOptions(options2) .setMarginLeft(0) .setMarginTop(0); // .show(); this.addComponent(chart2.show()); chart2.setWidth((width - 100) + "px"); chart2.setHeight("100%"); }