I am using latest release of mpandroidchart library. I have 2 bar charts on single activity. chart1 & chart2 are the id's in XML (I don't want to use barchart list view). chart1 cosnist Counts value & chart2 consist dollars value. I am getting the values already. But I want to know that is it a dollar value or counts value. so I can display the toast according to chart selected.
This is my Sample code.
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
View view;
TextView text;
switch (e.getXIndex()) {
case 0:
if (toast != null)
toast.cancel();
toast = Toast.makeText(getActivity(), "All Other Year Defectors: " +e.getVal(), Toast.LENGTH_SHORT);
view = toast.getView();
view.setBackgroundResource(R.color.all_odr_yr);
toast.setGravity(Gravity.TOP, 0, 950);
toast.show();
break;
case 1:
if (toast != null)
toast.cancel();
toast = Toast.makeText(getActivity(), "Last Year Defectors: " + e.getVal(), Toast.LENGTH_SHORT);
view = toast.getView();
view.setBackgroundResource(R.color.lst_yr_df);
toast.setGravity(Gravity.TOP, 0, 950);
toast.show();
break;
That seems to be quite difficult and hard to acheive with the library alone.
But what you could do is inline the listeners and use a separate listener for each chart, like this:
countChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
// COUNT CHART VALUE SELECTED
}
@Override
public void onNothingSelected() { }
});
dollarChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, int dataSetIndex, Highlight h) {
// DOLLAR CHART VALUE SELECTED
}
@Override
public void onNothingSelected() { }
});
In that way you can differentiate between the different charts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With