Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawable Icon of entry will disappear if chart.setVisibleXRangeMaximum bigger than a specific value

I am using MPAndroidchart and I want to draw a red dot when I detect a trough in realtime.

I use

set.getEntryForIndex(set.getEntryCount()-1).setIcon(ContextCompat.getDrawable(this, R.drawable.red_dot));

If I set chart.setVisibleXRangeMaximum(90), it is fine, but if I set XRangeMaximum bigger than about 100, the red dot will disappear if I don't use finger to zoom in.

When I zoom in, I can see those red dot

Is there any solution to keep the red dot visible when XRangeMaximum bigger than 100 and no need to zoom in because I want to show about 300 data in that chart.

private void addEntry(double Pulse_Signal){
        LineData data = chart.getData();
        if (data != null) {
            ILineDataSet set = data.getDataSetByIndex(0);
            // set.addEntry(...); // can be called as well
            if (set == null) {
                set = createSet(false);
                data.addDataSet(set);
            }
            if(DrawCircleFlag){
                set.getEntryForIndex(set.getEntryCount()-1).setIcon(ContextCompat.getDrawable(this, R.drawable.red_dot));
            }
            else {
                data.addEntry(new Entry(set.getEntryCount(), (float) Pulse_Signal), 0);
            }
            data.notifyDataChanged();

            chart.notifyDataSetChanged();
            chart.setVisibleXRangeMaximum(260);
            chart.moveViewToX(data.getEntryCount());
        }
    }

XRangeMaximum 90 like this XRangeMaximum 90

XRangeMaximum 260 like this XRangeMaximum 260

XRangeMaximum 260 when I use finger to zoom in XRangeMaximum 260

like image 697
John Avatar asked Aug 31 '25 17:08

John


1 Answers

I had this problem and found the answer. There is a maximum number of visible values on the chart, and it won't draw icons when you exceed this. The default seems to be 100. I used the following to make sure that icons are always drawn on my chart:

chart.setMaxVisibleValueCount(10000000);

like image 57
Tim B Avatar answered Sep 07 '25 15:09

Tim B