Line chart drops to X axis when there is no value


« Back to message list

Enter your email address to get email updates on this topic. You can stop receiving updates by clicking the link in the update email messages.

Posted by Max on 6th August 2016
Hi,

I've a line chart to indicate certain parameters on Y- axis which is shown month wise on X axis. I've data only till july and the graph stoops to zero on after july month.The line graph should at stop instead at that point.Please find html javascript below.
<wicket:extend>
   <div class="container">
    <div class="row pag_content_row">
     <div class="col s12"></div>
    </div>
   </div>
   <div class="container">
    <div class="row ">
     <div class="col s12">
      <div class="card">
       <div class="pag_title">
        <h1>DashBoard</h1>
       </div>
       <div class="page_hold">
        <div class="card frm_register_holder" style="width: 100%;">
         <div class="col m12">
          <form novalidate="novalidate" id="DefineDashboardForm"
           wicket:id="DefineDashboardForm">
           <div class="cl"></div>
           <div class="cl"></div>
           <div class="row">
           <table style="background: aliceblue;">
           <tr>
           <td style="width:50%;border-width: 2px; border-style: solid; border-color: olive;">
           <div class="row">
            <label style="font-size: large; color: black;">Total no. of visitors by region</label>
           </div>
           <div class="row">
            <div class="form_row" style="margin-left: 110px;">
             <div class="col s4 m3" style="padding-top: 10px;margin-left: 73px;">
              <label>Year</label>
             </div>
             <div class="col s4 m3" style="padding-top:10px;">
              <label>Month</label>
             </div>
            </div>
           </div>
           <div class="row">
            <div class="form_row" style="margin-left:182px;">
             <div class="col s4 m3" style="padding-top: 10px;margin-left: 30px;">
              <select wicket:id="ddcYear1"></select>
             </div>
             <div class="col s4 m3" style="padding-top:10px;">
              <select wicket:id="ddcQuarter"></select>
             </div>
            </div>
           </div>
           <br /> <br />
             <div class="banBox" style="margin-top: 22px;">
             <canvas id="bar3" width="550" height="250"></canvas>
           <div class="row">
           <span id="names1" wicket:id="lblname1" style="visibility: hidden;"></span>
           <span id="value1" wicket:id="lblvalue1" style="visibility: hidden;"></span>
                    <script>
                     var data = document.getElementById("value1").innerHTML;
                     var array =data.split(",").map(Number);
                     var names= document.getElementById("names1").innerHTML;
                     var array1 = names.split(",");
                     var bar3 = new RGraph.Bar('bar3', array);
                     bar3.Set('chart.labels',array1);
                     bar3.Set('chart.tooltips',array.map(String));
                     bar3.Set('chart.colors', [RGraph.LinearGradient(bar3, 0,0,0,200, 'red', 'rgba(255,255,255,1)')]);
                     bar3.Set('chart.shadow', true);
                     bar3.Set('chart.shadow.offsetx', 3);
                     bar3.Set('chart.shadow.offsety', -3);
                     bar3.Set('chart.shadow.blur', 5);
                     bar3.Set('chart.shadow.color', '#ccc');
                     bar3.Set('chart.background.grid', false);
                     bar3.Set('chart.ymax',25000);
                     bar3.Set('chart.gutter.left',50);
                     bar3.Draw();
               </script>
          </div>
           </div>
           </td>
           <td style="width:50%;border-width: 2px; border-style: solid; border-color: olive;">
            <div class="row">
             <label style="font-size: large; color: black;">Yearly KPI's</label>
            </div>
            <div class="row">
            <div class="form_row" style="margin-left: 108px;">
             <div class="col s4 m3" style="padding-top: 10px;">
              <label>From Year</label>
             </div>
             <div class="col s4 m3" style="padding-top:10px;">
              <label>To Year</label>
             </div>
             <div class="col s4 m3" style="padding-top:10px;">
              <label>KPI</label>
             </div>
            </div>
           </div>
           <div class="row">
            <div class="form_row" style="margin-left: 108px;">
             <div class="col s4 m3" style="padding-top: 10px;">
              <select wicket:id="ddcYear11"></select>
             </div>
             <div class="col s4 m3" style="padding-top: 10px;">
              <select wicket:id="ddcYear12"></select>
             </div>
             <div class="col s4 m5" style="padding-top:10px;">
              <select wicket:id="ddcKPI" style="width:100%;"></select>
            </div>
            </div>
           </div>
           <br /> <br />
           <div class="banBox" style="margin-top: 22px;">
           <div class="row">
             <span id="names2" wicket:id="lblname2" style="visibility: hidden;"></span>
             <span id="value2" wicket:id="lblvalue2" style="visibility: hidden;"></span>
             <span id="value3" wicket:id="lblvalue3" style="visibility: hidden;"></span>
             <span id="value4" wicket:id="lblvalue4" style="visibility: hidden;"></span>
             <span id="value5" wicket:id="lblvalue5" style="visibility: hidden;"></span>
                   </div>
                   <div class="row">
            <canvas id="line1" width="550" height="250"></canvas>
           
            <script>
            var arr;
            var array8=['Year 1','Year 2','Year 3','Year 4'];
            var names= document.getElementById("names2").innerHTML;
                     var array1 = names.split(",");
                     var data = document.getElementById("value2").innerHTML;
                     var array =data.split(",").map(Number);
                     var data1 = document.getElementById("value3").innerHTML;
                     var array2 =data1.split(",").map(Number);
                     var data2 = document.getElementById("value4").innerHTML;
                     var array3 =data2.split(",").map(Number);
                     var data3 = document.getElementById("value5").innerHTML;
                     var array4 =data3.split(",").map(Number);
               var line1 = new RGraph.Line('line1',array,array2,array3,array4);
               line1.Set('chart.labels',array1);
              // line1.Set('chart.numxticks',array1);
              // line1.Set('chart.title','Yearly KPI Variance');
                     line1.Set('chart.numyticks',5);
                     line1.Set('chart.linewidth',2);
                     line1.Set('chart.shadow', false);
                     line1.Set('chart.noxaxis', true);
                     line1.Set('chart.textSize', 10);
                     line1.Set('chart.textColor', '#999');
                     line1.Set('chart.textAngle', 0);
                     line1.Set('chart.textSize', 10);
                     line1.Set('chart.spline', false);
                     line1.Set('chart.hmargin', 5);
                     //line1.Set('chart.BackgroundBarcolor1', 'white');
                    // line1.Set('chart.BackgroundBarcolor2', 'white');
                     //line1.Set('chart.BackgroundGridColor', 'rgba(238,238,238,1)');
                     //line1.Set('chart.colors', ['rgba(0,0,0,0)']);
                    line1.Set('chart.key',array8);
                     line1.Set('chart.filled', false);
                     line1.Set('chart.fillstyle', ['red','blue','#0f0']);
                     line1.Set('chart.tickmarks', true);
                     line1.Set('chart.gutter.left',100);
                   
               line1.Draw();
              
              // line1.defined(function(d) { return !isNaN(d[1]); });
               </script>
           </div></div>
           </td>
           </tr>
           </table>
           </div>
          </form>
         </div>
        </div>
       </div>
      </div>
     </div>
    </div>
   </div>
   <!-- Scripts-->
   <script src="js/materialize.js"></script>
   <script src="js/init.js"></script>
   <script>
    $(document).ready(function() {
     $('select').material_select();
    });
    $('.datepicker').pickadate({
     selectMonths : true, // Creates a dropdown to control month
     selectYears : 15,
     format : 'dd/mm/yyyy'
    // Creates a dropdown of 15 years to control year
    });
   </script>
