美文网首页
MPAndroidChart 堆叠图

MPAndroidChart 堆叠图

作者: KenChen_939 | 来源:发表于2019-07-05 08:48 被阅读0次

    与柱形图无太多差别,主要差别在添加数据

    import android.graphics.Color;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import com.github.mikephil.charting.charts.BarChart;
    import com.github.mikephil.charting.data.BarData;
    import com.github.mikephil.charting.data.BarDataSet;
    import com.github.mikephil.charting.data.BarEntry;
    import java.util.ArrayList;
    import java.util.List;
    
    public class MainActivity extends AppCompatActivity {
        private BarChart barChart;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            barChart=findViewById(R.id.barChart2);
    
            List<String> namelist = new ArrayList<>();
            List<BarEntry> entries = new ArrayList<>();
    
    
            namelist.add("111");
            namelist.add("222");
            namelist.add("333");
    
            entries.add(new BarEntry(new float[]{123.0f,456.0f},0));
            entries.add(new BarEntry(new float[]{123.0f,456.0f},1));
            entries.add(new BarEntry(new float[]{123.0f,456.0f},2));
    
            barChart.setDrawValueAboveBar(false);
            barChart.setEnabled(false);
    
            BarDataSet barData1 = new BarDataSet(entries,"京东");
            barData1.setColors(new int[]{Color.RED,Color.GREEN,Color.rgb(111,32,16)});
    
            BarData barData = new BarData(namelist,barData1);
            barChart.setData(barData);
        }
    }
    

    相关文章

      网友评论

          本文标题:MPAndroidChart 堆叠图

          本文链接:https://www.haomeiwen.com/subject/jgnjhctx.html