Java Code Examples for com.github.mikephil.charting.components.XAxis#setTextSize()

The following examples show how to use com.github.mikephil.charting.components.XAxis#setTextSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DailyBarChart.java    From AndroidApp with GNU Affero General Public License v3.0 6 votes vote down vote up
private void setFormatting() {
    barChart.setDrawGridBackground(false);
    barChart.getLegend().setEnabled(false);
    barChart.getAxisLeft().setEnabled(false);
    barChart.getAxisRight().setEnabled(false);
    barChart.setHardwareAccelerationEnabled(true);
    barChart.getDescription().setEnabled(false);
    barChart.setNoDataText("");
    barChart.setTouchEnabled(false);
    barChart.setExtraBottomOffset(2);

    XAxis xAxis2 = barChart.getXAxis();
    xAxis2.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis2.setTextColor(ContextCompat.getColor(context, R.color.lightGrey));
    xAxis2.setTextSize(context.getResources().getInteger(R.integer.chartValueTextSize));
    xAxis2.setDrawGridLines(false);
    xAxis2.setDrawAxisLine(false);
    xAxis2.setValueFormatter(new LabelAxisFormatter(chartLabels));
}
 
Example 2
Source File: RealmBaseActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
protected void setup(Chart<?> chart) {

        mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

        // no description text
        chart.setDescription("");
        chart.setNoDataTextDescription("You need to provide data for the chart.");

        // enable touch gestures
        chart.setTouchEnabled(true);

        if (chart instanceof BarLineChartBase) {

            BarLineChartBase mChart = (BarLineChartBase) chart;

            mChart.setDrawGridBackground(false);

            // enable scaling and dragging
            mChart.setDragEnabled(true);
            mChart.setScaleEnabled(true);

            // if disabled, scaling can be done on x- and y-axis separately
            mChart.setPinchZoom(false);

            YAxis leftAxis = mChart.getAxisLeft();
            leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines
            leftAxis.setTypeface(mTf);
            leftAxis.setTextSize(8f);
            leftAxis.setTextColor(Color.DKGRAY);
            leftAxis.setValueFormatter(new PercentFormatter());

            XAxis xAxis = mChart.getXAxis();
            xAxis.setTypeface(mTf);
            xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
            xAxis.setTextSize(8f);
            xAxis.setTextColor(Color.DKGRAY);

            mChart.getAxisRight().setEnabled(false);
        }
    }
 
Example 3
Source File: PowerChart.java    From AndroidApp with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setFormatting() {
    powerChart.setDrawGridBackground(false);
    powerChart.getLegend().setEnabled(false);
    powerChart.getAxisRight().setEnabled(false);
    powerChart.getDescription().setEnabled(false);
    powerChart.setNoDataText("");
    powerChart.setHardwareAccelerationEnabled(true);

    YAxis yAxis = powerChart.getAxisLeft();
    yAxis.setEnabled(true);
    yAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    yAxis.setDrawTopYLabelEntry(false);
    yAxis.setDrawGridLines(false);
    yAxis.setDrawAxisLine(false);
    yAxis.setTextColor(ContextCompat.getColor(context, R.color.lightGrey));
    yAxis.setTextSize(context.getResources().getInteger(R.integer.chartDateTextSize));
    yAxis.setValueFormatter(new IntegerYAxisValueFormatter());

    XAxis xAxis = powerChart.getXAxis();
    xAxis.setDrawAxisLine(false);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawLabels(true);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextColor(ContextCompat.getColor(context, R.color.lightGrey));
    xAxis.setValueFormatter(new HoursMinutesXAxisValueFormatter(chartLabels));

    xAxis.setTextSize(context.getResources().getInteger(R.integer.chartDateTextSize));
}
 
