2015-11-23 19 views
2

我有下面顯示一些值的圖表。Android:MPAndroidChart如何刪除圖表右側的值?

我想隱藏/刪除右側的值,因爲左側已經足夠了。

下面

見圖片:

enter image description here

而代碼如下:

public class MainActivity extends AppCompatActivity implements 
     OnChartValueSelectedListener{ 
    private LineChart mDataLineChart; 
    private RelativeLayout mRelativeLayout; 

    private LineChart mChart; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     setContentView(R.layout.activity_linechart); 

     // Set chart 
     setChart(); 
     // add data 
     setData2(3, 155); 
     // ANIMATE CHART 
     animateChart(); 
    } 


    private void setChart() { 
     mChart = (LineChart) findViewById(R.id.chart1); 
     mChart.setOnChartValueSelectedListener(this); 

     //////////////////////////////// 
     // SET DESCRIPTION COLOR 
     //////////////////////////////// 
     mChart.setDescriptionColor(getResources().getColor(R.color.chart_desc_color)); 
     //////////////////////////////// 
     // BORDERS SURROUNDING THE CHART 
     //////////////////////////////// 
     mChart.setDrawBorders(true); 
     mChart.setBorderColor(getResources().getColor(R.color.chart_border)); 
     mChart.setBorderWidth(2); 
     //////////////////////////////// 
     // CHART BG COLOR 
     //////////////////////////////// 
     mChart.setBackgroundColor(getResources().getColor(R.color.chart_bg)); 
     //////////////////////////////// 
     // GRID BG COLOR 
     //////////////////////////////// 
     mChart.setDrawGridBackground(true); 
     mChart.setGridBackgroundColor(getResources().getColor(R.color.chart_bg)); 

     //////////////////////////////// 
     // OTHER SETTINGS 
     //////////////////////////////// 
     mChart.setDescription(""); 
     mChart.setNoDataTextDescription("You need to provide data for the chart."); 
     // enable touch gestures 
     mChart.setTouchEnabled(true); 
     mChart.setDragDecelerationFrictionCoef(0.9f); 
     // enable scaling and dragging 
     mChart.setDragEnabled(true); 
     mChart.setScaleEnabled(true); 
     mChart.setHighlightPerDragEnabled(true); 
     // if disabled, scaling can be done on x- and y-axis separately 
     mChart.setPinchZoom(true); 

    } 


    private void setData2(int count, float range) { 

     //////////////////////////////// 
     // X axis values (labels) 
     //////////////////////////////// 
     ArrayList<String> xVals = new ArrayList<String>(); 
     for (int i = 0; i < count; i++) { 
      xVals.add((i) + " day"); 
     } 

     //////////////////////////////// 
     // Y axis values (value in linechart) 
     //////////////////////////////// 
     ArrayList<Entry> yVals1 = new ArrayList<Entry>(); 
     for (int i = 0; i < count; i++) { 
      float mult = range/2f; 
      float val = (float) (Math.random() * mult) + 50;// + (float) 
      // ((mult * 
      // 0.1)/10); 
      yVals1.add(new Entry(val, i)); 
     } 

     //////////////////////////////// 
     // SETTING FOR LINEAR LINE 
     //////////////////////////////// 
     LineDataSet set1 = new LineDataSet(yVals1, "Pressure mm/Hg"); 
     set1.setAxisDependency(AxisDependency.LEFT); 
     set1.setLineWidth(2f); 
     set1.setCircleSize(5f); 
     set1.setColor(getResources().getColor(R.color.chart_line_color)); 
     set1.setCircleColor(getResources().getColor(R.color.chart_line_color)); 
     set1.setFillColor(getResources().getColor(R.color.chart_line_color)); 
     set1.setDrawCircleHole(true); 

     ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>(); 
     dataSets.add(set1); // add the datasets 

     //////////////////////////////// 
     // SETTING FOR DATASET (FONT SIZE,) 
     //////////////////////////////// 
     LineData data = new LineData(xVals, dataSets); 
     data.setValueTextColor(Color.BLACK); 
     data.setValueTextSize(9f); 

     //////////////////////////////// 
     // SET WHOLE DATASET TO CHART 
     //////////////////////////////// 
     mChart.setData(data); 
    } 

    private void animateChart() { 
     //////////////////////////////// 
     // ANIMATION DURATION 
     //////////////////////////////// 
     mChart.animateX(1000); 
     //////////////////////////////// 
     // SET LEGEND BOTTOM DATA TEXT 
     //////////////////////////////// 
     XAxis xAxis = mChart.getXAxis(); 
     xAxis.setTextSize(12f); 
     xAxis.setTextColor(Color.BLACK); 
     xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); 
     xAxis.setSpaceBetweenLabels(1); 



    } 

    @Override 
    public void onValueSelected(Entry e, int dataSetIndex, Highlight h) { 
     Log.i("Entry selected", e.toString()); 
    } 

    @Override 
    public void onNothingSelected() { 
     Log.i("Nothing selected", "Nothing selected."); 
    } 

} 

我試圖在文檔中進行搜索在Github上:

https://github.com/PhilJay/MPAndroidChart/wiki/The-Axis

但沒有運氣。

如何從右側刪除值?

非常感謝您的任何建議。

回答

0

你可能想檢查示例應用程序和相應的代碼。該應用程序包括2個相關示例:折線圖和折線圖(雙YAxis)。首先是你想要的,後者是你所知道的。

應用鏈接:https://play.google.com/store/apps/details?id=com.xxmassdeveloper.mpchartexample

代碼:https://github.com/PhilJay/MPAndroidChart/tree/master/MPChartExample

+0

發佈代碼基於您鏈接的示例。 – redrom

+0

問題是因爲您通過創建2個Y軸創建圖表,左邊一個,右邊一個。你不需要正確的。嘗試用yVals2刪除一個,並只添加第一個到圖表。 –

+0

我不使用yVals2,它被評論的代碼。我更新了代碼示例。 – redrom

12
YAxis yAxisRight = mChart.getAxisRight(); 
yAxisRight.setEnabled(false); 

將此代碼放置在您的setChart();

相關問題