title: Creating multiple bar charts dynamically
body: <p>I'm making a webapp whose dashboard has a window which will have bar charts.</p>
  
  <pre><code>Agent       customer      time
  1             aa           40 mins
  2             aa           4 hours
  1             ab           45 mins
  2             ab           3 hours
  1             ac           5 hours
  2             ac           10 mins
  </code></pre>
  
  <p>As you can see that time unit can be different, so I came to a decision that I will make chart per customer. So for 1 chart my label will be <code>aa</code> and chart series data will be <code>1, 40 mins</code> and <code>2,4 hours</code>.
  As you can see I have to create total 3 charts in above case.</p>
  
  <p>I read in some previous threads that we can generate such dynamic charts by using <code>&lt;p:datagrid&gt;</code>.</p>
  
  <pre><code>&lt;p:dataGrid id="timegapdatagrid" value="#{dashboardController.chartlist}"&gt;
                  &lt;p:panel id="timegap" header="Time gap Diagram" styleClass="ui-dashboard-layout"&gt;
                      &lt;p:chart id="timeGapDiagram" type="bar" model="#{dashboardController.dashboardView.timeGapDiagram}" 
                           styleClass="ui-diagram-layout" responsive="true" parent="timegapdatagrid" binding="timegapdatagrid"/&gt;      
                  &lt;/p:panel&gt;
           &lt;/p:dataGrid&gt;  
  </code></pre>
  
  <p></p>
  
  <pre><code>private void createTimeGapDiaLineModels(JourneyDTO journeyDTO) {
          dashboardView.getTimeGapDiagram().clear();
          List&lt;TouchPointDTO&gt; tplist = getTouchPointList(journeyDTO);
          ChartSeries cs;
          String a1=null;
          int b1=0;
          Map&lt;String, ChartSeries&gt; mapcs = new HashMap&lt;&gt;();
  
          TouchPointFieldResearcherListDTO touchPointFieldResearcherDTOList = journeyService.getTouchPointFiedlResearcherListOfJourney(journeyDTO);
          for (int i = 0; i&lt;tplist.size(); i++){
              cs = new ChartSeries();
              String n1 = tplist.get(i).getTouchPointDesc();
              cs.setLabel(n1);
              for (int j=0; j&lt;touchPointFieldResearcherDTOList.getTouchPointFieldResearcherDTOList().size(); j++){
                  if (touchPointFieldResearcherDTOList.getTouchPointFieldResearcherDTOList().get(j).getTouchpointDTO().getTouchPointDesc().equals(tplist.get(i).getTouchPointDesc()))
                  {
                      a1= touchPointFieldResearcherDTOList.getTouchPointFieldResearcherDTOList().get(j).getFieldResearcherDTO().getSdtUserDTO().getUsername();
                      System.out.println(touchPointFieldResearcherDTOList.getTouchPointFieldResearcherDTOList().get(j).getFieldResearcherDTO().getSdtUserDTO().getUsername());
                      System.out.println(touchPointFieldResearcherDTOList.getTouchPointFieldResearcherDTOList().get(j).getDuration());
  
                      if (touchPointFieldResearcherDTOList.getTouchPointFieldResearcherDTOList().get(j).getDuration()==null){
                          System.out.println("here");
                          b1=0;  
                      }else {
                          b1 = touchPointFieldResearcherDTOList.getTouchPointFieldResearcherDTOList().get(j).getDuration();
                      }
                  }
                  cs.set(a1,b1);
                  }
              mapcs.put(n1, cs);
              }
  
              //dashboardView.getTimeGapDiagram().addSeries(cs);
  
          for (Map.Entry&lt;String, ChartSeries&gt; mapChartSeries : mapcs.entrySet()) {   
              System.out.println(mapChartSeries.getValue().getLabel());
  
              System.out.println(mapChartSeries.getValue().getData());
              dashboardView.getTimeGapDiagram().addSeries(mapChartSeries.getValue());
      }
      }
  </code></pre>
  
  <p>It will be great help if I can get some help on the above issue.</p>