Example 4
Source File: GraphUtils.java    From your-local-weather with GNU General Public License v3.0 4 votes vote down vote up
public static void setupXAxis(XAxis x,
                              List<DetailedWeatherForecast> weatherForecastList,
                              int textColorId,
                              Float textSize,
                              AppPreference.GraphGridColors gridColor,
                              Locale locale) {
    x.removeAllLimitLines();
    Map<Integer, Long> hourIndexes = new HashMap<>();

    int lastDayOflimitLine = 0;
    for (int i = 0; i < weatherForecastList.size(); i++) {
        hourIndexes.put(i, weatherForecastList.get(i).getDateTime());
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(weatherForecastList.get(i).getDateTime() * 1000);
        if (cal.get(Calendar.DAY_OF_YEAR) != lastDayOflimitLine) {
            Calendar calOfPreviousRecord = Calendar.getInstance();
            int previousRecordHour = 24;
            if (i > 0) {
                calOfPreviousRecord.setTimeInMillis(weatherForecastList.get(i - 1).getDateTime() * 1000);
                previousRecordHour = calOfPreviousRecord.get(Calendar.HOUR_OF_DAY);
            }
            int currentHour = cal.get(Calendar.HOUR_OF_DAY);
            float timeSpan = (24 - previousRecordHour) + currentHour;
            float dayLine = currentHour / timeSpan;
            float midnight = i - dayLine;
            float hour6 = midnight + (6 / timeSpan);
            float hour12 = midnight + (12 / timeSpan);
            float hour18 = midnight + (18 / timeSpan);
            LimitLine limitLine = new LimitLine(midnight);
            limitLine.setLineColor(gridColor.getMainGridColor());
            limitLine.setLineWidth(0.5f);
            x.addLimitLine(limitLine);
            /*LimitLine limitLine6 = new LimitLine(hour6, "");
            limitLine6.setLineColor(Color.LTGRAY);
            limitLine6.setLineWidth(0.5f);
            x.addLimitLine(limitLine6);*/
            LimitLine limitLine12 = new LimitLine(hour12);
            limitLine12.setLineColor(gridColor.getSecondaryGridColor());
            limitLine12.setLineWidth(0.5f);
            x.addLimitLine(limitLine12);
            /*LimitLine limitLine18 = new LimitLine(hour18, "");
            limitLine18.setLineColor(Color.LTGRAY);
            limitLine18.setLineWidth(0.5f);
            x.addLimitLine(limitLine18);*/
            lastDayOflimitLine = cal.get(Calendar.DAY_OF_YEAR);
        }
    }

    x.setEnabled(true);
    x.setPosition(XAxis.XAxisPosition.BOTTOM);
    x.setDrawGridLines(false);
    x.setLabelCount(25, true);
    x.setTextColor(textColorId);
    x.setValueFormatter(new XAxisValueFormatter(hourIndexes, locale));
    x.setDrawLimitLinesBehindData(true);

    if (textSize != null) {
        x.setTextSize(textSize);
    }
}
 
Example 5
Source File: RadarChartActivity.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_radarchart);

    setTitle("RadarChartActivity");

    chart = findViewById(R.id.chart1);
    chart.setBackgroundColor(Color.rgb(60, 65, 82));

    chart.getDescription().setEnabled(false);

    chart.setWebLineWidth(1f);
    chart.setWebColor(Color.LTGRAY);
    chart.setWebLineWidthInner(1f);
    chart.setWebColorInner(Color.LTGRAY);
    chart.setWebAlpha(100);

    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    MarkerView mv = new RadarMarkerView(this, R.layout.radar_markerview);
    mv.setChartView(chart); // For bounds control
    chart.setMarker(mv); // Set the marker to the chart

    setData();

    chart.animateXY(1400, 1400, Easing.EaseInOutQuad);

    XAxis xAxis = chart.getXAxis();
    xAxis.setTypeface(tfLight);
    xAxis.setTextSize(9f);
    xAxis.setYOffset(0f);
    xAxis.setXOffset(0f);
    xAxis.setValueFormatter(new ValueFormatter() {

        private final String[] mActivities = new String[]{"Burger", "Steak", "Salad", "Pasta", "Pizza"};

        @Override
        public String getFormattedValue(float value) {
            return mActivities[(int) value % mActivities.length];
        }
    });
    xAxis.setTextColor(Color.WHITE);

    YAxis yAxis = chart.getYAxis();
    yAxis.setTypeface(tfLight);
    yAxis.setLabelCount(5, false);
    yAxis.setTextSize(9f);
    yAxis.setAxisMinimum(0f);
    yAxis.setAxisMaximum(80f);
    yAxis.setDrawLabels(false);

    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setTypeface(tfLight);
    l.setXEntrySpace(7f);
    l.setYEntrySpace(5f);
    l.setTextColor(Color.WHITE);
}
 
