Coder Social home page Coder Social logo

Comments (3)

lecho avatar lecho commented on July 22, 2024

Can you paste part of code responsible for chart's data generation?

from hellocharts-android.

twisty1988 avatar twisty1988 commented on July 22, 2024
  private LineChartData buildLineChartData(AQIHourDatas aqiHourDatas) {
    if (aqiHourDatas == null) return null;
    List<PointValue> values = new ArrayList<>();
    List<AQIHourData> hourDatas = aqiHourDatas.getData();
    int size = hourDatas.size();
    for (int i = 0; i < size; ++i) {
        //if (i > 12) values.add(new PointValue(i, hourDatas.get(i).getAqi()));


        //TODO Sometimes  pointvalue will be the same..example..
        if (i > 12) values.add(new PointValue(i, 8));

    }

    Line line = new Line(values);

    line.setStrokeWidth(2);
    line.setFilled(false);
    line.setShape(ValueShape.CIRCLE);
    line.setColor(ColorUtil.EXCELLENT);
    line.setHasLabels(true);
    line.setPointRadius(4);


    List<Line> lines = new ArrayList<>();
    lines.add(line);

    LineChartData lineChartData = new LineChartData(lines);


    List<AxisValue> axisValueX = new ArrayList<>();
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    for (int i = 0; i < size; ++i) {
        if (i > 12) {
            String dateTime = hourDatas.get(i).getDateTime();
            try {
                Date date = simpleDateFormat.parse(dateTime);
                calendar.setTime(date);
                dateTime = calendar.get(Calendar.HOUR_OF_DAY) + ":00";
            } catch (ParseException e) {
                Timber.e(e.toString());
                dateTime = "";
            }
            axisValueX.add(new AxisValue(i, dateTime.toCharArray()));
        }
    }

    Axis axisX = new Axis().setValues(axisValueX).setHasLines(true);
    Axis axisY = new Axis().setHasLines(true);
    lineChartData.setAxisXBottom(axisX);
    lineChartData.setAxisYLeft(axisY);
    lineChartData.setValueLabelTextSize(8);
    lineChartData.setValueLabelsTextColor(ColorUtil.EXCELLENT);

    return lineChartData;
}

If I have to set the Viewport?

from hellocharts-android.

lecho avatar lecho commented on July 22, 2024

Oh, I think now I understand. When all chart's entries have the same value there is no difference between min and max value so viewport's height is equal 0. So yes, you need to modify viewport.

//set chart data to initialize viewport, otherwise it will be[0,0;0,0]
//get initialized viewport and change if ranges according to your needs.
final Viewport v = new Viewport(chart.getMaximumViewport());
v.top =100;
v.bottom = 0; 
chart.setMaximumViewport(v);
chart.setCurrentViewport(v);
//Optional step: disable viewport recalculations, thanks to this animations will not change viewport automatically.
//chart.setViewportCalculationEnabled(false);

Check out LineChartActivity in samples, specifically method LineChartActivity.resetViewport() for more code.

from hellocharts-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.