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()));
}
}
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;
}
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;
}
}
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;
}
Aggregations