Example 6
Source File: StackedBarActivityNegative.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_age_distribution);

    setTitle("StackedBarActivityNegative");

    chart = findViewById(R.id.chart1);
    chart.setOnChartValueSelectedListener(this);
    chart.setDrawGridBackground(false);
    chart.getDescription().setEnabled(false);

    // scaling can now only be done on x- and y-axis separately
    chart.setPinchZoom(false);

    chart.setDrawBarShadow(false);
    chart.setDrawValueAboveBar(true);
    chart.setHighlightFullBarEnabled(false);

    chart.getAxisLeft().setEnabled(false);
    chart.getAxisRight().setAxisMaximum(25f);
    chart.getAxisRight().setAxisMinimum(-25f);
    chart.getAxisRight().setDrawGridLines(false);
    chart.getAxisRight().setDrawZeroLine(true);
    chart.getAxisRight().setLabelCount(7, false);
    chart.getAxisRight().setValueFormatter(new CustomFormatter());
    chart.getAxisRight().setTextSize(9f);

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextSize(9f);
    xAxis.setAxisMinimum(0f);
    xAxis.setAxisMaximum(110f);
    xAxis.setCenterAxisLabels(true);
    xAxis.setLabelCount(12);
    xAxis.setGranularity(10f);
    xAxis.setValueFormatter(new ValueFormatter() {

        private final DecimalFormat format = new DecimalFormat("###");

        @Override
        public String getFormattedValue(float value) {
            return format.format(value) + "-" + format.format(value + 10);
        }
    });

    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setFormSize(8f);
    l.setFormToTextSpace(4f);
    l.setXEntrySpace(6f);

    // IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
    ArrayList<BarEntry> values = new ArrayList<>();
    values.add(new BarEntry(5, new float[]{ -10, 10 }));
    values.add(new BarEntry(15, new float[]{ -12, 13 }));
    values.add(new BarEntry(25, new float[]{ -15, 15 }));
    values.add(new BarEntry(35, new float[]{ -17, 17 }));
    values.add(new BarEntry(45, new float[]{ -19, 20 }));
    values.add(new BarEntry(45, new float[]{ -19, 20 }, getResources().getDrawable(R.drawable.star)));
    values.add(new BarEntry(55, new float[]{ -19, 19 }));
    values.add(new BarEntry(65, new float[]{ -16, 16 }));
    values.add(new BarEntry(75, new float[]{ -13, 14 }));
    values.add(new BarEntry(85, new float[]{ -10, 11 }));
    values.add(new BarEntry(95, new float[]{ -5, 6 }));
    values.add(new BarEntry(105, new float[]{ -1, 2 }));

    BarDataSet set = new BarDataSet(values, "Age Distribution");
    set.setDrawIcons(false);
    set.setValueFormatter(new CustomFormatter());
    set.setValueTextSize(7f);
    set.setAxisDependency(YAxis.AxisDependency.RIGHT);
    set.setColors(Color.rgb(67,67,72), Color.rgb(124,181,236));
    set.setStackLabels(new String[]{
            "Men", "Women"
    });

    BarData data = new BarData(set);
    data.setBarWidth(8.5f);
    chart.setData(data);
    chart.invalidate();
}
 
Example 7
Source File: LineChartTime.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_linechart_time);

    setTitle("LineChartTime");

    tvX = findViewById(R.id.tvXMax);
    seekBarX = findViewById(R.id.seekBar1);
    seekBarX.setOnSeekBarChangeListener(this);

    chart = findViewById(R.id.chart1);

    // no description text
    chart.getDescription().setEnabled(false);

    // enable touch gestures
    chart.setTouchEnabled(true);

    chart.setDragDecelerationFrictionCoef(0.9f);

    // enable scaling and dragging
    chart.setDragEnabled(true);
    chart.setScaleEnabled(true);
    chart.setDrawGridBackground(false);
    chart.setHighlightPerDragEnabled(true);

    // set an alternative background color
    chart.setBackgroundColor(Color.WHITE);
    chart.setViewPortOffsets(0f, 0f, 0f, 0f);

    // add data
    seekBarX.setProgress(100);

    // get the legend (only possible after setting data)
    Legend l = chart.getLegend();
    l.setEnabled(false);

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.TOP_INSIDE);
    xAxis.setTypeface(tfLight);
    xAxis.setTextSize(10f);
    xAxis.setTextColor(Color.WHITE);
    xAxis.setDrawAxisLine(false);
    xAxis.setDrawGridLines(true);
    xAxis.setTextColor(Color.rgb(255, 192, 56));
    xAxis.setCenterAxisLabels(true);
    xAxis.setGranularity(1f); // one hour
    xAxis.setValueFormatter(new ValueFormatter() {

        private final SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH);

        @Override
        public String getFormattedValue(float value) {

            long millis = TimeUnit.HOURS.toMillis((long) value);
            return mFormat.format(new Date(millis));
        }
    });

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    leftAxis.setTypeface(tfLight);
    leftAxis.setTextColor(ColorTemplate.getHoloBlue());
    leftAxis.setDrawGridLines(true);
    leftAxis.setGranularityEnabled(true);
    leftAxis.setAxisMinimum(0f);
    leftAxis.setAxisMaximum(170f);
    leftAxis.setYOffset(-9f);
    leftAxis.setTextColor(Color.rgb(255, 192, 56));

    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setEnabled(false);
}
 
Example 8
Source File: BarChartPositiveNegative.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_barchart_noseekbar);

    setTitle("BarChartPositiveNegative");

    chart = findViewById(R.id.chart1);
    chart.setBackgroundColor(Color.WHITE);
    chart.setExtraTopOffset(-30f);
    chart.setExtraBottomOffset(10f);
    chart.setExtraLeftOffset(70f);
    chart.setExtraRightOffset(70f);

    chart.setDrawBarShadow(false);
    chart.setDrawValueAboveBar(true);

    chart.getDescription().setEnabled(false);

    // scaling can now only be done on x- and y-axis separately
    chart.setPinchZoom(false);

    chart.setDrawGridBackground(false);

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setTypeface(tfRegular);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextColor(Color.LTGRAY);
    xAxis.setTextSize(13f);
    xAxis.setLabelCount(5);
    xAxis.setCenterAxisLabels(true);
    xAxis.setGranularity(1f);

    YAxis left = chart.getAxisLeft();
    left.setDrawLabels(false);
    left.setSpaceTop(25f);
    left.setSpaceBottom(25f);
    left.setDrawAxisLine(false);
    left.setDrawGridLines(false);
    left.setDrawZeroLine(true); // draw a zero line
    left.setZeroLineColor(Color.GRAY);
    left.setZeroLineWidth(0.7f);
    chart.getAxisRight().setEnabled(false);
    chart.getLegend().setEnabled(false);

    // THIS IS THE ORIGINAL DATA YOU WANT TO PLOT
    final List<Data> data = new ArrayList<>();
    data.add(new Data(0f, -224.1f, "12-29"));
    data.add(new Data(1f, 238.5f, "12-30"));
    data.add(new Data(2f, 1280.1f, "12-31"));
    data.add(new Data(3f, -442.3f, "01-01"));
    data.add(new Data(4f, -2280.1f, "01-02"));

    xAxis.setValueFormatter(new ValueFormatter() {
        @Override
        public String getFormattedValue(float value) {
            return data.get(Math.min(Math.max((int) value, 0), data.size()-1)).xAxisValue;
        }
    });

    setData(data);
}
 