</wicket:extend>


I've found that defined() be used to stop the graph for zero values but I could not implement it properly.
Please suggest.
Posted by Richard on 6th August 2016
Hi there,

Short of reading all of your code, is this something you're referring to?

www.rgraph.net/demos/line-null-values.html

If it is then you need to use null values instead of zero. Like this:




var line = new RGraph.Line({
     id: 'cvs',
     data: [5,7,4,8,null,null,null],
     options: {
         // ...
     }
}).draw();







Richard
Posted by Max on 6th August 2016
Dear Richard,

Thank you so much for the help. But the data set for my graph is not defined in the javascript file. It is derived from a query which is executed in another java file.The data values are not handled directly in the code.The data objects from the java file are defined are referred in the .html file. Please find my java code below.



import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;


public class DefineDashboard extends Home{

  DefineDashboardModel defineDashboardModel = new DefineDashboardModel();
  String script="";
  String value1="";
  String names1="";
  String value2="";
  String value3="";
  String value4="";
  String value5="";
  String names2="";
  String action="add";
  @SpringBean
  ReportServiceImpl reportServiceImpl;
  @SpringBean
  ConfigurationService configurationService;
  @SpringBean
  MasterHotelHomeServiceImpl masterHotelHomeServiceImpl;
  @SpringBean
  MonthlyproductionByNationalityImpl masterwtccountrieslistservice;
  @SpringBean
  MonthlykpitRespository monthlykpitRespository;
  public DefineDashboard(){
   add(new DefineDashboardForm("DefineDashboardForm"));
  }
 
