com.github.mikephil.charting.charts.Chart Java Examples

The following examples show how to use com.github.mikephil.charting.charts.Chart. 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: MyMarkerView.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {

    MPPointF offset = getOffset();
    mOffset2.x = offset.x;
    mOffset2.y = offset.y;

    Chart chart = getChartView();

    float width = getWidth();
    float height = getHeight();

    if (posX + mOffset2.x < 0) {
        mOffset2.x = -posX;
    } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
        mOffset2.x = chart.getWidth() - posX - width;
    }

    if (posY + mOffset2.y < 0) {
        mOffset2.y = -posY;
    } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
        mOffset2.y = chart.getHeight() - posY - height;
    }

    return mOffset2;
}
 
Example #2
Source File: MarkerView.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {

    MPPointF offset = getOffset();
    mOffset2.x = offset.x;
    mOffset2.y = offset.y;

    Chart chart = getChartView();

    float width = getWidth();
    float height = getHeight();

    if (posX + mOffset2.x < 0) {
        mOffset2.x = - posX;
    } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
        mOffset2.x = chart.getWidth() - posX - width;
    }

    if (posY + mOffset2.y < 0) {
        mOffset2.y = - posY;
    } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
        mOffset2.y = chart.getHeight() - posY - height;
    }

    return mOffset2;
}
 
Example #3
Source File: MarkerView.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {

    MPPointF offset = getOffset();
    mOffset2.x = offset.x;
    mOffset2.y = offset.y;

    Chart chart = getChartView();

    float width = getWidth();
    float height = getHeight();

    if (posX + mOffset2.x < 0) {
        mOffset2.x = -posX;
    } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
        mOffset2.x = chart.getWidth() - posX - width;
    }

    if (posY + mOffset2.y < 0) {
        mOffset2.y = -posY;
    } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
        mOffset2.y = chart.getHeight() - posY - height;
    }

    return mOffset2;
}
 
Example #4
Source File: InfoViewListener.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public void onValueSelected(Entry e, Highlight h) {
    int x = (int) e.getX();
    if (x < mList.size()) {
        mInfoView.setVisibility(View.VISIBLE);
        mInfoView.setData(mLastClose, mList.get(x));
    }
    FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mInfoView.getLayoutParams();
    if (h.getXPx() < mWidth / 2) {
        lp.gravity = Gravity.RIGHT;
    } else {
        lp.gravity = Gravity.LEFT;
    }
    mInfoView.setLayoutParams(lp);
    if (mOtherChart != null) {
        for (Chart aMOtherChart : mOtherChart) {
            aMOtherChart.highlightValues(new Highlight[]{new Highlight(h.getX(), Float.NaN, h.getDataSetIndex())});
        }
    }
}
 