Example 9
Source File: LineChartActivity2.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_linechart);

        setTitle("LineChartActivity2");

        tvX = findViewById(R.id.tvXMax);
        tvY = findViewById(R.id.tvYMax);

        seekBarX = findViewById(R.id.seekBar1);
        seekBarX.setOnSeekBarChangeListener(this);

        seekBarY = findViewById(R.id.seekBar2);
        seekBarY.setOnSeekBarChangeListener(this);

        chart = findViewById(R.id.chart1);
        chart.setOnChartValueSelectedListener(this);

        // no description text
        chart.getDescription().setEnabled(false);

        // enable touch gestures
        chart.setTouchEnabled(true);

        chart.setDragDecelerationFrictionCoef(0.9f);

        // enable scaling and dragging
        chart.setDragEnabled(true);
        chart.setScaleEnabled(true);
        chart.setDrawGridBackground(false);
        chart.setHighlightPerDragEnabled(true);

        // if disabled, scaling can be done on x- and y-axis separately
        chart.setPinchZoom(true);

        // set an alternative background color
        chart.setBackgroundColor(Color.LTGRAY);

        // add data
        seekBarX.setProgress(20);
        seekBarY.setProgress(30);

        chart.animateX(1500);

        // get the legend (only possible after setting data)
        Legend l = chart.getLegend();

        // modify the legend ...
        l.setForm(LegendForm.LINE);
        l.setTypeface(tfLight);
        l.setTextSize(11f);
        l.setTextColor(Color.WHITE);
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
        l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
        l.setDrawInside(false);
//        l.setYOffset(11f);

        XAxis xAxis = chart.getXAxis();
        xAxis.setTypeface(tfLight);
        xAxis.setTextSize(11f);
        xAxis.setTextColor(Color.WHITE);
        xAxis.setDrawGridLines(false);
        xAxis.setDrawAxisLine(false);

        YAxis leftAxis = chart.getAxisLeft();
        leftAxis.setTypeface(tfLight);
        leftAxis.setTextColor(ColorTemplate.getHoloBlue());
        leftAxis.setAxisMaximum(200f);
        leftAxis.setAxisMinimum(0f);
        leftAxis.setDrawGridLines(true);
        leftAxis.setGranularityEnabled(true);

        YAxis rightAxis = chart.getAxisRight();
        rightAxis.setTypeface(tfLight);
        rightAxis.setTextColor(Color.RED);
        rightAxis.setAxisMaximum(900);
        rightAxis.setAxisMinimum(-200);
        rightAxis.setDrawGridLines(false);
        rightAxis.setDrawZeroLine(false);
        rightAxis.setGranularityEnabled(false);
    }
 
Example 10
Source File: ChartFragment.java    From Liapp with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    view = inflater.inflate(R.layout.fragment_lastscanchart, container, false);

    LineChart cv_LastScan = (LineChart) view.findViewById(R.id.cv_LastScan);

    cv_LastScan.setOnChartGestureListener(new myChartGestureListener(cv_LastScan));

    XAxis xAxis = cv_LastScan.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextSize(10f);
    xAxis.setTextColor(getResources().getColor(R.color.colorGlucoseNow));
    xAxis.enableGridDashedLine(5f, 5f, 0f);
    xAxis.setDrawLimitLinesBehindData(true);

    YAxis yAxisLeft = cv_LastScan.getAxisLeft();
    YAxis yAxisRight = cv_LastScan.getAxisRight();

    yAxisRight.setEnabled(false);

    yAxisLeft.setTextSize(18f); // set the textsize
    yAxisLeft.setTextColor(getResources().getColor(R.color.colorGlucoseNow));
    yAxisLeft.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    yAxisLeft.setStartAtZero(true);
    yAxisLeft.setYOffset(-6f);
    yAxisLeft.setAxisMinValue(0.0f);

    Legend legend = cv_LastScan.getLegend();
    legend.setEnabled(false);

    // no description text
    cv_LastScan.setDescription("");
    cv_LastScan.setNoDataText(getResources().getString(R.string.no_data));
    cv_LastScan.setNoDataTextDescription("");

    // enable touch gestures
    cv_LastScan.setTouchEnabled(true);

    // enable scaling and dragging
    cv_LastScan.setDragEnabled(true);
    cv_LastScan.setScaleEnabled(true);
    cv_LastScan.setDrawGridBackground(false);

    // if disabled, scaling can be done on x- and y-axis separately
    cv_LastScan.setPinchZoom(true);


    MyMarkerView mv = new MyMarkerView(view.getContext(), R.layout.custom_marker_view);

    // set the marker to the chart
    cv_LastScan.setMarkerView(mv);

    try {
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
            cv_LastScan.setHardwareAccelerationEnabled(false);

        } else {
           cv_LastScan.setHardwareAccelerationEnabled(true);
        }
    } catch (Exception e) {
    }

    refresh();

    return (view);
}
 
