Search in sources :

Example 36 with XAxis

use of com.github.mikephil.charting.components.XAxis in project MPAndroidChart by PhilJay.

the class Chart method init.

/**
     * initialize all paints and stuff
     */
protected void init() {
    setWillNotDraw(false);
    if (android.os.Build.VERSION.SDK_INT < 11)
        mAnimator = new ChartAnimator();
    else
        mAnimator = new ChartAnimator(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                // ViewCompat.postInvalidateOnAnimation(Chart.this);
                postInvalidate();
            }
        });
    // initialize the utils
    Utils.init(getContext());
    mMaxHighlightDistance = Utils.convertDpToPixel(500f);
    mDescription = new Description();
    mLegend = new Legend();
    mLegendRenderer = new LegendRenderer(mViewPortHandler, mLegend);
    mXAxis = new XAxis();
    mDescPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mInfoPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    // orange
    mInfoPaint.setColor(Color.rgb(247, 189, 51));
    mInfoPaint.setTextAlign(Align.CENTER);
    mInfoPaint.setTextSize(Utils.convertDpToPixel(12f));
    if (mLogEnabled)
        Log.i("", "Chart.init()");
}
Also used : Legend(com.github.mikephil.charting.components.Legend) Description(com.github.mikephil.charting.components.Description) LegendRenderer(com.github.mikephil.charting.renderer.LegendRenderer) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) Paint(android.graphics.Paint) ValueAnimator(android.animation.ValueAnimator) ChartAnimator(com.github.mikephil.charting.animation.ChartAnimator) XAxis(com.github.mikephil.charting.components.XAxis)

Example 37 with XAxis

use of com.github.mikephil.charting.components.XAxis in project MPAndroidChart by PhilJay.

the class PieRadarChartBase method calculateOffsets.

@Override
public void calculateOffsets() {
    float legendLeft = 0f, legendRight = 0f, legendBottom = 0f, legendTop = 0f;
    if (mLegend != null && mLegend.isEnabled() && !mLegend.isDrawInsideEnabled()) {
        float fullLegendWidth = Math.min(mLegend.mNeededWidth, mViewPortHandler.getChartWidth() * mLegend.getMaxSizePercent());
        switch(mLegend.getOrientation()) {
            case VERTICAL:
                {
                    float xLegendOffset = 0.f;
                    if (mLegend.getHorizontalAlignment() == Legend.LegendHorizontalAlignment.LEFT || mLegend.getHorizontalAlignment() == Legend.LegendHorizontalAlignment.RIGHT) {
                        if (mLegend.getVerticalAlignment() == Legend.LegendVerticalAlignment.CENTER) {
                            // this is the space between the legend and the chart
                            final float spacing = Utils.convertDpToPixel(13f);
                            xLegendOffset = fullLegendWidth + spacing;
                        } else {
                            // this is the space between the legend and the chart
                            float spacing = Utils.convertDpToPixel(8f);
                            float legendWidth = fullLegendWidth + spacing;
                            float legendHeight = mLegend.mNeededHeight + mLegend.mTextHeightMax;
                            MPPointF center = getCenter();
                            float bottomX = mLegend.getHorizontalAlignment() == Legend.LegendHorizontalAlignment.RIGHT ? getWidth() - legendWidth + 15.f : legendWidth - 15.f;
                            float bottomY = legendHeight + 15.f;
                            float distLegend = distanceToCenter(bottomX, bottomY);
                            MPPointF reference = getPosition(center, getRadius(), getAngleForPoint(bottomX, bottomY));
                            float distReference = distanceToCenter(reference.x, reference.y);
                            float minOffset = Utils.convertDpToPixel(5f);
                            if (bottomY >= center.y && getHeight() - legendWidth > getWidth()) {
                                xLegendOffset = legendWidth;
                            } else if (distLegend < distReference) {
                                float diff = distReference - distLegend;
                                xLegendOffset = minOffset + diff;
                            }
                            MPPointF.recycleInstance(center);
                            MPPointF.recycleInstance(reference);
                        }
                    }
                    switch(mLegend.getHorizontalAlignment()) {
                        case LEFT:
                            legendLeft = xLegendOffset;
                            break;
                        case RIGHT:
                            legendRight = xLegendOffset;
                            break;
                        case CENTER:
                            switch(mLegend.getVerticalAlignment()) {
                                case TOP:
                                    legendTop = Math.min(mLegend.mNeededHeight, mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent());
                                    break;
                                case BOTTOM:
                                    legendBottom = Math.min(mLegend.mNeededHeight, mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent());
                                    break;
                            }
                            break;
                    }
                }
                break;
            case HORIZONTAL:
                float yLegendOffset = 0.f;
                if (mLegend.getVerticalAlignment() == Legend.LegendVerticalAlignment.TOP || mLegend.getVerticalAlignment() == Legend.LegendVerticalAlignment.BOTTOM) {
                    // It's possible that we do not need this offset anymore as it
                    //   is available through the extraOffsets, but changing it can mean
                    //   changing default visibility for existing apps.
                    float yOffset = getRequiredLegendOffset();
                    yLegendOffset = Math.min(mLegend.mNeededHeight + yOffset, mViewPortHandler.getChartHeight() * mLegend.getMaxSizePercent());
                    switch(mLegend.getVerticalAlignment()) {
                        case TOP:
                            legendTop = yLegendOffset;
                            break;
                        case BOTTOM:
                            legendBottom = yLegendOffset;
                            break;
                    }
                }
                break;
        }
        legendLeft += getRequiredBaseOffset();
        legendRight += getRequiredBaseOffset();
        legendTop += getRequiredBaseOffset();
        legendBottom += getRequiredBaseOffset();
    }
    float minOffset = Utils.convertDpToPixel(mMinOffset);
    if (this instanceof RadarChart) {
        XAxis x = this.getXAxis();
        if (x.isEnabled() && x.isDrawLabelsEnabled()) {
            minOffset = Math.max(minOffset, x.mLabelRotatedWidth);
        }
    }
    legendTop += getExtraTopOffset();
    legendRight += getExtraRightOffset();
    legendBottom += getExtraBottomOffset();
    legendLeft += getExtraLeftOffset();
    float offsetLeft = Math.max(minOffset, legendLeft);
    float offsetTop = Math.max(minOffset, legendTop);
    float offsetRight = Math.max(minOffset, legendRight);
    float offsetBottom = Math.max(minOffset, Math.max(getRequiredBaseOffset(), legendBottom));
    mViewPortHandler.restrainViewPort(offsetLeft, offsetTop, offsetRight, offsetBottom);
    if (mLogEnabled)
        Log.i(LOG_TAG, "offsetLeft: " + offsetLeft + ", offsetTop: " + offsetTop + ", offsetRight: " + offsetRight + ", offsetBottom: " + offsetBottom);
}
Also used : MPPointF(com.github.mikephil.charting.utils.MPPointF) XAxis(com.github.mikephil.charting.components.XAxis)

