Java Code Examples for com.github.mikephil.charting.components.Legend#setYOffset()

The following examples show how to use com.github.mikephil.charting.components.Legend#setYOffset() . 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: ScatterChartFrag.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_scatter, container, false);

    chart = v.findViewById(R.id.scatterChart1);
    chart.getDescription().setEnabled(false);

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

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

    chart.setDrawGridBackground(false);
    chart.setData(generateScatterData(6, 10000, 200));

    XAxis xAxis = chart.getXAxis();
    xAxis.setEnabled(true);
    xAxis.setPosition(XAxisPosition.BOTTOM);

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setTypeface(tf);

    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setTypeface(tf);
    rightAxis.setDrawGridLines(false);

    Legend l = chart.getLegend();
    l.setWordWrapEnabled(true);
    l.setTypeface(tf);
    l.setFormSize(14f);
    l.setTextSize(9f);

    // increase the space between legend & bottom and legend & content
    l.setYOffset(13f);
    chart.setExtraBottomOffset(16f);

    return v;
}
 
Example 2
Source File: ScatterChartFrag.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_simple_scatter, container, false);
    
    mChart = (ScatterChart) v.findViewById(R.id.scatterChart1);
    mChart.setDescription("");
    
    Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"OpenSans-Light.ttf");
    
    MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);

    mChart.setMarkerView(mv);

    mChart.setDrawGridBackground(false);
    mChart.setData(generateScatterData(6, 10000, 200));
    
    XAxis xAxis = mChart.getXAxis();
    xAxis.setEnabled(true);
    xAxis.setPosition(XAxisPosition.BOTTOM);
    
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(tf);
    
    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setTypeface(tf);
    rightAxis.setDrawGridLines(false);
    
    Legend l = mChart.getLegend();
    l.setWordWrapEnabled(true);
    l.setTypeface(tf);
    l.setFormSize(14f);
    l.setTextSize(9f);
    
    // increase the space between legend & bottom and legend & content
    l.setYOffset(13f);       
    mChart.setExtraBottomOffset(16f);
    
    return v;
}
 
Example 3
Source File: PieChartItem.java    From memorize with MIT License 4 votes vote down vote up
@SuppressLint("InflateParams")
@Override
public View getView(int position, View convertView, Context c) {

    ViewHolder holder;

    if (convertView == null) {

        holder = new ViewHolder();

        convertView = LayoutInflater.from(c).inflate(
                R.layout.stats_item_piechart, null);
        holder.chart = convertView.findViewById(R.id.chart);

        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    // apply styling
    holder.chart.getDescription().setEnabled(false);
    holder.chart.setHoleRadius(52f);
    holder.chart.setTransparentCircleRadius(57f);
    holder.chart.setCenterText(mCenterText);
    holder.chart.setCenterTextSize(9f);
    holder.chart.setUsePercentValues(true);
    holder.chart.setExtraOffsets(5, 10, 50, 10);

    mChartData.setValueFormatter(new PercentFormatter());
    mChartData.setValueTextSize(11f);
    mChartData.setValueTextColor(Color.WHITE);
    // set data
    holder.chart.setData((PieData) mChartData);

    Legend l = holder.chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    l.setYEntrySpace(0f);
    l.setYOffset(0f);

    holder.chart.animateY(900);

    return convertView;
}
 
Example 4
Source File: InventoryReportFragment.java    From mobikul-standalone-pos with MIT License 4 votes vote down vote up
private void setSalesProductChart(List<SalesProductReportModel> soldProducts) {
        binding.productChart.setUsePercentValues(true);
        binding.productChart.getDescription().setEnabled(false);
//        binding.productChart.setExtraOffsets(5, 10, 10, 5);
//        holder.chart.setExtraOffsets(5, 10, 50, 10);

        binding.productChart.setDragDecelerationFrictionCoef(0.95f);

        binding.productChart.setCenterText(generateCenterSpannableText());

        binding.productChart.setDrawHoleEnabled(true);
        binding.productChart.setHoleColor(Color.WHITE);

        binding.productChart.setTransparentCircleColor(Color.WHITE);
        binding.productChart.setTransparentCircleAlpha(90);

        binding.productChart.setHoleRadius(50f);
        binding.productChart.setTransparentCircleRadius(55f);

        binding.productChart.setDrawCenterText(true);

        binding.productChart.setRotationAngle(0);
        // enable rotation of the chart by touch
        binding.productChart.setRotationEnabled(true);
        binding.productChart.setHighlightPerTapEnabled(true);

        // binding.productChart.setUnit(" €");
        // binding.productChart.setDrawUnitsInChart(true);

        // add a selection listener
//        binding.productChart.setOnChartValueSelectedListener(this);

        setData(soldProducts, 10);

        binding.productChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
        // binding.productChart.spin(2000, 0, 360);

        Legend l = binding.productChart.getLegend();
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
        l.setOrientation(Legend.LegendOrientation.VERTICAL);
        l.setDrawInside(false);
//        l.setXEntrySpace(7f);
        l.setYEntrySpace(0f);
        l.setYOffset(0f);

        // entry label styling
        binding.productChart.setEntryLabelColor(Color.WHITE);
        binding.productChart.setEntryLabelTextSize(12f);
    }
 
Example 5
Source File: BarChartActivityMultiDataset.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);

        setTitle("BarChartActivityMultiDataset");

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

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

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

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