Example 11
Source File: StackedBarActivityNegative.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_age_distribution);

    setTitle("Age Distribution Austria");

    mChart = (HorizontalBarChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawGridBackground(false);
    mChart.setDescription("");

    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);

    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);
    
    mChart.getAxisLeft().setEnabled(false);
    mChart.getAxisRight().setAxisMaxValue(25f);
    mChart.getAxisRight().setAxisMinValue(-25f);
    mChart.getAxisRight().setDrawGridLines(false);
    mChart.getAxisRight().setDrawZeroLine(true);
    mChart.getAxisRight().setLabelCount(7, false);
    mChart.getAxisRight().setValueFormatter(new CustomFormatter());
    mChart.getAxisRight().setTextSize(9f);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextSize(9f);

    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.BELOW_CHART_RIGHT);
    l.setFormSize(8f);
    l.setFormToTextSpace(4f);
    l.setXEntrySpace(6f);

    // IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
    ArrayList<BarEntry> yValues = new ArrayList<BarEntry>();
    yValues.add(new BarEntry(new float[]{ -10, 10 }, 0));
    yValues.add(new BarEntry(new float[]{ -12, 13 }, 1));
    yValues.add(new BarEntry(new float[]{ -15, 15 }, 2));
    yValues.add(new BarEntry(new float[]{ -17, 17 }, 3));
    yValues.add(new BarEntry(new float[]{ -19, 20 }, 4));
    yValues.add(new BarEntry(new float[]{ -19, 19 }, 5));
    yValues.add(new BarEntry(new float[]{ -16, 16 }, 6));
    yValues.add(new BarEntry(new float[]{ -13, 14 }, 7));
    yValues.add(new BarEntry(new float[]{ -10, 11 }, 8));
    yValues.add(new BarEntry(new float[]{ -5, 6 }, 9));
    yValues.add(new BarEntry(new float[]{ -1, 2 }, 10));

    BarDataSet set = new BarDataSet(yValues, "Age Distribution");
    set.setValueFormatter(new CustomFormatter());
    set.setValueTextSize(7f);
    set.setAxisDependency(YAxis.AxisDependency.RIGHT);
    set.setBarSpacePercent(40f);
    set.setColors(new int[] {Color.rgb(67,67,72), Color.rgb(124,181,236)});
    set.setStackLabels(new String[]{
            "Men", "Women"
    });

    String []xVals = new String[]{"0-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80", "80-90", "90-100", "100+"};

    BarData data = new BarData(xVals, set);
    mChart.setData(data);
    mChart.invalidate();
}
 
Example 12
Source File: BarChartPositiveNegative.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_barchart_noseekbar);

    mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
    mChart = (BarChart) findViewById(R.id.chart1);
    mChart.setBackgroundColor(Color.WHITE);
    mChart.setExtraTopOffset(-30f);
    mChart.setExtraBottomOffset(10f);
    mChart.setExtraLeftOffset(70f);
    mChart.setExtraRightOffset(70f);

    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);

    mChart.setDescription("");

    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);

    mChart.setDrawGridBackground(false);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setTypeface(mTf);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setSpaceBetweenLabels(2);
    xAxis.setTextColor(Color.LTGRAY);
    xAxis.setTextSize(13f);

    YAxis left = mChart.getAxisLeft();
    left.setDrawLabels(false);
    left.setStartAtZero(false);
    left.setSpaceTop(25f);
    left.setSpaceBottom(25f);
    left.setDrawAxisLine(false);
    left.setDrawGridLines(false);
    left.setDrawZeroLine(true); // draw a zero line
    left.setZeroLineColor(Color.GRAY);
    left.setZeroLineWidth(0.7f);
    mChart.getAxisRight().setEnabled(false);
    mChart.getLegend().setEnabled(false);

    // THIS IS THE ORIGINAL DATA YOU WANT TO PLOT
    List<Data> data = new ArrayList<>();
    data.add(new Data(0, -224.1f, "12-29"));
    data.add(new Data(1, 238.5f, "12-30"));
    data.add(new Data(2, 1280.1f, "12-31"));
    data.add(new Data(3, -442.3f, "01-01"));
    data.add(new Data(4, -2280.1f, "01-02"));

    setData(data);
}
 