Example 38 with XAxis

use of com.github.mikephil.charting.components.XAxis in project Weather by Sparker0i.

the class GraphsFragment method loadSnowChart.

public void loadSnowChart() {
    snowChart.setDrawGridBackground(false);
    snowChart.setBackgroundColor(Color.BLACK);
    snowChart.setTouchEnabled(true);
    snowChart.setDragEnabled(true);
    snowChart.setMaxHighlightDistance(300);
    snowChart.setPinchZoom(true);
    snowChart.setPadding(2, 2, 2, 2);
    snowChart.getLegend().setEnabled(true);
    snowChart.getLegend().setTextColor(Color.WHITE);
    YAxis yAxisRight = snowChart.getAxisRight();
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setDrawAxisLine(false);
    yAxisRight.setDrawLabels(false);
    yAxisRight.setTextColor(Color.WHITE);
    yAxisRight.enableAxisLineDashedLine(2f, 4f, 2f);
    YAxis yAxisLeft = snowChart.getAxisLeft();
    yAxisLeft.setTextColor(Color.WHITE);
    XAxis x = snowChart.getXAxis();
    x.setEnabled(true);
    x.setPosition(XAxis.XAxisPosition.BOTTOM);
    x.setDrawGridLines(false);
    x.setTextColor(Color.parseColor("#FFFFFF"));
    x.setValueFormatter(new XFormatter(dates));
    LineDataSet set;
    if (snowChart.getData() != null) {
        snowChart.getData().removeDataSet(snowChart.getData().getDataSetByIndex(snowChart.getData().getDataSetCount() - 1));
        snowChart.getLegend().setTextColor(Color.parseColor("#FFFFFF"));
    }
    set = new LineDataSet(snowEntries, getString(R.string.g_snow));
    set.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    set.setCubicIntensity(0.2f);
    set.setDrawCircles(false);
    set.setLineWidth(2f);
    set.setDrawValues(false);
    set.setValueTextSize(10f);
    set.setColor(Color.YELLOW);
    set.setHighlightEnabled(false);
    set.setValueFormatter(mValueFormatter);
    LineData data = new LineData(set);
    snowChart.setData(data);
    snowChart.invalidate();
}
Also used : LineData(com.github.mikephil.charting.data.LineData) LineDataSet(com.github.mikephil.charting.data.LineDataSet) XFormatter(com.a5corp.weather.utils.XFormatter) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 39 with XAxis

use of com.github.mikephil.charting.components.XAxis in project Weather by Sparker0i.

the class GraphsFragment method loadWindChart.

