2015-08-18 37 views
5

Tôi muốn loại bỏ thu phóng từ một mục barchart. MpChart BarItem chart before scroll MpChart BarItem chart after scrollcách xóa tính năng thu phóng từ thư viện android mpchart?

Khi người dùng cuộn mục biểu đồ thanh giá trị chú giải y ghi đè giá trị x huyền thoại hoặc giá trị huyền thoại y được hiển thị bên dưới trục X.

Đây mã cho các mục biểu đồ thanh:

import ro.charttest.R; 
    import android.content.Context; 
    import android.graphics.Typeface; 
    import android.view.LayoutInflater; 
    import android.view.View; 

    import com.github.mikephil.charting.charts.BarChart; 
    import com.github.mikephil.charting.data.ChartData; 
    import com.github.mikephil.charting.utils.ColorTemplate; 
    import com.github.mikephil.charting.utils.Legend; 
    import com.github.mikephil.charting.utils.XLabels; 
    import com.github.mikephil.charting.utils.Legend.LegendPosition; 
    import com.github.mikephil.charting.utils.XLabels.XLabelPosition; 
    import com.github.mikephil.charting.utils.YLabels; 
    import com.github.mikephil.charting.utils.YLabels.YLabelPosition; 

    public class BarChartItem extends ChartItem { 

private ColorTemplate mCt; 
private Typeface mTf; 

public BarChartItem(ChartData cd, Context c) { 
    super(cd);   
    mCt = new ColorTemplate(); 
    mCt.addDataSetColors(new int[]{ R.color.colorful_1}, c); 
    mCt.addDataSetColors(new int[]{ R.color.greens_2}, c); 
    mTf = Typeface.createFromAsset(c.getAssets(), "tahoma.ttf");   
} 

@Override 
public int getItemType() { 
    return TYPE_BARCHART; 
} 

@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_barchart, null); 
     holder.chart = (BarChart) convertView.findViewById(R.id.chart); 

     convertView.setTag(holder); 

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

    // apply styling 
    // holder.chart.setYLabelCount(10); 
    holder.chart.setColorTemplate(mCt); 
    holder.chart.setBarSpace(30); 
    holder.chart.setStartAtZero(false); 

    holder.chart.setScrollContainer(false); 


    holder.chart.setYLabelTypeface(mTf); 
    holder.chart.setXLabelTypeface(mTf); 
    holder.chart.setValueTypeface(mTf); 
    holder.chart.setDescription(""); 
    holder.chart.setDrawVerticalGrid(false); 
    holder.chart.setDrawYLabels(true); 
    holder.chart.setDrawYValues(true); 
    holder.chart.setDrawGridBackground(false); 

    holder.chart.setMaxVisibleValueCount(10); 
    // sets the number of digits for values inside the chart 
    holder.chart.setValueDigits(0); 

    // disable 3D 
    holder.chart.set3DEnabled(false); 
    // holder.chart.setYLabelCount(10); 
    holder.chart.setAutoFinish(true); 
    // scaling can now only be done on x- and y-axis separately 
    holder.chart.setPinchZoom(true);   

    XLabels xl = holder.chart.getXLabels(); 
    xl.setCenterXLabelText(true); 
    xl.setPosition(XLabelPosition.BOTTOM); 

    // set data 
    holder.chart.setData(mChartData); 

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

    holder.chart.cancelLongPress(); 

    holder.chart.setYRange(0, 1.5f*holder.chart.getYMax(), false); 

    YLabels yLabels = holder.chart.getYLabels(); 
    yLabels.mDecimals = 0; 
    yLabels.setPosition(YLabelPosition.LEFT); 

    XLabels xLabels = holder.chart.getXLabels(); 
    xLabels.setPosition(XLabelPosition.BOTTOM); 

    Legend l = holder.chart.getLegend(); 
    l.setPosition(LegendPosition.BELOW_CHART_LEFT); 
    l.setOffsetBottom(50f); 
    l.setTypeface(mTf); 

    return convertView; 
} 

private static class ViewHolder { 
    BarChart chart; 
} 

}

Trả lời

7

tôi đã thêm dòng sau:

holder.chart.setTouchEnabled(false); 

và zoom tính năng đã bị loại bỏ và cũng có tất cả các cảm ứng tương tác có thể với biểu đồ. Xem reference.

Các vấn đề liên quan