Example #5
Source File: ChartBaseManager.java    From react-native-mp-android-chart with MIT License 6 votes vote down vote up
@ReactProp(name = "description")
public void setDescription(Chart chart, ReadableMap propMap) {
    if (BridgeUtils.validate(propMap, ReadableType.String, "text")) {
        chart.setDescription(propMap.getString("text"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.String, "textColor")) {
        chart.setDescriptionColor(Color.parseColor(propMap.getString("textColor")));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) {
        chart.setDescriptionTextSize((float) propMap.getDouble("textSize"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "positionX") &&
            BridgeUtils.validate(propMap, ReadableType.Number, "positionY")) {

        chart.setDescriptionPosition((float) propMap.getDouble("positionX"), (float) propMap.getDouble("positionY"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.String, "fontFamily") ||
            BridgeUtils.validate(propMap, ReadableType.Number, "fontStyle")) {
        chart.setDescriptionTypeface(BridgeUtils.parseTypeface(chart.getContext(), propMap, "fontStyle", "fontFamily"));
    }
}
 
Example #6
Source File: MarkerView.java    From android-kline with Apache License 2.0 6 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {

    MPPointF offset = getOffset();
    mOffset2.x = offset.x;
    mOffset2.y = offset.y;

    Chart chart = getChartView();

    float width = getWidth();
    float height = getHeight();

    if (posX + mOffset2.x < 0) {
        mOffset2.x = - posX;
    } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
        mOffset2.x = chart.getWidth() - posX - width;
    }

    if (posY + mOffset2.y < 0) {
        mOffset2.y = - posY;
    } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
        mOffset2.y = chart.getHeight() - posY - height;
    }

    return mOffset2;
}
 
Example #7
Source File: ChartBaseManager.java    From react-native-mp-android-chart with MIT License 6 votes vote down vote up
/**
 * xAxis config details: https://github.com/PhilJay/MPAndroidChart/wiki/XAxis
 */
@ReactProp(name = "xAxis")
public void setXAxis(Chart chart, ReadableMap propMap) {
    XAxis axis = chart.getXAxis();

    setCommonAxisConfig(chart, axis, propMap);

    if (BridgeUtils.validate(propMap, ReadableType.Number, "labelsToSkip")) {
        axis.setLabelsToSkip(propMap.getInt("labelsToSkip"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "avoidFirstLastClipping")) {
        axis.setAvoidFirstLastClipping(propMap.getBoolean("avoidFirstLastClipping"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceBetweenLabels")) {
        axis.setSpaceBetweenLabels(propMap.getInt("spaceBetweenLabels"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.String, "position")) {
        axis.setPosition(XAxisPosition.valueOf(propMap.getString("position")));
    }
}
 
Example #8
Source File: ChartBaseManager.java    From react-native-mp-android-chart with MIT License 5 votes vote down vote up
/**
 *
 * Dataset config details: https://github.com/PhilJay/MPAndroidChart/wiki/DataSet-classes-in-detail
 */
@ReactProp(name = "data")
public void setData(Chart chart, ReadableMap propMap) {
    if (!BridgeUtils.validate(propMap, ReadableType.Array, "datasets")) {
        return;
    }

    String[] xValues = new String[0];
    if (BridgeUtils.validate(propMap, ReadableType.Array, "xValues")) {
        xValues = BridgeUtils.convertToStringArray(propMap.getArray("xValues"));
    }

    ChartData<IDataSet<U>> chartData = createData(xValues);

    ReadableArray datasets = propMap.getArray("datasets");
    for (int i = 0; i < datasets.size(); i++) {
        ReadableMap dataset = datasets.getMap(i);

        // TODO validation
        ReadableArray yValues = dataset.getArray("yValues");
        String label = dataset.getString("label");

        ArrayList<U> entries = createEntries(yValues);

        IDataSet<U> lineDataSet = createDataSet(entries, label);

        if (BridgeUtils.validate(dataset, ReadableType.Map, "config")) {
            dataSetConfig(lineDataSet, dataset.getMap("config"));
        }

        chartData.addDataSet(lineDataSet);
    }

    chart.setData(chartData);
    chart.invalidate();
}
 
Example #9
Source File: BarGraphMarkerView.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public BarGraphMarkerView(Context context, int layoutResource, Chart chart) {
    super(context, layoutResource);

    // find your layout components
    tvContent = findViewById(R.id.tvContent);
    tvDate = findViewById(R.id.tvDate);
    uiScreenWidth = getResources().getDisplayMetrics().widthPixels;
    lineChart = chart;
}
 
Example #10
Source File: NodeInfoFragment.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ((AppCompatActivity) getActivity()).setSupportActionBar(nodeInfoToolbar);
    chart.setNoDataText(getString(R.string.messages_no_chart_data));
    chart.setNoDataTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary));
    chart.setEntryLabelColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary));
    Paint p = chart.getPaint(Chart.PAINT_INFO);
    p.setColor(ContextCompat.getColor(getActivity(), R.color.colorAccent));
    initializeChart();
}
 
Example #11
Source File: MarkerImage.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {

    MPPointF offset = getOffset();
    mOffset2.x = offset.x;
    mOffset2.y = offset.y;

    Chart chart = getChartView();

    float width = mSize.width;
    float height = mSize.height;

    if (width == 0.f && mDrawable != null) {
        width = mDrawable.getIntrinsicWidth();
    }
    if (height == 0.f && mDrawable != null) {
        height = mDrawable.getIntrinsicHeight();
    }

    if (posX + mOffset2.x < 0) {
        mOffset2.x = - posX;
    } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
        mOffset2.x = chart.getWidth() - posX - width;
    }

    if (posY + mOffset2.y < 0) {
        mOffset2.y = - posY;
    } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
        mOffset2.y = chart.getHeight() - posY - height;
    }

    return mOffset2;
}
 
