Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jomingeorge opened this issue Apr 15, 2020 · 2 comments

Comments

@jomingeorge
Copy link

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);


    }
}
@578618770wts
Copy link

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

@V2oD2o
Copy link

V2oD2o commented Oct 20, 2022

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants