Search in sources :

Example 1 with BarChart

use of com.github.mikephil.charting.charts.BarChart in project LeMondeRssReader by MBach.

the class ArticleAdapter method onCreateViewHolder.

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    switch(viewType) {
        default:
        case Model.TEXT_TYPE:
            return new ViewHolderText(new TextView(parent.getContext()));
        case Model.IMAGE_TYPE:
            ImageView imageView = new ImageView(parent.getContext());
            imageView.setImageResource(R.drawable.avatar);
            return new ViewHolderImage(imageView);
        case Model.TWEET_TYPE:
            return new ViewHolderCardView(new CardView(parent.getContext()));
        case Model.GRAPH_TYPE:
            BarChart barChart = new BarChart(parent.getContext());
            return new ViewHolderBarChart(barChart);
        case Model.COMMENT_TYPE:
            return new ViewHolderText(new TextView(parent.getContext()));
    }
}
Also used : CardView(android.support.v7.widget.CardView) BarChart(com.github.mikephil.charting.charts.BarChart) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NonNull(android.support.annotation.NonNull)

Example 2 with BarChart

use of com.github.mikephil.charting.charts.BarChart in project MPAndroidChart by PhilJay.

the class BarChartFrag method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_simple_bar, container, false);
    // create a new chart object
    mChart = new BarChart(getActivity());
    mChart.getDescription().setEnabled(false);
    mChart.setOnChartGestureListener(this);
    MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
    // For bounds control
    mv.setChartView(mChart);
    mChart.setMarker(mv);
    mChart.setDrawGridBackground(false);
    mChart.setDrawBarShadow(false);
    Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Light.ttf");
    mChart.setData(generateBarData(1, 20000, 12));
    Legend l = mChart.getLegend();
    l.setTypeface(tf);
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(tf);
    // this replaces setStartAtZero(true)
    leftAxis.setAxisMinimum(0f);
    mChart.getAxisRight().setEnabled(false);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setEnabled(false);
    // programatically add the chart
    FrameLayout parent = (FrameLayout) v.findViewById(R.id.parentLayout);
    parent.addView(mChart);
    return v;
}
Also used : Legend(com.github.mikephil.charting.components.Legend) Typeface(android.graphics.Typeface) FrameLayout(android.widget.FrameLayout) BarChart(com.github.mikephil.charting.charts.BarChart) View(android.view.View) MyMarkerView(com.xxmassdeveloper.mpchartexample.custom.MyMarkerView) MyMarkerView(com.xxmassdeveloper.mpchartexample.custom.MyMarkerView) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 3 with BarChart

use of com.github.mikephil.charting.charts.BarChart in project LeMondeRssReader by MBach.

the class ArticleAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
    Model model = items.get(position);
    if (model == null) {
        return;
    }
    RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    RecyclerView.LayoutParams lp2 = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    switch(model.getType()) {
        case Model.TEXT_TYPE:
        case Model.COMMENT_TYPE:
            TextView textView = (TextView) model.getTheContent();
            ((ViewHolderText) holder).text.setText(textView.getText());
            ((ViewHolderText) holder).text.setPadding(textView.getPaddingLeft(), textView.getPaddingTop(), textView.getPaddingRight(), textView.getPaddingBottom());
            ((ViewHolderText) holder).text.setTypeface(textView.getTypeface());
            ((ViewHolderText) holder).text.setTextColor(textView.getCurrentTextColor());
            ((ViewHolderText) holder).text.setBackground(textView.getBackground());
            if (textView.getBackground() != null) {
                ((ViewHolderText) holder).text.setAllCaps(true);
            }
            ((ViewHolderText) holder).text.setLayoutParams(lp);
            ((ViewHolderText) holder).text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textView.getTextSize());
            break;
        case Model.IMAGE_TYPE:
            String imageURI = (String) model.getTheContent();
            ((ViewHolderImage) holder).image.setLayoutParams(lp);
            Picasso.with(((ViewHolderImage) holder).image.getContext()).load(imageURI).into(((ViewHolderImage) holder).image);
            break;
        case Model.TWEET_TYPE:
            //((ViewHolderCardView) holder).content.setText();
            break;
        case Model.GRAPH_TYPE:
            BarChart barChart = (BarChart) model.getTheContent();
            ((ViewHolderBarChart) holder).barChart.setLayoutParams(lp2);
            ((ViewHolderBarChart) holder).barChart.setData(barChart.getData());
            break;
    }
}
Also used : BarChart(com.github.mikephil.charting.charts.BarChart) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 4 with BarChart

use of com.github.mikephil.charting.charts.BarChart in project LeMondeRssReader by MBach.

the class GraphExtractor method generate.

Object generate() {
    BarChart barChart = new BarChart(context);
    List<BarEntry> yVals1 = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        float mult = 5;
        float val = (float) (Math.random() * mult);
        yVals1.add(new BarEntry(i, val));
    }
    BarDataSet set1 = new BarDataSet(yVals1, "The year 2017");
    List<IBarDataSet> dataSets = new ArrayList<>();
    dataSets.add(set1);
    BarData barData = new BarData(dataSets);
    barChart.setData(barData);
    return barChart;
}
Also used : BarDataSet(com.github.mikephil.charting.data.BarDataSet) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) BarData(com.github.mikephil.charting.data.BarData) IBarDataSet(com.github.mikephil.charting.interfaces.datasets.IBarDataSet) BarChart(com.github.mikephil.charting.charts.BarChart) ArrayList(java.util.ArrayList) BarEntry(com.github.mikephil.charting.data.BarEntry)

Aggregations

BarChart (com.github.mikephil.charting.charts.BarChart)4 TextView (android.widget.TextView)2 Typeface (android.graphics.Typeface)1 NonNull (android.support.annotation.NonNull)1 CardView (android.support.v7.widget.CardView)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 Legend (com.github.mikephil.charting.components.Legend)1 XAxis (com.github.mikephil.charting.components.XAxis)1 YAxis (com.github.mikephil.charting.components.YAxis)1 BarData (com.github.mikephil.charting.data.BarData)1 BarDataSet (com.github.mikephil.charting.data.BarDataSet)1 BarEntry (com.github.mikephil.charting.data.BarEntry)1 IBarDataSet (com.github.mikephil.charting.interfaces.datasets.IBarDataSet)1 MyMarkerView (com.xxmassdeveloper.mpchartexample.custom.MyMarkerView)1 ArrayList (java.util.ArrayList)1