Example #12
Source File: RadarChartManager.java    From react-native-mp-android-chart with MIT License 5 votes vote down vote up
@Override
public void setYAxis(Chart chart, ReadableMap propMap) {
    RadarChart radarChart = (RadarChart) chart;
    YAxis axis = radarChart.getYAxis();

    setCommonAxisConfig(chart, axis, propMap);
    setYAxisConfig(axis, propMap);
}
 
Example #13
Source File: MarkerImage.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {

    MPPointF offset = getOffset();
    mOffset2.x = offset.x;
    mOffset2.y = offset.y;

    Chart chart = getChartView();

    float width = mSize.width;
    float height = mSize.height;

    if (width == 0.f && mDrawable != null) {
        width = mDrawable.getIntrinsicWidth();
    }
    if (height == 0.f && mDrawable != null) {
        height = mDrawable.getIntrinsicHeight();
    }

    if (posX + mOffset2.x < 0) {
        mOffset2.x = -posX;
    } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
        mOffset2.x = chart.getWidth() - posX - width;
    }

    if (posY + mOffset2.y < 0) {
        mOffset2.y = -posY;
    } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
        mOffset2.y = chart.getHeight() - posY - height;
    }

    return mOffset2;
}
 
Example #14
Source File: ChartBaseManager.java    From react-native-mp-android-chart with MIT License 5 votes vote down vote up
/**
 * Animations docs: https://github.com/PhilJay/MPAndroidChart/wiki/Animations
*/
@ReactProp(name = "animation")
public void setAnimation(Chart chart, ReadableMap propMap) {
    Integer durationX = null;
    Integer durationY = null;
    EasingOption easingX = EasingOption.Linear;
    EasingOption easingY = EasingOption.Linear;

    if (BridgeUtils.validate(propMap, ReadableType.Number, "durationX")) {
        durationX = propMap.getInt("durationX");
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "durationY")) {
        durationY = propMap.getInt("durationY");
    }
    if (BridgeUtils.validate(propMap, ReadableType.String, "easingX")) {
        easingX = EasingOption.valueOf(propMap.getString("easingX"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.String, "easingY")) {
        easingY = EasingOption.valueOf(propMap.getString("easingY"));
    }

    if (durationX != null && durationY != null) {
        chart.animateXY(durationX, durationY, easingX, easingY);
    } else if (durationX != null) {
        chart.animateX(durationX, easingX);
    } else if (durationY != null) {
        chart.animateY(durationY, easingY);
    }
}
 
Example #15
Source File: CoupleChartGestureListener.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
public void syncCharts() {
    if (dstCharts == null) {
        return;
    }
    Matrix srcMatrix;
    float[] srcVals = new float[9];
    Matrix dstMatrix;
    float[] dstVals = new float[9];
    // get src chart translation matrix:
    srcMatrix = srcChart.getViewPortHandler().getMatrixTouch();
    srcMatrix.getValues(srcVals);

    // apply X axis scaling and position to dst charts:
    for (Chart dstChart : dstCharts) {
        if (dstChart.getVisibility() == View.VISIBLE) {
            dstMatrix = dstChart.getViewPortHandler().getMatrixTouch();
            dstMatrix.getValues(dstVals);

            dstVals[Matrix.MSCALE_X] = srcVals[Matrix.MSCALE_X];
            dstVals[Matrix.MSKEW_X] = srcVals[Matrix.MSKEW_X];
            dstVals[Matrix.MTRANS_X] = srcVals[Matrix.MTRANS_X];
            dstVals[Matrix.MSKEW_Y] = srcVals[Matrix.MSKEW_Y];
            dstVals[Matrix.MSCALE_Y] = srcVals[Matrix.MSCALE_Y];
            dstVals[Matrix.MTRANS_Y] = srcVals[Matrix.MTRANS_Y];
            dstVals[Matrix.MPERSP_0] = srcVals[Matrix.MPERSP_0];
            dstVals[Matrix.MPERSP_1] = srcVals[Matrix.MPERSP_1];
            dstVals[Matrix.MPERSP_2] = srcVals[Matrix.MPERSP_2];

            dstMatrix.setValues(dstVals);
            dstChart.getViewPortHandler().refresh(dstMatrix, dstChart, true);
        }
    }
}
 
