Android Open Source - AChartEngineOnAndroidStudio Sales Comparison Chart






From Project

Back to project page AChartEngineOnAndroidStudio.

License

The source code is released under:

Apache License

If you think the Android project AChartEngineOnAndroidStudio listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Copyright (C) 2009 - 2013 SC 4ViewSoft SRL
 *  /*from   w  w w  . j ava  2s. c  o m*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.achartengine.chartdemo.demo.chart;

import java.util.ArrayList;
import java.util.List;

import org.achartengine.ChartFactory;
import org.achartengine.chart.PointStyle;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer.FillOutsideLine;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;

/**
 * Sales comparison demo chart.
 */
public class SalesComparisonChart extends AbstractDemoChart {
  /**
   * Returns the chart name.
   * 
   * @return the chart name
   */
  public String getName() {
    return "Sales comparison";
  }

  /**
   * Returns the chart description.
   * 
   * @return the chart description
   */
  public String getDesc() {
    return "Monthly sales advance for 2 years (interpolated line and area charts)";
  }

  /**
   * Executes the chart demo.
   * 
   * @param context the context
   * @return the built intent
   */
  public Intent execute(Context context) {
    String[] titles = new String[] { "Sales for 2008", "Sales for 2007",
        "Difference between 2008 and 2007 sales" };
    List<double[]> values = new ArrayList<double[]>();
    values.add(new double[] { 14230, 12300, 14240, 15244, 14900, 12200, 11030, 12000, 12500, 15500,
        14600, 15000 });
    values.add(new double[] { 10230, 10900, 11240, 12540, 13500, 14200, 12530, 11200, 10500, 12500,
        11600, 13500 });
    int length = values.get(0).length;
    double[] diff = new double[length];
    for (int i = 0; i < length; i++) {
      diff[i] = values.get(0)[i] - values.get(1)[i];
    }
    values.add(diff);
    int[] colors = new int[] { Color.BLUE, Color.CYAN, Color.GREEN };
    PointStyle[] styles = new PointStyle[] { PointStyle.POINT, PointStyle.POINT, PointStyle.POINT };
    XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
    setChartSettings(renderer, "Monthly sales in the last 2 years", "Month", "Units sold", 0.75,
        12.25, -5000, 19000, Color.GRAY, Color.LTGRAY);
    renderer.setXLabels(12);
    renderer.setYLabels(10);
    renderer.setChartTitleTextSize(20);
    renderer.setTextTypeface("sans_serif", Typeface.BOLD);
    renderer.setLabelsTextSize(14f);
    renderer.setAxisTitleTextSize(15);
    renderer.setLegendTextSize(15);
    length = renderer.getSeriesRendererCount();

    for (int i = 0; i < length; i++) {
      XYSeriesRenderer seriesRenderer = (XYSeriesRenderer) renderer.getSeriesRendererAt(i);
      if (i == length - 1) {
        FillOutsideLine fill = new FillOutsideLine(FillOutsideLine.Type.BOUNDS_ALL);
        fill.setColor(Color.GREEN);
        seriesRenderer.addFillOutsideLine(fill);
      }
      seriesRenderer.setLineWidth(2.5f);
      seriesRenderer.setDisplayChartValues(true);
      seriesRenderer.setChartValuesTextSize(10f);
    }
    return ChartFactory.getCubicLineChartIntent(context, buildBarDataset(titles, values), renderer,
        0.5f);
  }
}




Java Source Code List

org.achartengine.chartdemo.demo.BuildConfig.java
org.achartengine.chartdemo.demo.ChartDemo.java
org.achartengine.chartdemo.demo.GeneratedChartDemo.java
org.achartengine.chartdemo.demo.chart.AbstractDemoChart.java
org.achartengine.chartdemo.demo.chart.AverageCubicTemperatureChart.java
org.achartengine.chartdemo.demo.chart.AverageTemperatureChart.java
org.achartengine.chartdemo.demo.chart.BudgetDoughnutChart.java
org.achartengine.chartdemo.demo.chart.BudgetPieChart.java
org.achartengine.chartdemo.demo.chart.CombinedTemperatureChart.java
org.achartengine.chartdemo.demo.chart.IDemoChart.java
org.achartengine.chartdemo.demo.chart.MultipleTemperatureChart.java
org.achartengine.chartdemo.demo.chart.PieChartBuilder.java
org.achartengine.chartdemo.demo.chart.ProjectStatusBubbleChart.java
org.achartengine.chartdemo.demo.chart.ProjectStatusChart.java
org.achartengine.chartdemo.demo.chart.SalesBarChart.java
org.achartengine.chartdemo.demo.chart.SalesComparisonChart.java
org.achartengine.chartdemo.demo.chart.SalesGrowthChart.java
org.achartengine.chartdemo.demo.chart.SalesStackedBarChart.java
org.achartengine.chartdemo.demo.chart.ScatterChart.java
org.achartengine.chartdemo.demo.chart.SensorValuesChart.java
org.achartengine.chartdemo.demo.chart.TemperatureChart.java
org.achartengine.chartdemo.demo.chart.TrigonometricFunctionsChart.java
org.achartengine.chartdemo.demo.chart.WeightDialChart.java
org.achartengine.chartdemo.demo.chart.XYChartBuilderBackup.java
org.achartengine.chartdemo.demo.chart.XYChartBuilder.java