com.github.mikephil.charting.components.YAxis Java Examples

The following examples show how to use com.github.mikephil.charting.components.YAxis. 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: CombinedChartKline.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void init() {
    super.init();

    mLeftAxisTransformer = new MyTransformer(mViewPortHandler);
    mRightAxisTransformer = new MyTransformer(mViewPortHandler);

    mXAxis = new MyXAxis();
    mXAxisRenderer = new XAxisRendererKline(mViewPortHandler, (MyXAxis) mXAxis, mLeftAxisTransformer, this);

    mAxisLeft = new MyYAxis(YAxis.AxisDependency.LEFT);
    mAxisRendererLeft = new YAxisRendererKline(mViewPortHandler, (MyYAxis) mAxisLeft, mLeftAxisTransformer);

    mAxisRight = new MyYAxis(YAxis.AxisDependency.RIGHT);
    mAxisRendererRight = new YAxisRendererKline(mViewPortHandler, (MyYAxis) mAxisRight, mRightAxisTransformer);

    mLegend = new MyLegend();
    mLegendRenderer = new MyLegendRenderer(mViewPortHandler, (MyLegend) mLegend);

    mRenderer = new CombinedChartKlineRenderer(this, mAnimator, mViewPortHandler);
}
 
Example #2
Source File: KLineDataManage.java    From StockChart-MPAndroidChart with MIT License 6 votes vote down vote up
private LineDataSet setALine(ColorType colorType, ArrayList<Entry> lineEntries, String label, boolean highlightEnable) {
    LineDataSet lineDataSetMa = new LineDataSet(lineEntries, label);
    lineDataSetMa.setDrawHorizontalHighlightIndicator(false);
    lineDataSetMa.setHighlightEnabled(highlightEnable);//是否画高亮十字线
    lineDataSetMa.setHighLightColor(ContextCompat.getColor(mContext, R.color.highLight_Color));//高亮十字线颜色
    lineDataSetMa.setDrawValues(false);//是否画出每个蜡烛线的数值
    if (colorType == ColorType.blue) {
        lineDataSetMa.setColor(ContextCompat.getColor(mContext, R.color.ma5));
    } else if (colorType == ColorType.yellow) {
        lineDataSetMa.setColor(ContextCompat.getColor(mContext, R.color.ma10));
    } else if (colorType == ColorType.purple) {
        lineDataSetMa.setColor(ContextCompat.getColor(mContext, R.color.ma20));
    }
    lineDataSetMa.setLineWidth(0.6f);
    lineDataSetMa.setDrawCircles(false);
    lineDataSetMa.setAxisDependency(YAxis.AxisDependency.LEFT);
    return lineDataSetMa;
}
 
Example #3
Source File: HorizontalBarHighlighter.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the base y-value to the corresponding x-touch value in pixels.
 * 
 * @param y
 * @return
 */
@Override
protected float getBase(float y) {

	// create an array of the touch-point
	float[] pts = new float[2];
	pts[1] = y;

	// take any transformer to determine the x-axis value
	mChart.getTransformer(YAxis.AxisDependency.LEFT).pixelsToValue(pts);
	float yVal = pts[1];

	int setCount = mChart.getBarData().getDataSetCount();

	// calculate how often the group-space appears
	int steps = (int) ((float) yVal / ((float) setCount + mChart.getBarData().getGroupSpace()));

	float groupSpaceSum = mChart.getBarData().getGroupSpace() * (float) steps;

	float baseNoSpace = (float) yVal - groupSpaceSum;
	return baseNoSpace;
}
 
Example #4
Source File: YAxisRenderer.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
public YAxisRenderer(ViewPortHandler viewPortHandler, YAxis yAxis, Transformer trans) {
    super(viewPortHandler, trans, yAxis);

    this.mYAxis = yAxis;

    if(mViewPortHandler != null) {

        mAxisLabelPaint.setColor(Color.BLACK);
        mAxisLabelPaint.setTextSize(Utils.convertDpToPixel(10f));

        mZeroLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mZeroLinePaint.setColor(Color.GRAY);
        mZeroLinePaint.setStrokeWidth(1f);
        mZeroLinePaint.setStyle(Paint.Style.STROKE);
    }
}
 
Example #5
Source File: KlineFragment.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * date: 2019/2/22
 * author: chenli
 * description: 产生持仓量数据集
 */
private LineDataSet generateLineDataSet(List<Entry> entries, int color, String label, boolean isHighlight, YAxis.AxisDependency axisDependency) {
    LineDataSet set = new LineDataSet(entries, label);
    set.setColor(color);
    set.setLineWidth(0.7f);
    set.setDrawCircles(false);
    set.setDrawCircleHole(false);
    set.setDrawValues(false);
    set.setAxisDependency(axisDependency);
    if (isHighlight) {
        set.setHighlightLineWidth(0.7f);
        set.setHighLightColor(color);
    } else {
        set.setHighlightEnabled(false);
    }
    return set;
}
 
Example #6
Source File: CurrentDayFragment.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * date: 6/1/18
 * author: chenli
 * description: 初始化时产生分时图数据集
 */
private LineDataSet generateLineDataSet(List<Entry> entries, int color, String label, boolean isHighlight, YAxis.AxisDependency axisDependency) {
    LineDataSet set = new LineDataSet(entries, label);
    set.setColor(color);
    set.setLineWidth(0.7f);
    set.setDrawCircles(false);
    set.setDrawCircleHole(false);
    set.setDrawValues(false);
    set.setAxisDependency(axisDependency);
    if (isHighlight) {
        refreshYAxisRange(set);
        set.setHighlightLineWidth(0.7f);
        set.setHighLightColor(mHighlightColor);
    } else {
        set.setHighlightEnabled(false);
    }
    return set;
}
 
Example #7
Source File: CoupleChartGestureListener.java    From shinny-futures-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onChartScale(MotionEvent me, float scaleX, float scaleY) {
    float[] mBodyBuffers = new float[4];
    mBodyBuffers[0] = 0f;
    mBodyBuffers[1] = 0f;
    mBodyBuffers[2] = 0.8f;
    mBodyBuffers[3] = 0f;
    Transformer transformer = srcChart.getTransformer(YAxis.AxisDependency.LEFT);
    transformer.pointValuesToPixel(mBodyBuffers);
    float px = mBodyBuffers[2] - mBodyBuffers[0];
    int width = ScreenUtils.px2dp(BaseApplication.getContext(), px);
    Identify identify = new Identify();
    identify.set(AMP_USER_KLINE_WIDTH, width);
    Amplitude.getInstance().identify(identify);

    float[] srcVals = new float[9];
    Matrix srcMatrix = srcChart.getViewPortHandler().getMatrixTouch();
    srcMatrix.getValues(srcVals);
    SPUtils.putAndApply(BaseApplication.getContext(), MarketConstants.SCALE_X, srcVals[0]);
    syncCharts();
}
 
Example #8
Source File: BarLineChartBaseManager.java    From react-native-mp-android-chart with MIT License 6 votes vote down vote up
@ReactProp(name = "zoom")
public void setZoom(BarLineChartBase chart, ReadableMap propMap) {
    if (BridgeUtils.validate(propMap, ReadableType.Number, "scaleX") &&
        BridgeUtils.validate(propMap, ReadableType.Number, "scaleY") &&
        BridgeUtils.validate(propMap, ReadableType.Number, "xValue") &&
        BridgeUtils.validate(propMap, ReadableType.Number, "yValue")) {

        YAxis.AxisDependency axisDependency = YAxis.AxisDependency.LEFT;
        if (propMap.hasKey("axisDependency") &&
                propMap.getString("axisDependency").equalsIgnoreCase("RIGHT")) {
            axisDependency = YAxis.AxisDependency.RIGHT;
        }

        chart.zoom(
                (float) propMap.getDouble("scaleX"),
                (float) propMap.getDouble("scaleY"),
                (float) propMap.getDouble("xValue"),
                (float) propMap.getDouble("yValue"),
                axisDependency
        );
    }
}
 