Example #16
Source File: CombinedChartRenderer.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
    Chart chart = mChart.get();
    if (chart == null) {
        return;
    }

    for (DataRenderer renderer : mRenderers) {
        ChartData data = null;

        if (renderer instanceof BarChartRenderer) {
            data = ((BarChartRenderer) renderer).mChart.getBarData();
        } else if (renderer instanceof LineChartRenderer) {
            data = ((LineChartRenderer) renderer).mChart.getLineData();
        } else if (renderer instanceof CandleStickChartRenderer) {
            data = ((CandleStickChartRenderer) renderer).mChart.getCandleData();
        } else if (renderer instanceof ScatterChartRenderer) {
            data = ((ScatterChartRenderer) renderer).mChart.getScatterData();
        } else if (renderer instanceof BubbleChartRenderer) {
            data = ((BubbleChartRenderer) renderer).mChart.getBubbleData();
        }

        int dataIndex = data == null ? -1
                : ((CombinedData) chart.getData()).getAllData().indexOf(data);

        mHighlightBuffer.clear();

        for (Highlight h : indices) {
            if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1) {
                mHighlightBuffer.add(h);
            }
        }

        renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()]));
    }
}
 
Example #17
Source File: CoupleChartGestureListener.java    From shinny-futures-android with GNU General Public License v3.0 5 votes vote down vote up
private void syncCharts() {
    Matrix srcMatrix;
    float[] srcVals = new float[9];
    Matrix dstMatrix;
    float[] dstVals = new float[9];
    // get src chart translation matrix:
    srcMatrix = srcChart.getViewPortHandler().getMatrixTouch();
    srcMatrix.getValues(srcVals);
    // apply X axis scaling and position to dst charts:
    for (Chart dstChart : dstCharts) {
        dstMatrix = dstChart.getViewPortHandler().getMatrixTouch();
        dstMatrix.getValues(dstVals);

        dstVals[Matrix.MSCALE_X] = srcVals[Matrix.MSCALE_X];
        dstVals[Matrix.MSKEW_X] = srcVals[Matrix.MSKEW_X];
        dstVals[Matrix.MTRANS_X] = srcVals[Matrix.MTRANS_X];
        dstVals[Matrix.MSKEW_Y] = srcVals[Matrix.MSKEW_Y];
        dstVals[Matrix.MSCALE_Y] = srcVals[Matrix.MSCALE_Y];
        dstVals[Matrix.MTRANS_Y] = srcVals[Matrix.MTRANS_Y];
        dstVals[Matrix.MPERSP_0] = srcVals[Matrix.MPERSP_0];
        dstVals[Matrix.MPERSP_1] = srcVals[Matrix.MPERSP_1];
        dstVals[Matrix.MPERSP_2] = srcVals[Matrix.MPERSP_2];

        dstMatrix.setValues(dstVals);
        dstChart.getViewPortHandler().refresh(dstMatrix, dstChart, true);
    }
}
 
Example #18
Source File: RecordingFragment.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shows no weather data message.
 */
private void showNoWeatherData() {
    float textSize = WeatherUtils.convertDpToPixel(getResources(), 12);
    tempChart.setNoDataText(getString(R.string.no_weather_data_available));
    tempChart.getPaint(Chart.PAINT_INFO).setTextSize(textSize);
    rainChart.setNoDataText(getString(R.string.no_weather_data_available));
    rainChart.getPaint(Chart.PAINT_INFO).setTextSize(textSize);
    windChart.setNoDataText(getString(R.string.no_weather_data_available));
    windChart.getPaint(Chart.PAINT_INFO).setTextSize(textSize);
}
 
