HSB
HSB

Reputation: 33

Graphing scientific data in LineChart from MPAndroidChart

I am using MPAndroidChart library to draw graphs (especially LineCharts) in my App.

To draw a LineChart with the mentioned library first we need to create entries and labels as follow:

    // Getting LineChart
    LineChart lineChart = (LineChart) rootView.findViewById(R.id.chart);

    // Creating list of entry
    ArrayList<Entry> entries = new ArrayList<>();

    // Creating labels
    ArrayList<String> labels = new ArrayList<String>();

    // Fill entries and lables
    entries.add(new Entry(326.422f, 0));
    entries.add(new Entry(8.36f, 1));
    entries.add(new Entry(6.5f, 2));
    entries.add(new Entry(2.37f, 3));
    entries.add(new Entry(18.13f, 4));
    entries.add(new Entry(9f, 5));

    labels.add("0");
    labels.add("1");
    labels.add("2");
    labels.add("3");
    labels.add("4");
    labels.add("5");

    // Create dataset
    final LineDataSet dataset = new LineDataSet(entries, "Legend description");

    // Create LineData with labels and dataset prepared previously
    LineData data = new LineData(labels, dataset);

    // Set the data and list of labels into chart
    lineChart.setData(data);

Ok this is working, but the point is what if I want to graph a set of coordinates like this: X = {(35.3, 22.9), (69.39, 27.36), (66.37, 31.697), (58.36, 36.32), (45.336, 38.296), (25.39, 40), (67.396, 43.633)}.

The constructor of Entry accepts a float number as first parameter and an integer as second parameter, so how can I give the above X set to the LineChart?

Someone could say that I can set the labels accordingly, for example the first label could be labeled as "22.9", the second as "27.36", and so on... But this is mathematically wrong as the graph is not scaled properly.

In the documentation I found classes like Entry, BarEntry, BubbleEntry, CandleEntry but there is nothing something like LineEntry.

Can anyone point me to the right direction on how to achieve this goal?

Thank you,

HSB

Upvotes: 2

Views: 156

Answers (1)

Philipp Jahoda
Philipp Jahoda

Reputation: 51421

Currently only integers are supported for the x-axis. The reason therefore is that each string on the x-axis should correspond to a value on the y-axis.

This will change in the next release of the library, where both values will be changed to double.

The new version should be released in April.

Upvotes: 1

Related Questions