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

Inconsistent behavior with date series #34

Open
nicolabeghin opened this issue Jun 15, 2018 · 1 comment
Open

Inconsistent behavior with date series #34

nicolabeghin opened this issue Jun 15, 2018 · 1 comment

Comments

@nicolabeghin
Copy link

Hi everyone
I'm very pleased with the library, great works!

Problem is, I don't understand why it behaves inconsistently, meaning that one time it shows like this (without date X labels and incorrect Y axis rounding)

image
image

in place of the correct display
image

image

I'm following the example Dates.java
https://github.com/jjoe64/GraphView-Demos/blob/master/app/src/main/java/com/jjoe64/graphview_demos/examples/Dates.java

if (story.getId().equals(storyId)) {
    GraphView graph = (GraphView) findViewById(R.id.graph);
    DataPoint[] dataPoints = new DataPoint[story.getMetrics().size()];
    int i = 0;
    for (Story.Metric metric : story.getMetrics()) {
        dataPoints[i] = new DataPoint(metric.getDate(), (int)metric.getConversations());
        i++;
    }
    LineGraphSeries<DataPoint> series = new LineGraphSeries<DataPoint>(dataPoints);
    series.setAnimated(true);
    graph.addSeries(series);
    graph.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(graph.getContext(), new SimpleDateFormat(LABEL_DATE_FORMAT)));
    graph.getGridLabelRenderer().setNumHorizontalLabels(dataPoints.length);
    // as we use dates as labels, the human rounding to nice readable numbers
    // is not nessecary
    graph.getGridLabelRenderer().setHumanRounding(false);

    // set manual x bounds to have nice steps
    graph.getViewport().setMinX(story.getMetrics().get(0).getDate().getTime());
    graph.getViewport().setMaxX(story.getMetrics().get(story.getMetrics().size() - 1).getDate().getTime());
    graph.getViewport().setXAxisBoundsManual(true);

}

I'm really puzzled..

thanks
nicola

@hafiz013
Copy link

hafiz013 commented Jun 27, 2018

Same goes to me but my date redundance.

` DateFormat fmt1 = new SimpleDateFormat("MMMM dd, yyyy", Locale.US);
Date d1 = null,d2 = null,d3 = null,d4 = null,d5 = null,d6 = null,d7 = null,
d8 = null,d9 = null,d10 = null,d11 = null, d12 = null;

    try {
        d1 = fmt1.parse("January 1,  2018");
        d2 = fmt1.parse("February 1,  2018");
        d3 = fmt1.parse("March 1,  2018");
        d4 = fmt1.parse("April 1,  2018");
        d5 = fmt1.parse("May 1,  2018");
        d6 = fmt1.parse("June 1,  2018");
        d7 = fmt1.parse("July 1,  2018");
        d8 = fmt1.parse("August 1,  2018");
        d9 = fmt1.parse("September 1,  2018");
        d10 = fmt1.parse("October 1,  2018");
        d11 = fmt1.parse("November 1,  2018");
        d12 = fmt1.parse("December 1,  2018");
    } catch (ParseException e) {
        e.printStackTrace();
    }

    graphView = (GraphView)v.findViewById(R.id.graph);

    series = new LineGraphSeries<>(new DataPoint[] {
            new DataPoint(d1, 0),
            new DataPoint(d2, 123.00),
            new DataPoint(d3, 200.00),
            new DataPoint(d4, 145.00),
            new DataPoint(d5, 150.00),
            new DataPoint(d6, 180.00),
            new DataPoint(d7, 0.00),
            new DataPoint(d8, 0.00),
            new DataPoint(d9, 0.00),
            new DataPoint(d10, 0.00),
            new DataPoint(d11, 30.00),
            new DataPoint(d12, 0.00)
    });
    series.setColor(ContextCompat.getColor(getActivity(), R.color.bgwhite));

    //series.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.bgwhite));
    graphView.addSeries(series);

    // set date label formatter
    DateFormat fmt = new SimpleDateFormat("MMM", Locale.US);
    graphView.getGridLabelRenderer().setLabelFormatter(new DateAsXAxisLabelFormatter(getActivity(), fmt));
    graphView.getGridLabelRenderer().setNumHorizontalLabels(12); // only 4 because of the space
    graphView.getGridLabelRenderer().setTextSize(20f);
    graphView.getGridLabelRenderer().setLabelHorizontalHeight(10);

    // set manual x bounds to have nice steps
    graphView.getViewport().setMinX(d1.getTime());
    graphView.getViewport().setMaxX(d12.getTime());

    graphView.getViewport().setXAxisBoundsManual(true);
    //graphView.getViewport().calcCompleteRange();

    // as we use dates as labels, the human rounding to nice readable numbers

// is not necessary
graphView.getGridLabelRenderer().setHumanRounding(false); // show line graph y`
whatsapp image 2018-06-27 at 11 44 10 am

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

2 participants