Example #9
Source File: CombinedChartActivity.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
private BarData generateBarData() {

        ArrayList<BarEntry> entries1 = new ArrayList<>();
        ArrayList<BarEntry> entries2 = new ArrayList<>();

        for (int index = 0; index < count; index++) {
            entries1.add(new BarEntry(0, getRandom(25, 25)));

            // stacked
            entries2.add(new BarEntry(0, new float[]{getRandom(13, 12), getRandom(13, 12)}));
        }

        BarDataSet set1 = new BarDataSet(entries1, "Bar 1");
        set1.setColor(Color.rgb(60, 220, 78));
        set1.setValueTextColor(Color.rgb(60, 220, 78));
        set1.setValueTextSize(10f);
        set1.setAxisDependency(YAxis.AxisDependency.LEFT);

        BarDataSet set2 = new BarDataSet(entries2, "");
        set2.setStackLabels(new String[]{"Stack 1", "Stack 2"});
        set2.setColors(Color.rgb(61, 165, 255), Color.rgb(23, 197, 255));
        set2.setValueTextColor(Color.rgb(61, 165, 255));
        set2.setValueTextSize(10f);
        set2.setAxisDependency(YAxis.AxisDependency.LEFT);

        float groupSpace = 0.06f;
        float barSpace = 0.02f; // x2 dataset
        float barWidth = 0.45f; // x2 dataset
        // (0.45 + 0.02) * 2 + 0.06 = 1.00 -> interval per "group"

        BarData d = new BarData(set1, set2);
        d.setBarWidth(barWidth);

        // make this BarData object grouped
        d.groupBars(0, groupSpace, barSpace); // start at x = 0

        return d;
    }
 
Example #10
Source File: FragmentTimeBarChart.java    From fingen with Apache License 2.0 5 votes vote down vote up
private void setupBarChart() {
    mBarChart.setDrawBarShadow(false);
    mBarChart.setDrawValueAboveBar(true);
    mBarChart.setDescription("");
    mBarChart.setMaxVisibleValueCount(Integer.MAX_VALUE);
    mBarChart.setPinchZoom(false);
    mBarChart.setDrawGridBackground(false);
    mBarChart.setOnChartValueSelectedListener(this);
    mBarChart.setHighlightPerDragEnabled(false);

    int textColor = ColorUtils.getTextColor(getActivity());

    XAxis xl = mBarChart.getXAxis();
    xl.setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);
    xl.setDrawAxisLine(true);
    xl.setDrawGridLines(true);
    xl.setGridLineWidth(0.3f);
    xl.setTextColor(textColor);

    YAxis yl = mBarChart.getAxisLeft();
    yl.setDrawAxisLine(true);
    yl.setDrawGridLines(true);
    yl.setGridLineWidth(0.3f);
    yl.setAxisMinValue(0f);
    yl.setTextColor(textColor);

    YAxis yr = mBarChart.getAxisRight();
    yr.setDrawAxisLine(true);
    yr.setDrawGridLines(false);
    yr.setAxisMinValue(0f);
    yr.setTextColor(textColor);

    mBarChart.setXAxisRenderer(new FgHorizontalBarChartRenderer(getActivity(), mBarChart.getViewPortHandler(),
            mBarChart.getXAxis(), mBarChart.getTransformer(YAxis.AxisDependency.LEFT), mBarChart));
    mBarChart.getLegend().setEnabled(false);
}
 
Example #11
Source File: TempChart.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * By calling setData initializes the rest of the view
 * @param data the chart data
 */
@Override
public void setData(LineData data) {
    super.setData(data);
    setOnChartValueSelectedListener(this);
    setDescription("");
    setNoDataTextDescription("No chart data");
    setTouchEnabled(true);
    setScaleEnabled(true);
    setDragEnabled(true);
    setDrawGridBackground(true);
    setPinchZoom(true);

    Legend legend = getLegend();
    legend.setForm(Legend.LegendForm.CIRCLE);
    legend.setWordWrapEnabled(true);

    XAxis xAxis = getXAxis();
    xAxis.setAvoidFirstLastClipping(true);
    xAxis.setPosition(XAxis.XAxisPosition.TOP);

    YAxis yAxisLeft = getAxisLeft();
    yAxisLeft.setAxisMinValue(0);

    YAxis yAxisRight = getAxisRight();
    yAxisRight.setEnabled(false);
}
 
