title: Achartengine: Inserting dates as X-values in
body: <p>I'm using AChartEngine to display averages across several days (2 months if possible). I'd like to provide a comparison between one individual and a group. At this point, I'm working on how to provide dates across the x-axis (ie, 12/15/2011 or Dec. 11, 2011 or even 12/15, Dec. 15).</p>
  
  <p>I'm not sure how to do this in AchartEngine; the documentation is a little hard for me to follow without pictures (sorry). I'd like something like this: <a href="https://stackoverflow.com/questions/6689178/using-achartengine-library-for-graphs-not-able-to-get-value-for-diffrent-x-axis">Using AChartEngine library for graphs, not able to get value for diffrent x-axis value</a></p>
  
  <p>Here's my code:</p>
  
  <pre><code>private void setupHistoryChart() {    
          XYMultipleSeriesRenderer renderer = getBarDemoRenderer();
          setChartSettings(renderer);
          Intent intent = ChartFactory.getBarChartIntent(this, getBarDemoDataset(), renderer, Type.DEFAULT);
          startActivity(intent);
      }
  
       public XYMultipleSeriesRenderer getBarDemoRenderer() {
           XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
           renderer.setAxisTitleTextSize(15);
           renderer.setChartTitleTextSize(18);
           renderer.setLabelsTextSize(12);
           renderer.setLegendTextSize(15);
           renderer.setMargins(new int[] {20, 30, 15, 0});
           SimpleSeriesRenderer r = new SimpleSeriesRenderer();
           r.setColor(Color.BLUE);
           renderer.addSeriesRenderer(r);
  
           return renderer;
         }
  
       private void setChartSettings(XYMultipleSeriesRenderer renderer) {   
           renderer.setChartTitle("History");
           renderer.setChartTitleTextSize((float) 14.0);
           renderer.setXTitle("Day");
           renderer.setXLabelsAlign(Align.LEFT);
           renderer.setYLabelsAlign(Align.LEFT);
           renderer.setBarSpacing(0.5);
           renderer.setZoomEnabled(true);
           renderer.setZoomRate(0.2f);
           renderer.setYTitle("Unit)");
           renderer.setXAxisMin(1.0);
  
           if(AppStatus.mDayMap.size() == 0){
               renderer.setXAxisMax(3.0);
               renderer.setYAxisMax(10.0);
           }else{
               renderer.setXAxisMax(AppStatus.mDayMap.size());
               // Get the max Integer out of myMap
               Map.Entry&lt;String, Integer&gt; maxEntry = null;
  
               for (Map.Entry&lt;String, Integer&gt; entry : AppStatus.mDayMap.entrySet())
               {
                   if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) &gt; 0)
                   {
                       maxEntry = entry;
                   }
               }
               renderer.setYAxisMax(maxEntry.getValue()/1000 + maxEntry.getValue()/1000);
           }
           renderer.setYAxisMin(0);
         }
  
       private XYMultipleSeriesDataset getBarDemoDataset() {
           XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
           HashMap&lt;String, Integer&gt; myMap = AppStatus.mDayMap;
           CategorySeries series = new CategorySeries ("Your History " + 1);
           try{
  
               if(AppStatus.mDayMap.size() == 0){
                   series.add(3.0);
                   series.add(10.0);
                   dataset.addSeries(series.toXYSeries());
               }else{
                   Log.v(LOG_TAG, "Size of Map = " + myMap.size());
                   float sum = (float) 0.0;
                   if(myMap.size() &gt; 0){
                       Iterator it = myMap.entrySet().iterator();
                       float j= (float)0.0;
                       for (int i = 0; i &lt; 1 /*2*/; i++) {
                         //CategorySeries series = new CategorySeries("Your History " + (i + 1));
                         while(it.hasNext()){
                             Map.Entry pairs = (Map.Entry)it.next();
                             sum = sum + (float) (1.0 + j);
                             series.add((((Integer) pairs.getValue()).doubleValue())/1000); 
                         }
                         dataset.addSeries(series.toXYSeries());
                       }
                   }
               }
  
           }catch(IllegalArgumentException e){
               Log.e(LOG_TAG, "IllegalArgumentException " + e.toString());
               series.add(3.0);
               series.add(10.0);
               dataset.addSeries(series.toXYSeries());
           }
  
           return dataset;
         }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/UZekg.png" alt="enter image description here"></p>