Example #19
Source File: CombinedChartRenderer.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    Chart chart = mChart.get();
    if (chart == null) return;

    for (DataRenderer renderer : mRenderers) {
        ChartData data = null;

        if (renderer instanceof BarChartRenderer)
            data = ((BarChartRenderer)renderer).mChart.getBarData();
        else if (renderer instanceof LineChartRenderer)
            data = ((LineChartRenderer)renderer).mChart.getLineData();
        else if (renderer instanceof CandleStickChartRenderer)
            data = ((CandleStickChartRenderer)renderer).mChart.getCandleData();
        else if (renderer instanceof ScatterChartRenderer)
            data = ((ScatterChartRenderer)renderer).mChart.getScatterData();
        else if (renderer instanceof BubbleChartRenderer)
            data = ((BubbleChartRenderer)renderer).mChart.getBubbleData();

        int dataIndex = data == null ? -1
                : ((CombinedData)chart.getData()).getAllData().indexOf(data);

        mHighlightBuffer.clear();

        for (Highlight h : indices) {
            if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1)
                mHighlightBuffer.add(h);
        }

        renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()]));
    }
}
 
Example #20
Source File: DateGraphMarkerView.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public DateGraphMarkerView(Context context, int layoutResource, Chart chart) {
    super(context, layoutResource);

    // find your layout components
    tvContent = findViewById(R.id.tvContent);
    tvDate = findViewById(R.id.tvDate);
    uiScreenWidth = getResources().getDisplayMetrics().widthPixels;
    lineChart = chart;
}
 
Example #21
Source File: CombinedChartRenderer.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    Chart chart = mChart.get();
    if (chart == null) return;

    for (DataRenderer renderer : mRenderers) {
        ChartData data = null;

        if (renderer instanceof BarChartRenderer)
            data = ((BarChartRenderer)renderer).mChart.getBarData();
        else if (renderer instanceof LineChartRenderer)
            data = ((LineChartRenderer)renderer).mChart.getLineData();
        else if (renderer instanceof CandleStickChartRenderer)
            data = ((CandleStickChartRenderer)renderer).mChart.getCandleData();
        else if (renderer instanceof ScatterChartRenderer)
            data = ((ScatterChartRenderer)renderer).mChart.getScatterData();
        else if (renderer instanceof BubbleChartRenderer)
            data = ((BubbleChartRenderer)renderer).mChart.getBubbleData();

        int dataIndex = data == null
                ? -1
                : ((CombinedData)chart.getData()).getAllData().indexOf(data);

        ArrayList<Highlight> dataIndices = new ArrayList<>();
        for (Highlight h : indices) {
            if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1)
                dataIndices.add(h);
        }

        renderer.drawHighlighted(c, dataIndices.toArray(new Highlight[dataIndices.size()]));

    }
}
 
Example #22
Source File: MarkerImage.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {

    MPPointF offset = getOffset();
    mOffset2.x = offset.x;
    mOffset2.y = offset.y;

    Chart chart = getChartView();

    float width = mSize.width;
    float height = mSize.height;

    if (width == 0.f && mDrawable != null) {
        width = mDrawable.getIntrinsicWidth();
    }
    if (height == 0.f && mDrawable != null) {
        height = mDrawable.getIntrinsicHeight();
    }

    if (posX + mOffset2.x < 0) {
        mOffset2.x = - posX;
    } else if (chart != null && posX + width + mOffset2.x > chart.getWidth()) {
        mOffset2.x = chart.getWidth() - posX - width;
    }

    if (posY + mOffset2.y < 0) {
        mOffset2.y = - posY;
    } else if (chart != null && posY + height + mOffset2.y > chart.getHeight()) {
        mOffset2.y = chart.getHeight() - posY - height;
    }

    return mOffset2;
}
 
Example #23
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 #24
Source File: ChartInfoView.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    setVisibility(GONE);
    if (mLineCharts != null) {
        for (Chart chart : mLineCharts) {
            chart.highlightValue(null);
        }
    }
}
 
Example #25
Source File: InfoViewListener.java    From android-kline with Apache License 2.0 5 votes vote down vote up
public InfoViewListener(Context context, double lastClose, List<HisData> list, ChartInfoView infoView, Chart... otherChart) {
    mWidth = DisplayUtils.getWidthHeight(context)[0];
    mLastClose = lastClose;
    mList = list;
    mInfoView = infoView;
    mOtherChart = otherChart;
}
 
Example #26
Source File: DrawChartActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/** callback when a DataSet has been drawn (when lifting the finger) */
@Override
public void onDrawFinished(DataSet<?> dataSet) {
    Log.i(Chart.LOG_TAG, "DataSet drawn. " + dataSet.toSimpleString());

    // prepare the legend again
    mChart.getLegendRenderer().computeLegend(mChart.getData());
}
 