Example #12
Source File: RideDetailActivity.java    From android-ponewheel with MIT License 5 votes vote down vote up
private void setupDatasetWithDefaultValues(LineDataSet dataSet) {
    dataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
    dataSet.setColor(ColorTemplate.getHoloBlue());
    dataSet.setValueTextColor(ColorTemplate.getHoloBlue());
    dataSet.setLineWidth(1.5f);
    dataSet.setDrawCircles(false);
    dataSet.setDrawValues(false);
    dataSet.setFillAlpha(65);
    dataSet.setFillColor(ColorTemplate.getHoloBlue());
    dataSet.setHighLightColor(Color.rgb(244, 117, 117));
    dataSet.setDrawCircleHole(false);
}
 
Example #13
Source File: Utils.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
private static LineDataSet initDownloadSet(Context context) {
    LineDataSet set = new LineDataSet(null, context.getString(R.string.downloadSpeed));
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    set.setLineWidth(2f);
    set.setColor(ContextCompat.getColor(context, R.color.downloadColor));
    set.setDrawCircles(false);
    set.setDrawValues(false);
    set.setMode(LineDataSet.Mode.CUBIC_BEZIER);
    set.setDrawFilled(false);
    return set;
}
 
Example #14
Source File: YAxisRendererCurrentDay.java    From shinny-futures-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void renderAxisLabels(Canvas c) {
    if (!mYAxis.isEnabled() || !mYAxis.isDrawLabelsEnabled())
        return;

    float[] positions = getTransformedPositions();

    mAxisLabelPaint.setTypeface(mYAxis.getTypeface());
    mAxisLabelPaint.setTextSize(mYAxis.getTextSize());
    mAxisLabelPaint.setColor(mYAxis.getTextColor());

    float yoffset = Utils.calcTextHeight(mAxisLabelPaint, "A") / 2.5f + mYAxis.getYOffset();

    YAxis.AxisDependency dependency = mYAxis.getAxisDependency();
    YAxis.YAxisLabelPosition labelPosition = mYAxis.getLabelPosition();

    float xPos;

    if (dependency == YAxis.AxisDependency.LEFT) {

        if (labelPosition == YAxis.YAxisLabelPosition.OUTSIDE_CHART) {
            mAxisLabelPaint.setTextAlign(Paint.Align.RIGHT);
        } else {
            mAxisLabelPaint.setTextAlign(Paint.Align.LEFT);
        }
        xPos = mViewPortHandler.offsetLeft();


    } else {

        if (labelPosition == YAxis.YAxisLabelPosition.OUTSIDE_CHART) {
            mAxisLabelPaint.setTextAlign(Paint.Align.LEFT);
        } else {
            mAxisLabelPaint.setTextAlign(Paint.Align.RIGHT);
        }
        xPos = mViewPortHandler.contentRight();
    }

    drawYLabels(c, xPos, positions, yoffset);
}
 
Example #15
Source File: AppCombinedChart.java    From android-kline with Apache License 2.0 5 votes vote down vote up
/**
 * 重写这两个方法,为了让开盘价和涨跌幅剧中显示
 */
@Override
protected void calcMinMax() {

    mXAxis.calculate(mData.getXMin(), mData.getXMax());

    if (mYCenter == 0) {
        // calculate axis range (min / max) according to provided data
        mAxisLeft.calculate(mData.getYMin(YAxis.AxisDependency.LEFT), mData.getYMax(YAxis.AxisDependency.LEFT));
        mAxisRight.calculate(mData.getYMin(YAxis.AxisDependency.RIGHT), mData.getYMax(YAxis.AxisDependency
                .RIGHT));
    } else {
        float yLMin = mData.getYMin(YAxis.AxisDependency.LEFT);
        float yLMax = mData.getYMax(YAxis.AxisDependency.LEFT);
        float interval = (float) Math.max(Math.abs(mYCenter - yLMax), Math.abs(mYCenter - yLMin));
        yLMax = (float) Math.max(yLMax, (mYCenter + interval));
        yLMin = (float) Math.min(yLMin, (mYCenter - interval));
        mAxisLeft.calculate(yLMin, yLMax);

        float yRMin = mData.getYMin(YAxis.AxisDependency.RIGHT);
        float yRMax = mData.getYMax(YAxis.AxisDependency.RIGHT);
        float rinterval = (float) Math.max(Math.abs(mYCenter - yRMax), Math.abs(mYCenter - yRMin));
        yRMax = (float) Math.max(yRMax, (mYCenter + rinterval));
        yRMin = (float) Math.min(yRMin, (mYCenter - rinterval));
        mAxisRight.calculate(yRMin, yRMax);
    }
}
 