//        chart.setDrawBorders(true);

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

        chart.setDrawBarShadow(false);

        chart.setDrawGridBackground(false);

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

        seekBarX.setProgress(10);
        seekBarY.setProgress(100);

        Legend l = chart.getLegend();
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
        l.setOrientation(Legend.LegendOrientation.VERTICAL);
        l.setDrawInside(true);
        l.setTypeface(tfLight);
        l.setYOffset(0f);
        l.setXOffset(10f);
        l.setYEntrySpace(0f);
        l.setTextSize(8f);

        XAxis xAxis = chart.getXAxis();
        xAxis.setTypeface(tfLight);
        xAxis.setGranularity(1f);
        xAxis.setCenterAxisLabels(true);
        xAxis.setValueFormatter(new ValueFormatter() {
            @Override
            public String getFormattedValue(float value) {
                return String.valueOf((int) value);
            }
        });

        YAxis leftAxis = chart.getAxisLeft();
        leftAxis.setTypeface(tfLight);
        leftAxis.setValueFormatter(new LargeValueFormatter());
        leftAxis.setDrawGridLines(false);
        leftAxis.setSpaceTop(35f);
        leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

        chart.getAxisRight().setEnabled(false);
    }
 
Example 6
Source File: HalfPieChartActivity.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_piechart_half);

    setTitle("HalfPieChartActivity");

    chart = findViewById(R.id.chart1);
    chart.setBackgroundColor(Color.WHITE);

    moveOffScreen();

    chart.setUsePercentValues(true);
    chart.getDescription().setEnabled(false);

    chart.setCenterTextTypeface(tfLight);
    chart.setCenterText(generateCenterSpannableText());

    chart.setDrawHoleEnabled(true);
    chart.setHoleColor(Color.WHITE);

    chart.setTransparentCircleColor(Color.WHITE);
    chart.setTransparentCircleAlpha(110);

    chart.setHoleRadius(58f);
    chart.setTransparentCircleRadius(61f);

    chart.setDrawCenterText(true);

    chart.setRotationEnabled(false);
    chart.setHighlightPerTapEnabled(true);

    chart.setMaxAngle(180f); // HALF CHART
    chart.setRotationAngle(180f);
    chart.setCenterTextOffset(0, -20);

    setData(4, 100);

    chart.animateY(1400, Easing.EaseInOutQuad);

    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setXEntrySpace(7f);
    l.setYEntrySpace(0f);
    l.setYOffset(0f);

    // entry label styling
    chart.setEntryLabelColor(Color.WHITE);
    chart.setEntryLabelTypeface(tfRegular);
    chart.setEntryLabelTextSize(12f);
}
 