Example 13
Source File: LineChartActivity2.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_linechart);

        tvX = (TextView) findViewById(R.id.tvXMax);
        tvY = (TextView) findViewById(R.id.tvYMax);
        mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
        mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);

        mSeekBarX.setProgress(45);
        mSeekBarY.setProgress(100);

        mSeekBarY.setOnSeekBarChangeListener(this);
        mSeekBarX.setOnSeekBarChangeListener(this);

        mChart = (LineChart) findViewById(R.id.chart1);
        mChart.setOnChartValueSelectedListener(this);
        
        // no description text
        mChart.setDescription("");
        mChart.setNoDataTextDescription("You need to provide data for the chart.");

        // enable touch gestures
        mChart.setTouchEnabled(true);
        
        mChart.setDragDecelerationFrictionCoef(0.9f);

        // enable scaling and dragging
        mChart.setDragEnabled(true);
        mChart.setScaleEnabled(true);
        mChart.setDrawGridBackground(false);
        mChart.setHighlightPerDragEnabled(true);

        // if disabled, scaling can be done on x- and y-axis separately
        mChart.setPinchZoom(true);

        // set an alternative background color
        mChart.setBackgroundColor(Color.LTGRAY);

        // add data
        setData(20, 30);

        mChart.animateX(2500);

        Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

        // get the legend (only possible after setting data)
        Legend l = mChart.getLegend();

        // modify the legend ...
        // l.setPosition(LegendPosition.LEFT_OF_CHART);
        l.setForm(LegendForm.LINE);
        l.setTypeface(tf);
        l.setTextSize(11f);
        l.setTextColor(Color.WHITE);
        l.setPosition(LegendPosition.BELOW_CHART_LEFT);
//        l.setYOffset(11f);

        XAxis xAxis = mChart.getXAxis();
        xAxis.setTypeface(tf);
        xAxis.setTextSize(12f);
        xAxis.setTextColor(Color.WHITE);
        xAxis.setDrawGridLines(false);
        xAxis.setDrawAxisLine(false);
        xAxis.setSpaceBetweenLabels(1);

        YAxis leftAxis = mChart.getAxisLeft();
        leftAxis.setTypeface(tf);
        leftAxis.setTextColor(ColorTemplate.getHoloBlue());
        leftAxis.setAxisMaxValue(200f);
        leftAxis.setAxisMinValue(0f);
        leftAxis.setDrawGridLines(true);
        
        YAxis rightAxis = mChart.getAxisRight();
        rightAxis.setTypeface(tf);
        rightAxis.setTextColor(Color.RED);
        rightAxis.setAxisMaxValue(900);
        rightAxis.setAxisMinValue(-200);
        rightAxis.setDrawGridLines(false);
        rightAxis.setDrawZeroLine(false);
    }
 
Example 14
Source File: RadarChartActivitry.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_radarchart);

    mChart = (RadarChart) findViewById(R.id.chart1);

    tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

    mChart.setDescription("");

    mChart.setWebLineWidth(1.5f);
    mChart.setWebLineWidthInner(0.75f);
    mChart.setWebAlpha(100);

    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);

    // set the marker to the chart
    mChart.setMarkerView(mv);

    setData();

    mChart.animateXY(
            1400, 1400,
            Easing.EasingOption.EaseInOutQuad,
            Easing.EasingOption.EaseInOutQuad);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setTypeface(tf);
    xAxis.setTextSize(9f);

    YAxis yAxis = mChart.getYAxis();
    yAxis.setTypeface(tf);
    yAxis.setLabelCount(5, false);
    yAxis.setTextSize(9f);
    yAxis.setAxisMinValue(0f);

    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.RIGHT_OF_CHART);
    l.setTypeface(tf);
    l.setXEntrySpace(7f);
    l.setYEntrySpace(5f);
}
 