Example #16
Source File: HorizontalBarHighlighter.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
protected int getXIndex(float x) {

	if (!mChart.getBarData().isGrouped()) {

		// create an array of the touch-point
		float[] pts = new float[2];
		pts[1] = x;

		// take any transformer to determine the x-axis value
		mChart.getTransformer(YAxis.AxisDependency.LEFT).pixelsToValue(pts);

		return (int) Math.round(pts[1]);
	} else {

		float baseNoSpace = getBase(x);

		int setCount = mChart.getBarData().getDataSetCount();
		int xIndex = (int) baseNoSpace / setCount;

		int valCount = mChart.getData().getXValCount();

		if (xIndex < 0)
			xIndex = 0;
		else if (xIndex >= valCount)
			xIndex = valCount - 1;

		return xIndex;
	}
}
 
Example #17
Source File: CalibrationLinearityActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private void initLine() {
    LineChart lineChart = getLineChart();
    if(lineChart == null) {
        return;
    }
    lineChart.setDescription("");

    lineChart.setDrawGridBackground(false);

    // enable scaling and dragging

    Legend l = lineChart.getLegend();
    l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
    l.setTextColor(Color.WHITE);

    YAxis yl = lineChart.getAxisLeft();
    yl.setTextColor(Color.WHITE);
    yl.setGridColor(Color.WHITE);
    lineChart.getAxisRight().setEnabled(false);

    XAxis xl = lineChart.getXAxis();
    xl.setDrawGridLines(false);
    xl.setTextColor(Color.WHITE);
    xl.setGridColor(Color.WHITE);
    xl.setPosition(XAxis.XAxisPosition.BOTTOM);
    xl.setDrawAxisLine(true);
    xl.setLabelRotationAngle(-90);
    xl.setDrawLabels(true);
    xl.setLabelsToSkip(0);
}
 
Example #18
Source File: HorizontalBarHighlighter.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
protected int getXIndex(float x) {

	if (!mChart.getBarData().isGrouped()) {

		// create an array of the touch-point
		float[] pts = new float[2];
		pts[1] = x;

		// take any transformer to determine the x-axis value
		mChart.getTransformer(YAxis.AxisDependency.LEFT).pixelsToValue(pts);

		return (int) Math.round(pts[1]);
	} else {

		float baseNoSpace = getBase(x);

		int setCount = mChart.getBarData().getDataSetCount();
		int xIndex = (int) baseNoSpace / setCount;

		int valCount = mChart.getData().getXValCount();

		if (xIndex < 0)
			xIndex = 0;
		else if (xIndex >= valCount)
			xIndex = valCount - 1;

		return xIndex;
	}
}
 
Example #19
Source File: CustomPercentFormatter.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getFormattedValue(float value, YAxis yAxis) {
    if(value > 0.00001) {
        return super.getFormattedValue(value, yAxis);
    } else {
        return "";
    }
}
 
Example #20
Source File: RadarChart.java    From iMoney with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    super.init();

    mYAxis = new YAxis(AxisDependency.LEFT);
    mXAxis = new XAxis();
    mXAxis.setSpaceBetweenLabels(0);

    mWebLineWidth = Utils.convertDpToPixel(1.5f);
    mInnerWebLineWidth = Utils.convertDpToPixel(0.75f);

    mRenderer = new RadarChartRenderer(this, mAnimator, mViewPortHandler);
    mYAxisRenderer = new YAxisRendererRadarChart(mViewPortHandler, mYAxis, this);
    mXAxisRenderer = new XAxisRendererRadarChart(mViewPortHandler, mXAxis, this);
}
 