Example #27
Source File: AppCombinedChartRenderer.java    From android-kline with Apache License 2.0 5 votes vote down vote up
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    Chart chart = mChart.get();
    if (chart == null) return;

    for (DataRenderer renderer : mRenderers) {
        ChartData data = null;

        if (renderer instanceof BarChartRenderer)
            data = ((BarChartRenderer)renderer).mChart.getBarData();
        else if (renderer instanceof AppLineChartRenderer)
            data = ((AppLineChartRenderer)renderer).mChart.getLineData();
        else if (renderer instanceof CandleStickChartRenderer)
            data = ((CandleStickChartRenderer)renderer).mChart.getCandleData();
        else if (renderer instanceof ScatterChartRenderer)
            data = ((ScatterChartRenderer)renderer).mChart.getScatterData();
        else if (renderer instanceof BubbleChartRenderer)
            data = ((BubbleChartRenderer)renderer).mChart.getBubbleData();

        int dataIndex = data == null ? -1
                : ((CombinedData)chart.getData()).getAllData().indexOf(data);

        mHighlightBuffer.clear();

        for (Highlight h : indices) {
            if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1)
                mHighlightBuffer.add(h);
        }

        renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()]));
    }
}
 
Example #28
Source File: ChartSettings.java    From BrainPhaser with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Formats the text which will be shown when no challenges exist
 *
 * @param chart the chart whose no data text will be formatted
 */
public void applyNoDataSettings(Chart chart) {
    chart.setNoDataText(mApplication.getString(R.string.chart_no_data_text));
    Paint p = chart.getPaint(Chart.PAINT_INFO);
    p.setTextSize(NO_DATA_TEXT_SIZE);

    Context appContext = mApplication.getApplicationContext();

    p.setColor(ContextCompat.getColor(appContext, android.R.color.tertiary_text_light));
}
 
Example #29
Source File: DateTimeMarkerView.java    From OpenLibre with GNU General Public License v3.0 5 votes vote down vote up
@Override
public MPPointF getOffsetForDrawingAtPoint(float posX, float posY) {
    MPPointF offset = getOffset();

    offset.x = max(offset.x, - posX);
    offset.y = max(offset.y, - posY);

    Chart chart = getChartView();
    if (chart != null) {
        offset.x = min(offset.x, chart.getWidth() - posX - getWidth());
        offset.y = min(offset.y, chart.getHeight() - posY - getHeight());
    }

    return offset;
}
 
Example #30
Source File: CoupleChartGestureListener.java    From android-kline with Apache License 2.0 5 votes vote down vote up
public void syncCharts() {
    Matrix srcMatrix;
    float[] srcVals = new float[9];
    Matrix dstMatrix;
    float[] dstVals = new float[9];
    // get src chart translation matrix:
    srcMatrix = srcChart.getViewPortHandler().getMatrixTouch();
    srcMatrix.getValues(srcVals);
    // apply X axis scaling and position to dst charts:
    for (Chart dstChart : dstCharts) {
        dstMatrix = dstChart.getViewPortHandler().getMatrixTouch();
        dstMatrix.getValues(dstVals);

        dstVals[Matrix.MSCALE_X] = srcVals[Matrix.MSCALE_X];
        dstVals[Matrix.MSKEW_X] = srcVals[Matrix.MSKEW_X];
        dstVals[Matrix.MTRANS_X] = srcVals[Matrix.MTRANS_X];
        dstVals[Matrix.MSKEW_Y] = srcVals[Matrix.MSKEW_Y];
        dstVals[Matrix.MSCALE_Y] = srcVals[Matrix.MSCALE_Y];
        dstVals[Matrix.MTRANS_Y] = srcVals[Matrix.MTRANS_Y];
        dstVals[Matrix.MPERSP_0] = srcVals[Matrix.MPERSP_0];
        dstVals[Matrix.MPERSP_1] = srcVals[Matrix.MPERSP_1];
        dstVals[Matrix.MPERSP_2] = srcVals[Matrix.MPERSP_2];

        dstMatrix.setValues(dstVals);
        dstChart.getViewPortHandler().refresh(dstMatrix, dstChart, true);
    }
}