Example 7
Source File: PieChartItem.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@SuppressLint("InflateParams")
@Override
public View getView(int position, View convertView, Context c) {

    ViewHolder holder;

    if (convertView == null) {

        holder = new ViewHolder();

        convertView = LayoutInflater.from(c).inflate(
                R.layout.list_item_piechart, null);
        holder.chart = convertView.findViewById(R.id.chart);

        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    // apply styling
    holder.chart.getDescription().setEnabled(false);
    holder.chart.setHoleRadius(52f);
    holder.chart.setTransparentCircleRadius(57f);
    holder.chart.setCenterText(mCenterText);
    holder.chart.setCenterTextTypeface(mTf);
    holder.chart.setCenterTextSize(9f);
    holder.chart.setUsePercentValues(true);
    holder.chart.setExtraOffsets(5, 10, 50, 10);

    mChartData.setValueFormatter(new PercentFormatter());
    mChartData.setValueTypeface(mTf);
    mChartData.setValueTextSize(11f);
    mChartData.setValueTextColor(Color.WHITE);
    // set data
    holder.chart.setData((PieData) mChartData);

    Legend l = holder.chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    l.setYEntrySpace(0f);
    l.setYOffset(0f);

    // do not forget to refresh the chart
    // holder.chart.invalidate();
    holder.chart.animateY(900);

    return convertView;
}
 
Example 8
Source File: PieChartActivity.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_piechart);

    setTitle("PieChartActivity");

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

    seekBarX = findViewById(R.id.seekBar1);
    seekBarY = findViewById(R.id.seekBar2);

    seekBarX.setOnSeekBarChangeListener(this);
    seekBarY.setOnSeekBarChangeListener(this);

    chart = findViewById(R.id.chart1);
    chart.setUsePercentValues(true);
    chart.getDescription().setEnabled(false);
    chart.setExtraOffsets(5, 10, 5, 5);

    chart.setDragDecelerationFrictionCoef(0.95f);

    chart.setCenterTextTypeface(tfLight);
    chart.setCenterText(generateCenterSpannableText());

    chart.setDrawHoleEnabled(true);
    chart.setHoleColor(Color.WHITE);

    chart.setTransparentCircleColor(Color.WHITE);
    chart.setTransparentCircleAlpha(110);

    chart.setHoleRadius(58f);
    chart.setTransparentCircleRadius(61f);

    chart.setDrawCenterText(true);

    chart.setRotationAngle(0);
    // enable rotation of the chart by touch
    chart.setRotationEnabled(true);
    chart.setHighlightPerTapEnabled(true);

    // chart.setUnit(" €");
    // chart.setDrawUnitsInChart(true);

    // add a selection listener
    chart.setOnChartValueSelectedListener(this);

    seekBarX.setProgress(4);
    seekBarY.setProgress(10);

    chart.animateY(1400, Easing.EaseInOutQuad);
    // chart.spin(2000, 0, 360);

    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    l.setXEntrySpace(7f);
    l.setYEntrySpace(0f);
    l.setYOffset(0f);

    // entry label styling
    chart.setEntryLabelColor(Color.WHITE);
    chart.setEntryLabelTypeface(tfRegular);
    chart.setEntryLabelTextSize(12f);
}
 
Example 9
Source File: PieChartActivity.java    From iMoney with Apache License 2.0 4 votes vote down vote up
@Override
protected void initData() {
    ivBack.setVisibility(View.VISIBLE);
    ivSetting.setVisibility(View.GONE);
    tvTitle.setText("饼状图");

    // 初始化字体库
    mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

    pieChart.setDescription("目前android市场的占比情况");
    // 设置内部圆的半径
    pieChart.setHoleRadius(52f);
    // 设置包裹内部圆的半径
    pieChart.setTransparentCircleRadius(67f);

    pieChart.setCenterText("Android\n市场占比");
    // 设置中间显示的文本的字体
    pieChart.setCenterTextTypeface(mTf);
    // 设置中间显示的文本的字体大小
    pieChart.setCenterTextSize(18f);
    // 显示的各个部分的占比和是否为100%
    pieChart.setUsePercentValues(true);

    // 产生饼状图的数据
    PieData mChartData = generateDataPie();

    // 设置显示数据的格式
    mChartData.setValueFormatter(new PercentFormatter());
    mChartData.setValueTypeface(mTf);
    // 设置显示各个部分的文字的字体大小
    mChartData.setValueTextSize(11f);
    // 设置显示各个部分的文字的字体颜色
    mChartData.setValueTextColor(Color.RED);
    // set data
    pieChart.setData(mChartData);

    //获取图示的说明结构
    Legend l = pieChart.getLegend();
    //设置显示的位置
    l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
    //设置几项说明在Y轴方向的间距
    l.setYEntrySpace(10f);
    //设置第一项距离y轴顶部的间距
    l.setYOffset(30f);

    // do not forget to refresh the chart
    // pieChart.invalidate();
    pieChart.animateXY(900, 900);
}
 