Example #21
Source File: AnimatedZoomJob.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
public static AnimatedZoomJob getInstance(ViewPortHandler viewPortHandler, View v, Transformer trans, YAxis axis, float xAxisRange, float scaleX, float scaleY, float xOrigin, float yOrigin, float zoomCenterX, float zoomCenterY, float zoomOriginX, float zoomOriginY, long duration) {
    AnimatedZoomJob result = pool.get();
    result.mViewPortHandler = viewPortHandler;
    result.xValue = scaleX;
    result.yValue = scaleY;
    result.mTrans = trans;
    result.view = v;
    result.xOrigin = xOrigin;
    result.yOrigin = yOrigin;
    result.yAxis = axis;
    result.xAxisRange = xAxisRange;
    result.resetAnimator();
    result.animator.setDuration(duration);
    return result;
}
 
Example #22
Source File: BarChart.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Override
protected void calcMinMax() {

    if (mFitBars) {
        mXAxis.calculate(mData.getXMin() - mData.getBarWidth() / 2f, mData.getXMax() + mData.getBarWidth() / 2f);
    } else {
        mXAxis.calculate(mData.getXMin(), mData.getXMax());
    }

    // calculate axis range (min / max) according to provided data
    mAxisLeft.calculate(mData.getYMin(YAxis.AxisDependency.LEFT), mData.getYMax(YAxis.AxisDependency.LEFT));
    mAxisRight.calculate(mData.getYMin(YAxis.AxisDependency.RIGHT), mData.getYMax(YAxis.AxisDependency
            .RIGHT));
}
 
Example #23
Source File: BarChartFrag.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_simple_bar, container, false);

    // create a new chart object
    chart = new BarChart(getActivity());
    chart.getDescription().setEnabled(false);
    chart.setOnChartGestureListener(this);

    MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
    mv.setChartView(chart); // For bounds control
    chart.setMarker(mv);

    chart.setDrawGridBackground(false);
    chart.setDrawBarShadow(false);

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

    chart.setData(generateBarData(1, 20000, 12));

    Legend l = chart.getLegend();
    l.setTypeface(tf);

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setTypeface(tf);
    leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

    chart.getAxisRight().setEnabled(false);

    XAxis xAxis = chart.getXAxis();
    xAxis.setEnabled(false);

    // programmatically add the chart
    FrameLayout parent = v.findViewById(R.id.parentLayout);
    parent.addView(chart);

    return v;
}
 
Example #24
Source File: TestSuiteFragment.java    From SQLite-Performance with The Unlicense 5 votes vote down vote up
private void setupYAxes(BarLineChartBase chart) {
    YAxis y = chart.getAxisLeft();
    y.setDrawZeroLine(true);
    y.setDrawLabels(false);
    y.setDrawGridLines(false);
    y.setDrawAxisLine(false);
    y.setAxisMinimum(0);
    y = chart.getAxisRight();
    y.setDrawZeroLine(true);
    y.setDrawLabels(false);
    y.setDrawGridLines(false);
    y.setDrawAxisLine(false);
    y.setAxisMinimum(0);
}
 
Example #25
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 #26
Source File: CombinedChartActivity.java    From Stayfit with Apache License 2.0 5 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_combined);

        mChart = (CombinedChart) findViewById(R.id.chart1);
        mChart.setDescription("");
        mChart.setBackgroundColor(Color.WHITE);
        mChart.setDrawGridBackground(false);
        mChart.setDrawBarShadow(false);
        
        // draw bars behind lines
        mChart.setDrawOrder(new DrawOrder[] {
                DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER
        });

        YAxis rightAxis = mChart.getAxisRight();
        rightAxis.setDrawGridLines(false);
        rightAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)

        YAxis leftAxis = mChart.getAxisLeft();
        leftAxis.setDrawGridLines(false);
        leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)

        XAxis xAxis = mChart.getXAxis();
        xAxis.setPosition(XAxisPosition.BOTH_SIDED);

        CombinedData data = new CombinedData(mMonths);

        data.setData(generateLineData());
        data.setData(generateBarData());
//        data.setData(generateBubbleData());
//         data.setData(generateScatterData());
//         data.setData(generateCandleData());

        mChart.setData(data);
        mChart.invalidate();
    }
 