public void loadWindChart() {
    windChart.setDrawGridBackground(false);
    windChart.setBackgroundColor(Color.BLACK);
    windChart.setTouchEnabled(true);
    windChart.setDragEnabled(true);
    windChart.setMaxHighlightDistance(300);
    windChart.setPinchZoom(true);
    windChart.setPadding(2, 2, 2, 2);
    windChart.getLegend().setEnabled(true);
    windChart.getLegend().setTextColor(Color.WHITE);
    YAxis yAxisRight = windChart.getAxisRight();
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setDrawAxisLine(false);
    yAxisRight.setDrawLabels(false);
    yAxisRight.setTextColor(Color.WHITE);
    yAxisRight.enableAxisLineDashedLine(2f, 4f, 2f);
    YAxis yAxisLeft = windChart.getAxisLeft();
    yAxisLeft.setTextColor(Color.WHITE);
    XAxis x = windChart.getXAxis();
    x.setEnabled(true);
    x.setPosition(XAxis.XAxisPosition.BOTTOM);
    x.setDrawGridLines(false);
    x.setTextColor(Color.parseColor("#FFFFFF"));
    x.setValueFormatter(new XFormatter(dates));
    LineDataSet set;
    if (windChart.getData() != null) {
        windChart.getData().removeDataSet(windChart.getData().getDataSetByIndex(windChart.getData().getDataSetCount() - 1));
        windChart.getLegend().setTextColor(Color.parseColor("#FFFFFF"));
    }
    String wind = String.format(Locale.ENGLISH, getString(R.string.g_wind), pf.getUnits().equals("metric") ? getString(R.string.mps) : getString(R.string.mph));
    set = new LineDataSet(windEntries, wind);
    set.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    set.setCubicIntensity(0.2f);
    set.setDrawCircles(false);
    set.setLineWidth(2f);
    set.setDrawValues(false);
    set.setValueTextSize(10f);
    set.setColor(Color.RED);
    set.setHighlightEnabled(false);
    set.setValueFormatter(mValueFormatter);
    LineData data = new LineData(set);
    windChart.setData(data);
    windChart.invalidate();
}
Also used : LineData(com.github.mikephil.charting.data.LineData) LineDataSet(com.github.mikephil.charting.data.LineDataSet) XFormatter(com.a5corp.weather.utils.XFormatter) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 40 with XAxis

use of com.github.mikephil.charting.components.XAxis in project Weather by Sparker0i.

the class GraphsFragment method loadPressureChart.

public void loadPressureChart() {
    pressureChart.setDrawGridBackground(false);
    pressureChart.setBackgroundColor(Color.BLACK);
    pressureChart.setTouchEnabled(true);
    pressureChart.setDragEnabled(true);
    pressureChart.setMaxHighlightDistance(300);
    pressureChart.setPinchZoom(true);
    pressureChart.setPadding(2, 2, 2, 2);
    pressureChart.getLegend().setEnabled(true);
    pressureChart.getLegend().setTextColor(Color.WHITE);
    YAxis yAxisRight = pressureChart.getAxisRight();
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setDrawAxisLine(false);
    yAxisRight.setDrawLabels(false);
    yAxisRight.setTextColor(Color.WHITE);
    yAxisRight.enableAxisLineDashedLine(2f, 4f, 2f);
    YAxis yAxisLeft = pressureChart.getAxisLeft();
    yAxisLeft.setTextColor(Color.WHITE);
    XAxis x = pressureChart.getXAxis();
    x.setEnabled(true);
    x.setPosition(XAxis.XAxisPosition.BOTTOM);
    x.setDrawGridLines(false);
    x.setTextColor(Color.parseColor("#FFFFFF"));
    x.setValueFormatter(new XFormatter(dates));
    LineDataSet set;
    if (pressureChart.getData() != null) {
        pressureChart.getData().removeDataSet(pressureChart.getData().getDataSetByIndex(pressureChart.getData().getDataSetCount() - 1));
        pressureChart.getLegend().setTextColor(Color.parseColor("#FFFFFF"));
    }
    set = new LineDataSet(pressureEntries, getString(R.string.g_pressure));
    set.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    set.setCubicIntensity(0.2f);
    set.setDrawCircles(false);
    set.setLineWidth(2f);
    set.setDrawValues(false);
    set.setValueTextSize(10f);
    set.setColor(Color.CYAN);
    set.setHighlightEnabled(false);
    set.setValueFormatter(mValueFormatter);
    LineData data = new LineData(set);
    pressureChart.setData(data);
    pressureChart.invalidate();
}
Also used : LineData(com.github.mikephil.charting.data.LineData) LineDataSet(com.github.mikephil.charting.data.LineDataSet) XFormatter(com.a5corp.weather.utils.XFormatter) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Aggregations

XAxis (com.github.mikephil.charting.components.XAxis)40 YAxis (com.github.mikephil.charting.components.YAxis)35 Legend (com.github.mikephil.charting.components.Legend)21 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)7 Typeface (android.graphics.Typeface)6 AxisBase (com.github.mikephil.charting.components.AxisBase)6 LineData (com.github.mikephil.charting.data.LineData)6 LineDataSet (com.github.mikephil.charting.data.LineDataSet)6 XFormatter (com.a5corp.weather.utils.XFormatter)5 MyMarkerView (com.xxmassdeveloper.mpchartexample.custom.MyMarkerView)5 View (android.view.View)4 ArrayList (java.util.ArrayList)3 Paint (android.graphics.Paint)2 BarData (com.github.mikephil.charting.data.BarData)2 MyAxisValueFormatter (com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter)2 ValueAnimator (android.animation.ValueAnimator)1 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 ChartAnimator (com.github.mikephil.charting.animation.ChartAnimator)1