Example 10
Source File: BarChartActivityMultiDataset.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);

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

        mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
        mSeekBarX.setOnSeekBarChangeListener(this);

        mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
        mSeekBarY.setOnSeekBarChangeListener(this);

        mChart = (BarChart) findViewById(R.id.chart1);
        mChart.setOnChartValueSelectedListener(this);
        mChart.setDescription("");

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

        mChart.setDrawBarShadow(false);

        mChart.setDrawGridBackground(false);

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

        // define an offset to change the original position of the marker
        // (optional)
        // mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight());

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

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

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

        Legend l = mChart.getLegend();
        l.setPosition(LegendPosition.RIGHT_OF_CHART_INSIDE);
        l.setTypeface(tf);
        l.setYOffset(0f);
        l.setYEntrySpace(0f);
        l.setTextSize(8f);

        XAxis xl = mChart.getXAxis();
        xl.setTypeface(tf);

        YAxis leftAxis = mChart.getAxisLeft();
        leftAxis.setTypeface(tf);
        leftAxis.setValueFormatter(new LargeValueFormatter());
        leftAxis.setDrawGridLines(false);
        leftAxis.setSpaceTop(30f);
        leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)

        mChart.getAxisRight().setEnabled(false);
    }
 
Example 11
Source File: PieChartItem.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(int position, View convertView, Context c) {

    ViewHolder holder = null;

    if (convertView == null) {

        holder = new ViewHolder();

        convertView = LayoutInflater.from(c).inflate(
                R.layout.list_item_piechart, null);
        holder.chart = (PieChart) convertView.findViewById(R.id.chart);

        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    // apply styling
    holder.chart.setDescription("");
    holder.chart.setHoleRadius(52f);
    holder.chart.setTransparentCircleRadius(57f);
    holder.chart.setCenterText(mCenterText);
    holder.chart.setCenterTextTypeface(mTf);
    holder.chart.setCenterTextSize(9f);
    holder.chart.setUsePercentValues(true);
    holder.chart.setExtraOffsets(5, 10, 50, 10);

    mChartData.setValueFormatter(new PercentFormatter());
    mChartData.setValueTypeface(mTf);
    mChartData.setValueTextSize(11f);
    mChartData.setValueTextColor(Color.WHITE);
    // set data
    holder.chart.setData((PieData) mChartData);

    Legend l = holder.chart.getLegend();
    l.setPosition(LegendPosition.RIGHT_OF_CHART);
    l.setYEntrySpace(0f);
    l.setYOffset(0f);

    // do not forget to refresh the chart
    // holder.chart.invalidate();
    holder.chart.animateY(900);

    return convertView;
}
 
Example 12
Source File: PieChartActivity.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_piechart);

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

    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);

    mSeekBarY.setProgress(10);

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

    mChart = (PieChart) findViewById(R.id.chart1);
    mChart.setUsePercentValues(true);
    mChart.setDescription("");
    mChart.setExtraOffsets(5, 10, 5, 5);

    mChart.setDragDecelerationFrictionCoef(0.95f);

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

    mChart.setCenterTextTypeface(Typeface.createFromAsset(getAssets(), "OpenSans-Light.ttf"));
    mChart.setCenterText(generateCenterSpannableText());

    mChart.setDrawHoleEnabled(true);
    mChart.setHoleColor(Color.WHITE);

    mChart.setTransparentCircleColor(Color.WHITE);
    mChart.setTransparentCircleAlpha(110);

    mChart.setHoleRadius(58f);
    mChart.setTransparentCircleRadius(61f);

    mChart.setDrawCenterText(true);

    mChart.setRotationAngle(0);
    // enable rotation of the chart by touch
    mChart.setRotationEnabled(true);
    mChart.setHighlightPerTapEnabled(true);

    // mChart.setUnit(" €");
    // mChart.setDrawUnitsInChart(true);

    // add a selection listener
    mChart.setOnChartValueSelectedListener(this);

    setData(3, 100);

    mChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
    // mChart.spin(2000, 0, 360);

    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.RIGHT_OF_CHART);
    l.setXEntrySpace(7f);
    l.setYEntrySpace(0f);
    l.setYOffset(0f);
}