lecho/hellocharts-android

Hellocharts android library not rendering chart when there is a single value or when y axis values are same

jomingeorge opened this issue · 2 comments

When i try to generate the graph with a single value, it is just showing an empty graph (It is supposed to show a single dot in the graph indicating the value right?).

The problem also persists if the first and second y axis value is same (When there is just 2 values).

Any ideas why this weird problem occurs?

The code am using is given below

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        List<String> datelist = new ArrayList<String>();
        List<Float> weightlist = new ArrayList<Float>();
        datelist.add("12/Apr/2020");
        weightlist.add(72f);
        datelist.add("13/Apr/2020");
        weightlist.add(72f);

        LineChartView chart = findViewById(R.id.chart);

        List<AxisValue> axisValues = new ArrayList<AxisValue>();
        List<PointValue> values = new ArrayList<PointValue>();
        for (int i = 0; i < datelist.size(); ++i) {
            values.add(new PointValue(i, weightlist.get(i)));
            axisValues.add(new AxisValue(i).setLabel(datelist.get(i)));
        }

        Line line = new Line(values).setColor(Color.BLUE).setCubic(false);
        line.setHasLabels(true);
        List<Line> lines = new ArrayList<Line>();
        lines.add(line);

        LineChartData data = new LineChartData();
        data.setLines(lines);

        data.setAxisXBottom(new Axis(axisValues));
        data.setAxisYLeft(new Axis());

        chart.setLineChartData(data);


    }
}

i have the same problem,have you found the solution?

Hi, if suddenly someone will help after so much time

final Viewport v = new Viewport(charts[chart].getMaximumViewport());
v.top = (max > 0 ? max : 100);
v.bottom = min;
charts[chart].setMaximumViewport(v);
charts[chart].setCurrentViewport(v);