  public DefineDashboard(String year1,String quarter,String year11,String year12,String kpi,String action){
   this.action=action;
   this.defineDashboardModel.setDdcYear1(year1);
   this.defineDashboardModel.setDdcQuarter(quarter);
   this.defineDashboardModel.setDdcYear11(year11);
   this.defineDashboardModel.setDdcYear12(year12);
   this.defineDashboardModel.setDdcKPI(kpi);
   add(new DefineDashboardForm("DefineDashboardForm"));
  }
 
  private class DefineDashboardForm extends Form{

   public DefineDashboardForm(String id) {
    super("DefineDashboardForm");
    // TODO Auto-generated constructor stub
    setDefaultModel(new CompoundPropertyModel(defineDashboardModel));
   
    Tbcurrencyrate tbcurrencyrate=null;
    List<Tbcurrencyrate> list1 = configurationService.getConfigurationRespository().findAll();
    if(!list1.isEmpty()){
     tbcurrencyrate = list1.get(0);
    }
   
    List<String> monthList = new ArrayList<String>();
    monthList.add("January");
    monthList.add("February");
    monthList.add("March");
    monthList.add("April");
    monthList.add("May");
    monthList.add("June");
    monthList.add("July");
    monthList.add("August");
    monthList.add("September");
    monthList.add("October");
    monthList.add("November");
    monthList.add("December");
   
   
       List<String> yearList = new ArrayList<String>();
       int year = Calendar.getInstance().get(Calendar.YEAR);
       if(action.equals("add")){
        defineDashboardModel.setDdcYear1(year+"");
           defineDashboardModel.setDdcYear2(year+"");
           defineDashboardModel.setDdcYear11(year+"");
           defineDashboardModel.setDdcYear12(year+"");
           defineDashboardModel.setDdcQuarter("January");
           defineDashboardModel.setDdcKPI("occupancy");
       }
          for(int i=tbcurrencyrate.getStartyear();i<=year;i++){
           yearList.add(i+"");
          }
      
       final DropDownChoice ddcYear1 = new DropDownChoice("ddcYear1",yearList);
    add(ddcYear1);
    ddcYear1.setOutputMarkupId(true);
    ddcYear1.add(new AjaxFormComponentUpdatingBehavior("onchange") {
    
    
     @Override
     protected void onUpdate(AjaxRequestTarget arg0) {
      // TODO Auto-generated method stub
      if(defineDashboardModel.getDdcYear1()!=null && defineDashboardModel.getDdcQuarter()!=null){
       setResponsePage(new DefineDashboard(defineDashboardModel.getDdcYear1(),defineDashboardModel.getDdcQuarter(),defineDashboardModel.getDdcYear11(),defineDashboardModel.getDdcYear12(),defineDashboardModel.getDdcKPI(), "edit"));
      }
     }
    });
   
   
    final DropDownChoice ddcQuarter = new DropDownChoice("ddcQuarter",monthList);
    add(ddcQuarter);
    ddcQuarter.setOutputMarkupId(true);
    ddcQuarter.add(new AjaxFormComponentUpdatingBehavior("onchange") {
    
    
     @Override
     protected void onUpdate(AjaxRequestTarget arg0) {
      // TODO Auto-generated method stub
      if(defineDashboardModel.getDdcYear1()!=null && defineDashboardModel.getDdcQuarter()!=null){
       setResponsePage(new DefineDashboard(defineDashboardModel.getDdcYear1(),defineDashboardModel.getDdcQuarter(),defineDashboardModel.getDdcYear11(),defineDashboardModel.getDdcYear12(),defineDashboardModel.getDdcKPI(), "edit"));
      }
     }
    });
    String query ="select w.region,e.productionmonth,SUM(e.lengthofstay),SUM(e.arrivals),SUM(e.roomnights),w.country from Tbmonthlyproductionbynationality e join e.hotelid as hotelid,Tbwtccountrieslist w where e.activeStatus='Y' and hotelid.id in (:hotelid) and e.productionmonth=:Q1 and e.productionyear=:fromYear and w.region = (select w.region from Tbwtccountrieslist w where w.country IN :nationality and w.country = e.country) group by w.region,e.productionmonth,w.country order by e.productionmonth";
    List<TbHotelDetails> hotelList = masterHotelHomeServiceImpl.getHotelHomeRespository().findAll();
    String hotelid="";
    List<String> regionkey= new ArrayList<String>();
    List<String> subregionkey= new ArrayList<String>();
    List<String> nationalitykey= new ArrayList<String>();
    List<Tbwtccountrieslist> regionList = reportServiceImpl.getMasterwtccountrieslistRepository().findAll();
    if(!regionList.isEmpty()){
     for (Iterator iterator = regionList.iterator(); iterator.hasNext();)
     {
      Tbwtccountrieslist tbwtccountrieslist = (Tbwtccountrieslist) iterator.next();
      if(tbwtccountrieslist.getRegion()!=null && !tbwtccountrieslist.getRegion().equals(""))
      {
       regionkey.add(tbwtccountrieslist.getRegion());
      }
     }
    }
    List<Tbwtccountrieslist> subregionList = reportServiceImpl.getMasterwtccountrieslistRepository().findAll();
    if(!regionList.isEmpty()){
     for (Iterator iterator = regionList.iterator(); iterator.hasNext();)
     {
      Tbwtccountrieslist tbwtccountrieslist = (Tbwtccountrieslist) iterator.next();
      if(tbwtccountrieslist.getSubregion()!=null && !tbwtccountrieslist.getSubregion().equals(""))
      {
       subregionkey.add(tbwtccountrieslist.getSubregion());
      }
     }
    }
    List<String> countryList=reportServiceImpl.getMasterwtccountrieslistRepository().findCountrybyregionandsubregion(regionkey,subregionkey);
    if(!countryList.isEmpty()){
     for (Iterator iterator = countryList.iterator(); iterator.hasNext();)
     {
      String str = (String) iterator.next();
      if(str!=null && !str.equals(""))
      {
       nationalitykey.add(str);
      }
     }
    }
    if(!hotelList.isEmpty()){
     for (Iterator iterator = hotelList.iterator(); iterator.hasNext();) {
      TbHotelDetails tbHotelDetails = (TbHotelDetails) iterator.next();
      if(hotelid==""){
       hotelid = tbHotelDetails.getId()+",";
      }
      else{
       hotelid = hotelid +tbHotelDetails.getId()+",";
      }
     }
    }
    if(hotelid.length()!=0){
     hotelid = hotelid.substring(0,hotelid.length()-1);
    }
    String str1[]=hotelid.split(",");
    List<Integer> hotelkey = new ArrayList<Integer>();
    for(int i=0;i<str1.length;i++){
     hotelkey.add(Integer.parseInt(str1[i]));
    }
    List a=new ArrayList();
    List a1=new ArrayList();
    List a2=new ArrayList();
    Integer totalcount=new Integer(0);
    Integer count=new Integer(0);
    Integer uncovered=new Integer(0);
   
    List<Object> lsReturn = masterwtccountrieslistservice.findbyhotelguestsbyregion1(query, hotelkey, Integer.parseInt(defineDashboardModel.getDdcYear1()), defineDashboardModel.getDdcQuarter(), nationalitykey);
    if(!lsReturn.isEmpty()){
     for (Iterator iterator = lsReturn.iterator(); iterator.hasNext();) {
      Object[] dd = (Object[]) iterator.next();
      a.add(dd);
     }
    }
    Long b1 =0l,c=0l,d=0l,e=0l,f=0l;
    int i=a.size();
    int j=0;
    for (Iterator iterator = a.iterator(); iterator.hasNext();) {
     Object[] amodel1 = (Object[]) iterator.next();
      if(amodel1[0].equals("Africa")){
        b1 = (Long)amodel1[3];
      }
      else if(amodel1[0].equals("Americas")){
        c = (Long)amodel1[3];
      }
      else if(amodel1[0].equals("Asia-Pacific")){
        d = (Long)amodel1[3];
      }
      else if(amodel1[0].equals("Europe")){
        e = (Long)amodel1[3];
      }
      else if(amodel1[0].equals("Middle East")){
        f = (Long)amodel1[3];
      }
    }
    names1="Africa,Americas,Asia-Pacific,Europe,Middle East";
    if(b1!=null){
     value1=b1.toString()+",";
    }
    if(c!=null){
     value1=value1+c.toString()+",";
    }
    if(d!=null){
     value1=value1+d.toString()+",";
    }
    if(e!=null){
     value1=value1+e.toString()+",";
    }
    if(f!=null){
     value1=value1+f.toString();
    }
    defineDashboardModel.setLblname1(names1);
    defineDashboardModel.setLblvalue1(value1);
    Label lblname1 = new Label("lblname1");
    add(lblname1);
    lblname1.setOutputMarkupId(true);
   
    Label lblvalue1 = new Label("lblvalue1");
    add(lblvalue1);
    lblvalue1.setOutputMarkupId(true);
   
   
    final DropDownChoice ddcYear11 = new DropDownChoice("ddcYear11",yearList);
    add(ddcYear11);
    ddcYear11.setOutputMarkupId(true);
    ddcYear11.add(new AjaxFormComponentUpdatingBehavior("onchange") {
    
    
     @Override
     protected void onUpdate(AjaxRequestTarget arg0) {
      // TODO Auto-generated method stub
      if(defineDashboardModel.getDdcYear11()!=null && defineDashboardModel.getDdcYear11()!=null && defineDashboardModel.getDdcKPI()!=null){
       setResponsePage(new DefineDashboard(defineDashboardModel.getDdcYear1(),defineDashboardModel.getDdcQuarter(),defineDashboardModel.getDdcYear11(),defineDashboardModel.getDdcYear12(),defineDashboardModel.getDdcKPI(), "edit"));
      }
     }
    });
   
    final DropDownChoice ddcYear12 = new DropDownChoice("ddcYear12",yearList);
    add(ddcYear12);
    ddcYear12.setOutputMarkupId(true);
    ddcYear12.add(new AjaxFormComponentUpdatingBehavior("onchange") {
    
    
     @Override
     protected void onUpdate(AjaxRequestTarget arg0) {
      // TODO Auto-generated method stub
      if(defineDashboardModel.getDdcYear11()!=null && defineDashboardModel.getDdcYear11()!=null && defineDashboardModel.getDdcKPI()!=null){
       setResponsePage(new DefineDashboard(defineDashboardModel.getDdcYear1(),defineDashboardModel.getDdcQuarter(),defineDashboardModel.getDdcYear11(),defineDashboardModel.getDdcYear12(),defineDashboardModel.getDdcKPI(), "edit"));
      }
     }
    });
   
   
    final DropDownChoice ddcKPI = new DropDownChoice("ddcKPI",Arrays.asList(new String[]{"occupancy","averagedailyrate","revenueperavailableroom",
      "foodandbeveragerevenue","totalarrival","totalhotelrevenue","otherhotelrevenue","sparevenue","roomlodgingrevenue"}));
    add(ddcKPI);
    ddcKPI.setOutputMarkupId(true);
    ddcKPI.add(new AjaxFormComponentUpdatingBehavior("onchange") {
    
    
     @Override
     protected void onUpdate(AjaxRequestTarget arg0) {
      // TODO Auto-generated method stub
      if(defineDashboardModel.getDdcYear11()!=null && defineDashboardModel.getDdcYear11()!=null && defineDashboardModel.getDdcKPI()!=null){
       setResponsePage(new DefineDashboard(defineDashboardModel.getDdcYear1(),defineDashboardModel.getDdcQuarter(),defineDashboardModel.getDdcYear11(),defineDashboardModel.getDdcYear12(),defineDashboardModel.getDdcKPI(), "edit"));
      }
     }
    });
    List b=new ArrayList();
    String query1="select e1.kpimonth as kpimon2,e.kpimonth as kpimon,e.kpiyear as kpiyear1,sum(e1.KPI) as year11,sum(e2.KPI) as year12,sum(e3.KPI) as year13,sum(e4.KPI) as year14 ,sum(e1.totalroomsavailable) as k7,sum(e2.totalroomsavailable) as k8, sum(e3.totalroomsavailable) as k9,sum(e4.totalroomsavailable) as k10,sum(e1.totalroomsoccupied) as k11,sum(e2.totalroomsoccupied) as k12,sum(e3.totalroomsoccupied) as k13,sum(e4.totalroomsoccupied) as k14,sum(e1.roomlodgingrevenue) as k15,sum(e2.roomlodgingrevenue) as k16,sum(e3.roomlodgingrevenue) as k17,sum(e4.roomlodgingrevenue) as k18 from tbmonthlykpi e left join tbmonthlykpi e1 on e1.id = e. id and e1.kpiyear=:year1 left join tbmonthlykpi e2 on e2.id = e. id and e2.kpiyear=:year2 left join tbmonthlykpi e3 on e3.id = e. id and e3.kpiyear=:year3 left join tbmonthlykpi e4 on e4.id = e. id and e4.kpiyear=:year4 where e.kpimonth between :fromMonth and :toMonth and e.hotelid in (:hotelid) and e.activeStatus='Y' group by e.kpimonth,e.kpiyear,e1.kpimonth order by e.kpimonth";
    List<Object> lsReturn1 = monthlykpitRespository.findbyYearlyKPIVariance(query1, hotelkey,1,12, 2013, Integer.parseInt(defineDashboardModel.getDdcYear12()), defineDashboardModel.getDdcKPI());
    if(!lsReturn1.isEmpty()){
     for (Iterator iterator = lsReturn1.iterator(); iterator.hasNext();) {
      Object[] dd = (Object[]) iterator.next();
      b.add(dd);
     }
    }
    List<String> list = new ArrayList<String>();

     int m=b.size();
     int n=0;
      Hashtable<Integer,String> hm=new Hashtable<Integer,String>();
     for (Iterator iterator = b.iterator(); iterator.hasNext();) {
      Object[] amodel1 = (Object[]) iterator.next();
       if(amodel1[3]==null)
       {
        amodel1[3]=0;
       }
       if(amodel1[4]==null)
       {
        amodel1[4]=0;
       }
       if(amodel1[5]==null)
       {
        amodel1[5]=0;
       }
       if(amodel1[6]==null)
       {
        amodel1[6]=0;
       }
       if(amodel1[7]==null)
       {
        amodel1[7]=0;
       }
       if(amodel1[8]==null)
       {
        amodel1[8]=0;
       }
       if(amodel1[9]==null)
       {
        amodel1[9]=0;
       }
       if(amodel1[10]==null)
       {
        amodel1[10]=0;
       }
       if(amodel1[11]==null)
       {
        amodel1[11]=0;
       }
       if(amodel1[12]==null)
       {
        amodel1[12]=0;
       }
       if(amodel1[13]==null)
       {
        amodel1[13]=0;
       }
       if(amodel1[14]==null)
       {
        amodel1[14]=0;
       }
       if(amodel1[15]==null)
       {
        amodel1[15]=0;
       }
       if(amodel1[16]==null)
       {
        amodel1[16]=0;
       }
       if(amodel1[17]==null)
       {
        amodel1[17]=0;
       }
       if(amodel1[18]==null)
       {
        amodel1[18]=0;
       }
       if(defineDashboardModel.getDdcKPI().equals("occupancy")){
        Float aa=0.0f,bb=0.0f,cc=0.0f,dd=0.0f;
        if((Integer)amodel1[7]!=0){
         aa= (float) (((float)(Integer)amodel1[11]/(float)(Integer)amodel1[7])*100);
        }
        else{
         aa=0.0f;
        }
        if((Integer)amodel1[8]!=0){
          bb= (float) (((float)(Integer)amodel1[12]/(float)(Integer)amodel1[8])*100);
        }
        else{
         bb=0.0f;
        }
        if((Integer)amodel1[9]!=0){
         cc= (float) (((float)(Integer)amodel1[13]/(float)(Integer)amodel1[9])*100);
        }
        else{
         cc=0.0f;
        }
        if((Integer)amodel1[10]!=0){
        
         dd= (float) (((float)(Integer)amodel1[14]/(float)(Integer)amodel1[10])*100);
        }
        else{
         dd=0.0f;
        }
        hm.put((Integer)amodel1[1],Common.getMonth((int)amodel1[1]));
        //names2=names2+Common.getMonthname((int)amodel1[1]);
        value2=value2.concat(aa.toString()).concat(",");
        value3=value3.concat(bb.toString()).concat(",");
        value4=value4.concat(cc.toString()).concat(",");
        value5=value5.concat(dd.toString()).concat(",");
       }
       else if(defineDashboardModel.getDdcKPI().equals("averagedailyrate")){
        Float aa=0.0f,bb=0.0f,cc=0.0f,dd=0.0f;
        if((Integer)amodel1[11]!=0){
         aa= (float) (((Double)amodel1[15]/(Integer)amodel1[11]));
        }
        else{
         aa=0.0f;
        }
        if((Integer)amodel1[12]!=0){
          bb= (float) (((Double)amodel1[16]/(Integer)amodel1[12]));
        }
        else{
         bb=0.0f;
        }
        if((Integer)amodel1[13]!=0){
         cc= (float) (((Double)amodel1[17]/(Integer)amodel1[13]));
        }
        else{
         cc=0.0f;
        }
        if((Integer)amodel1[14]!=0){
        
         dd= (float) (((Double)amodel1[18]/(Integer)amodel1[14]));
        }
        else{
         dd=0.0f;
        }
        hm.put((Integer)amodel1[1],Common.getMonth((int)amodel1[1]));
        //names2=names2+Common.getMonthname((int)amodel1[1]);
        value2=value2.concat(aa.toString()).concat(",");
        value3=value3.concat(bb.toString()).concat(",");
        value4=value4.concat(cc.toString()).concat(",");
        value5=value5.concat(dd.toString()).concat(",");
       }
       else if(defineDashboardModel.getDdcKPI().equals("revenueperavailableroom")){
        Float aa=0.0f,bb=0.0f,cc=0.0f,dd=0.0f;
        if((Integer)amodel1[7]!=0){
         aa= (float) (((Double)amodel1[15]/(Integer)amodel1[7]));
        }
        else{
         aa=0.0f;
        }
        if((Integer)amodel1[8]!=0){
          bb= (float) (((Double)amodel1[16]/(Integer)amodel1[8]));
        }
        else{
         bb=0.0f;
        }
        if((Integer)amodel1[9]!=0){
         cc= (float) (((Double)amodel1[17]/(Integer)amodel1[9]));
        }
        else{
         cc=0.0f;
        }
        if((Integer)amodel1[10]!=0){
        
         dd= (float) (((Double)amodel1[18]/(Integer)amodel1[10]));
        }
        else{
         dd=0.0f;
        }
        hm.put((Integer)amodel1[1],Common.getMonth((int)amodel1[1]));
        //names2=names2+Common.getMonthname((int)amodel1[1]);
        value2=value2.concat(aa.toString()).concat(",");
        value3=value3.concat(bb.toString()).concat(",");
        value4=value4.concat(cc.toString()).concat(",");
        value5=value5.concat(dd.toString()).concat(",");
       }
       else{
        hm.put((Integer)amodel1[1],Common.getMonth((int)amodel1[1]));
        //names2=names2+Common.getMonthname((int)amodel1[1]);
        value2=value2.concat(amodel1[3].toString()).concat(",");
        value3=value3.concat(amodel1[4].toString()).concat(",");
        value4=value4.concat(amodel1[5].toString()).concat(",");
        value5=value5.concat(amodel1[6].toString()).concat(",");
       }
     
      }
    
     Map<Integer, String> sortedMapByKeys = new TreeMap<Integer,String>();
           sortedMapByKeys.putAll(hm);
           for(Integer z=0;z<=12;z++)
           {
            if(sortedMapByKeys.get(z)!=null)
            {
            names2=names2+sortedMapByKeys.get(z).concat(",");
            }
           }
    
      //System.out.println(names2);
    
     System.out.println(names2);
    
     System.out.println(value2);
     defineDashboardModel.setLblname2(names2);
     defineDashboardModel.setLblvalue2(value2);
     defineDashboardModel.setLblvalue3(value3);
     defineDashboardModel.setLblvalue4(value4);
     defineDashboardModel.setLblvalue5(value5);
   
     Label lblname2 = new Label("lblname2");
     add(lblname2);
     lblname2.setOutputMarkupId(true);
    
     Label lblvalue2 = new Label("lblvalue2");
     add(lblvalue2);
     lblvalue2.setOutputMarkupId(true);
    
     Label lblvalue3 = new Label("lblvalue3");
     add(lblvalue3);
     lblvalue3.setOutputMarkupId(true);
    
     Label lblvalue4 = new Label("lblvalue4");
     add(lblvalue4);
     lblvalue4.setOutputMarkupId(true);
    
     Label lblvalue5 = new Label("lblvalue5");
     add(lblvalue5);
     lblvalue5.setOutputMarkupId(true);
   
   }
  }
   public static <K extends Comparable,V extends Comparable> Map<K,V> sortByKeys(Map<K,V> map){
          List<K> keys = new LinkedList<K>(map.keySet());
          Collections.sort(keys);
       
          Map<K,V> sortedMap = new LinkedHashMap<K,V>();
          for(K key: keys){
              sortedMap.put(key, map.get(key));
          }
       
          return sortedMap;
      }
}
 
Kindly let me know how do I handle the zero values here.I'll be very thankfull.
Posted by Richard on 6th August 2016
Hi there,

There's no point pasting mountains of code - I'm not reading it. Plus - I don't know Java.

But if you want nothing displayed and you have no data, use null instead of zero. Like the example I gave.

Richard
Posted by Max on 17th September 2016
Hi Richard,

What should be done in case of the line graph allowing for modification after final output. I can modify the line curve plotted just by dragging it. Please let me know which property of line chart do I need to edit to make the output static.
Posted by Richard on 19th September 2016
Hi there,

Don't set the adjustable property to true. Either set it to false or just don't set it at all.



Richard
Posted by Max on 19th September 2016
Thanks for the help Richard. I could fix it yesterday when I found that it is adjustable property which should be set to false.

Add a reply




« Back to message list