Example 15
Source File: LineChartCard.java    From ResearchStack with Apache License 2.0 4 votes vote down vote up
private void initializeViews() {
    titleTextView = (TextView) findViewById(R.id.view_chart_line_title);
    titleTextView.setText(titleText);
    titleTextView.setTextColor(titleTextColor);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize);
    titleTextView.setTypeface(Typeface.create(titleTextTypeface, Typeface.NORMAL));

    expand = (ImageView) findViewById(R.id.view_chart_line_expand);
    if (expandTintColor != 0) {
        Drawable drawable = expand.getDrawable();
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable, expandTintColor);
        expand.setImageDrawable(drawable);
    }

    chart = (LineChart) findViewById(R.id.view_chart_line);
    chart.getLegend().setEnabled(false);
    chart.setDescription("");
    chart.setDrawBorders(false);
    chart.setDrawGridBackground(false);
    chart.setPinchZoom(false);
    chart.setTouchEnabled(true);
    chart.setDragEnabled(true);
    chart.setExtraLeftOffset(0);
    chart.setExtraBottomOffset(8);
    chart.setExtraTopOffset(0);

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setDrawAxisLine(false);
    xAxis.setDrawGridLines(false);
    xAxis.setLabelsToSkip(0);
    xAxis.setXOffset(16);
    xAxis.setTextSize(chartXAxisTextSize);
    xAxis.setTextColor(chartXAxisTextColor);
    xAxis.setTypeface(Typeface.create(chartXAxisTextTypeface, Typeface.NORMAL));

    YAxis yAxisLeft = chart.getAxisLeft();
    yAxisLeft.setDrawAxisLine(false);
    yAxisLeft.setDrawGridLines(false);
    yAxisLeft.setDrawZeroLine(false);
    yAxisLeft.setDrawLabels(true);
    yAxisLeft.setShowOnlyMinMax(true);
    yAxisLeft.setXOffset(16);
    yAxisLeft.setTextSize(chartYAxisTextSize);
    yAxisLeft.setTextColor(chartYAxisTextColor);
    yAxisLeft.setTypeface(Typeface.create(chartYAxisTextTypeface, Typeface.NORMAL));

    YAxis yAxisRight = chart.getAxisRight();
    yAxisRight.setDrawAxisLine(false);
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setDrawZeroLine(false);
    yAxisRight.setDrawLabels(false);
    yAxisRight.setSpaceTop(0);
}
 
Example 16
Source File: BarChartCard.java    From ResearchStack with Apache License 2.0 4 votes vote down vote up
private void initializeViews() {
    titleTextView = (TextView) findViewById(R.id.view_chart_bar_title);
    titleTextView.setText(titleText);
    titleTextView.setTextColor(titleTextColor);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize);
    titleTextView.setTypeface(Typeface.create(titleTextTypeface, Typeface.NORMAL));

    expand = (ImageView) findViewById(R.id.view_chart_line_expand);
    if (expandTintColor != 0) {
        Drawable drawable = expand.getDrawable();
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable, expandTintColor);
        expand.setImageDrawable(drawable);
    }

    chart = (BarChart) findViewById(R.id.view_chart_bar);
    chart.getLegend().setEnabled(false);
    chart.setDescription("");
    chart.setDrawBorders(false);
    chart.setDrawValueAboveBar(false);
    chart.setDrawGridBackground(false);
    chart.setDrawBarShadow(false);
    chart.setDrawHighlightArrow(false);
    chart.setPinchZoom(false);
    chart.setExtraLeftOffset(0);
    chart.setExtraRightOffset(0);
    chart.setExtraBottomOffset(8);
    chart.setExtraTopOffset(0);
    chart.setTouchEnabled(true);
    chart.setDragEnabled(true);

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setDrawAxisLine(false);
    xAxis.setYOffset(16);
    xAxis.setDrawGridLines(false);
    xAxis.setLabelsToSkip(0);
    xAxis.setTextSize(chartXAxisTextSize);
    xAxis.setTextColor(chartXAxisTextColor);
    xAxis.setTypeface(Typeface.create(chartXAxisTextTypeface, Typeface.NORMAL));

    YAxis yAxisLeft = chart.getAxisLeft();
    yAxisLeft.setDrawAxisLine(false);
    yAxisLeft.setDrawGridLines(false);
    yAxisLeft.setDrawZeroLine(false);
    yAxisLeft.setDrawLabels(false);

    YAxis yAxisRight = chart.getAxisRight();
    yAxisRight.setDrawAxisLine(false);
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setDrawZeroLine(false);
    yAxisRight.setDrawLabels(false);
}