Example #27
Source File: DrawChartActivity.java    From StockChart-MPAndroidChart with MIT License 5 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_draw_chart);

    setTitle("DrawChartActivity");

    chart = findViewById(R.id.chart1);

    // listener for selecting and drawing
    chart.setOnChartValueSelectedListener(this);
    chart.setOnDrawListener(this);

    // if disabled, drawn data sets with the finger will not be automatically
    // finished
    // chart.setAutoFinish(true);
    chart.setDrawGridBackground(false);

    // add dummy-data to the chart
    initWithDummyData();

    XAxis xl = chart.getXAxis();
    xl.setTypeface(tfRegular);
    xl.setAvoidFirstLastClipping(true);

    YAxis yl = chart.getAxisLeft();
    yl.setTypeface(tfRegular);

    chart.getLegend().setEnabled(false);

    // chart.setYRange(-40f, 40f, true);
    // call this to reset the changed y-range
    // chart.resetYRange(true);
}
 
Example #28
Source File: BarLineChartBase.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
@Override
protected void init() {
    super.init();

    mAxisLeft = new YAxis(AxisDependency.LEFT);
    mAxisRight = new YAxis(AxisDependency.RIGHT);

    mLeftAxisTransformer = new Transformer(mViewPortHandler);
    mRightAxisTransformer = new Transformer(mViewPortHandler);

    mAxisRendererLeft = new YAxisRenderer(mViewPortHandler, mAxisLeft, mLeftAxisTransformer);
    mAxisRendererRight = new YAxisRenderer(mViewPortHandler, mAxisRight, mRightAxisTransformer);

    mXAxisRenderer = new XAxisRenderer(mViewPortHandler, mXAxis, mLeftAxisTransformer);

    setHighlighter(new ChartHighlighter(this));

    mChartTouchListener = new BarLineChartTouchListener(this, mViewPortHandler.getMatrixTouch(), 3f);

    mGridBackgroundPaint = new Paint();
    mGridBackgroundPaint.setStyle(Style.FILL);
    // mGridBackgroundPaint.setColor(Color.WHITE);
    mGridBackgroundPaint.setColor(Color.rgb(240, 240, 240)); // light
    // grey

    mBorderPaint = new Paint();
    mBorderPaint.setStyle(Style.STROKE);
    mBorderPaint.setColor(Color.BLACK);
    mBorderPaint.setStrokeWidth(Utils.convertDpToPixel(1f));
}
 
Example #29
Source File: BarChartHelper.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
public BarChart generateBarChartConfig(BarChart barChart) {
    XAxis xAxis = barChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); //定制X轴是在图表上方还是下方。
    xAxis.setDrawAxisLine(true);
    xAxis.setDrawGridLines(false);
    xAxis.setGranularity(1f);//放大的时候X值不增多


    YAxis yAxisRight = barChart.getAxisRight();
    yAxisRight.setEnabled(false);
    YAxis yAxisLeft = barChart.getAxisLeft();
    yAxisLeft.setAxisMinimum(0);

    barChart.setDrawBarShadow(false);
    barChart.setPinchZoom(true);
    barChart.setFitBars(true);
    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    barChart.setMaxVisibleValueCount(60);

    barChart.setDrawValueAboveBar(true);

    barChart.getDescription().setEnabled(false);
    barChart.setNoDataText("无数据");

    Legend l = barChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    //设置单方向和双方向缩放 true x,y方向可以同时控制,false只能控制x方向的缩小放大或者Y方向的缩小放大
    l.setDrawInside(false);
    l.setFormSize(8f);
    l.setXEntrySpace(4f);
    return barChart;
}
 
Example #30
Source File: CandleStickChartActivity.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_candlechart);

        setTitle("CandleStickChartActivity");

        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.setBackgroundColor(Color.WHITE);

        chart.getDescription().setEnabled(false);

        // if more than 60 entries are displayed in the chart, no values will be
        // drawn
        chart.setMaxVisibleValueCount(60);

        // 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.setDrawGridLines(false);

        YAxis leftAxis = chart.getAxisLeft();
//        leftAxis.setEnabled(false);
        leftAxis.setLabelCount(7, false);
        leftAxis.setDrawGridLines(false);
        leftAxis.setDrawAxisLine(false);

        YAxis rightAxis = chart.getAxisRight();
        rightAxis.setEnabled(false);
//        rightAxis.setStartAtZero(false);

        // setting data
        seekBarX.setProgress(40);
        seekBarY.setProgress(100);

        chart.getLegend().setEnabled(false);
    }