lecho.lib.hellocharts.model.AxisValue Java Examples

The following examples show how to use lecho.lib.hellocharts.model.AxisValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BgGraphBuilder.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private Axis xAxis() {
    List<AxisValue> axisValues = new ArrayList<AxisValue>();
    final java.text.DateFormat timeFormat = hourFormat();
    timeFormat.setTimeZone(TimeZone.getDefault());
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTimeInMillis(start_time);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    if (calendar.getTimeInMillis()<start_time){
        calendar.add(Calendar.HOUR, 1);
    }
    while (calendar.getTimeInMillis()<end_time){
        axisValues.add(new AxisValue((calendar.getTimeInMillis() / FUZZER), (timeFormat.format(calendar.getTimeInMillis())).toCharArray()));
        calendar.add(Calendar.HOUR, 1);
    }
    Axis axis = new Axis();
    axis.setValues(axisValues);
    axis.setHasLines(true);
    return axis;
}
 
Example #2
Source File: MetricAvailabilityFragment.java    From hawkular-android-client with Apache License 2.0 6 votes vote down vote up
private List<AxisValue> getChartAxisPoints() {
    List<AxisValue> chartAxisPoints = new ArrayList<>();

    for (int metricDataPoint = 0; metricDataPoint < metricBucket.size();
         metricDataPoint += Defaults.AXIS_INTERVAL) {
        float chartAxisPointHorizontal = metricDataPoint;
        String chartAxisPointLabel;
        switch (timeMenu) {
            case R.id.menu_time_hour:
            case R.id.menu_time_day:
                chartAxisPointLabel = Formatter.formatTime(metricBucket.get(metricDataPoint).getStart());
                break;
            case R.id.menu_time_week:
            case R.id.menu_time_month:
            case R.id.menu_time_year:
            default:
                chartAxisPointLabel = Formatter.formatDate(metricBucket.get(metricDataPoint).getEnd());
        }


        chartAxisPoints.add(new AxisValue(chartAxisPointHorizontal)
                .setLabel(chartAxisPointLabel));
    }

    return chartAxisPoints;
}
 
Example #3
Source File: MetricGaugeFragment.java    From hawkular-android-client with Apache License 2.0 6 votes vote down vote up
private void setUpChartLine() {
    List<PointValue> chartPoints = getChartPoints();
    List<AxisValue> chartAxisPoints = getChartAxisPoints();

    Line chartLine = new Line(chartPoints)
        .setColor(getResources().getColor(R.color.background_primary_dark))
        .setCubic(true)
        .setHasPoints(false);

    LineChartData chartData = new LineChartData()
        .setLines(Collections.singletonList(chartLine));
    chartData.setAxisXBottom(new Axis()
        .setValues(chartAxisPoints));
    chartData.setAxisYLeft(new Axis()
        .setHasLines(true));

    chart.setLineChartData(chartData);
}
 
Example #4
Source File: MetricCounterFragment.java    From hawkular-android-client with Apache License 2.0 6 votes vote down vote up
private void setUpChartLine() {
    List<PointValue> chartPoints = getChartPoints();
    List<AxisValue> chartAxisPoints = getChartAxisPoints();

    Line chartLine = new Line(chartPoints)
            .setColor(getResources().getColor(R.color.background_primary_dark))
            .setCubic(true)
            .setHasPoints(false);

    LineChartData chartData = new LineChartData()
            .setLines(Collections.singletonList(chartLine));
    chartData.setAxisXBottom(new Axis()
            .setValues(chartAxisPoints));
    chartData.setAxisYLeft(new Axis()
            .setHasLines(true));

    chart.setLineChartData(chartData);
}
 
Example #5
Source File: BgGraphBuilder.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private Axis xAxis() {
    List<AxisValue> axisValues = new ArrayList<AxisValue>();
    final java.text.DateFormat timeFormat = hourFormat();
    timeFormat.setTimeZone(TimeZone.getDefault());
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTimeInMillis(start_time);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    if (calendar.getTimeInMillis()<start_time){
        calendar.add(Calendar.HOUR, 1);
    }
    while (calendar.getTimeInMillis()<end_time){
        axisValues.add(new AxisValue((calendar.getTimeInMillis() / FUZZER), (timeFormat.format(calendar.getTimeInMillis())).toCharArray()));
        calendar.add(Calendar.HOUR, 1);
    }
    Axis axis = new Axis();
    axis.setValues(axisValues);
    axis.setHasLines(true);
    return axis;
}
 
Example #6
Source File: BasalChart.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
static public Axis chartYAxis(float max_height) {
    Axis yAxis = new Axis();
    yAxis.setAutoGenerated(false);
    yAxis.setHasLines(true);

    //max_height = max_height * 3;
    final float yStep = chooseClosestStep(max_height / 20f);

    // rounding???

    final List<AxisValue> axisValues = new ArrayList<>();

    // TODO autoscale this - rebuild on data change??
    for (float j = 0; j <= max_height + yStep; j += yStep) {
        axisValues.add(new AxisValue(j));
    }
    yAxis.setValues(axisValues);
    // yAxis.setHasLines(true);
    yAxis.setMaxLabelChars(5);
    yAxis.setInside(false);
    // yAxis.setTextSize(axisTextSize);
    AxisValueFormatter formatter = new SimpleAxisValueFormatter(2);
    yAxis.setFormatter(formatter);
    return yAxis;
}
 
Example #7
Source File: BasalVSTempBasalGraph.java    From HAPP with GNU General Public License v3.0 6 votes vote down vote up
public Axis basalVsTempBasalyAxis() {
    Axis yAxis = new Axis();
    yAxis.setAutoGenerated(false);
    List<AxisValue> axisValues = new ArrayList<>();

    for(double j = -maxBasal.intValue(); j <= maxBasal.intValue(); j += 1) {
        //axisValues.add(new AxisValue((float)fitIOB2COBRange(j)));
        AxisValue value = new AxisValue((float)j);
        if (j==0){
            value.setLabel("Basal");
        } else if (j>0){
            value.setLabel("+" + String.valueOf(j) + "u");
        } else {
            value.setLabel(String.valueOf(j) + "u");
        }
        axisValues.add(value);
    }
    yAxis.setValues(axisValues);
    yAxis.setHasLines(true);
    yAxis.setMaxLabelChars(5);
    yAxis.setInside(true);
    return yAxis;
}
 
Example #8
Source File: BasalChart.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
static public Axis chartYAxis(float max_height) {
    Axis yAxis = new Axis();
    yAxis.setAutoGenerated(false);
    yAxis.setHasLines(true);

    //max_height = max_height * 3;
    final float yStep = chooseClosestStep(max_height / 20f);

    // rounding???

    final List<AxisValue> axisValues = new ArrayList<>();

    // TODO autoscale this - rebuild on data change??
    for (float j = 0; j <= max_height + yStep; j += yStep) {
        axisValues.add(new AxisValue(j));
    }
    yAxis.setValues(axisValues);
    // yAxis.setHasLines(true);
    yAxis.setMaxLabelChars(5);
    yAxis.setInside(false);
    // yAxis.setTextSize(axisTextSize);
    AxisValueFormatter formatter = new SimpleAxisValueFormatter(2);
    yAxis.setFormatter(formatter);
    return yAxis;
}
 
Example #9
Source File: CommonChartSupport.java    From HAPP with GNU General Public License v3.0 6 votes vote down vote up
public Axis iobPastyAxis() {
    Axis yAxis = new Axis();
    yAxis.setAutoGenerated(false);
    List<AxisValue> axisValues = new ArrayList<AxisValue>();

    for(int j = 1; j <= 8; j += 1) {
        //axisValues.add(new AxisValue((float)fitIOB2COBRange(j)));
        AxisValue value = new AxisValue(j*10);
        value.setLabel(String.valueOf(j*2) + "u");
        axisValues.add(value);
    }
    yAxis.setTextColor(ChartUtils.COLOR_BLUE);
    yAxis.setValues(axisValues);
    yAxis.setHasLines(true);
    yAxis.setMaxLabelChars(5);
    yAxis.setInside(true);
    return yAxis;
}
 
Example #10
Source File: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
private Axis xAxis() {
    List<AxisValue> axisValues = new ArrayList<AxisValue>();
    final java.text.DateFormat timeFormat = hourFormat();
    timeFormat.setTimeZone(TimeZone.getDefault());
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTimeInMillis(start_time);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    if (calendar.getTimeInMillis()<start_time){
        calendar.add(Calendar.HOUR, 1);
    }
    while (calendar.getTimeInMillis()<end_time){
        axisValues.add(new AxisValue((calendar.getTimeInMillis() / FUZZER), (timeFormat.format(calendar.getTimeInMillis())).toCharArray()));
        calendar.add(Calendar.HOUR, 1);
    }
    Axis axis = new Axis();
    axis.setValues(axisValues);
    axis.setHasLines(true);
    return axis;
}
 
Example #11
Source File: CommonChartSupport.java    From HAPP with GNU General Public License v3.0 6 votes vote down vote up
public Axis cobPastyAxis() {
    Axis yAxis = new Axis();
    yAxis.setAutoGenerated(false);
    List<AxisValue> axisValues = new ArrayList<AxisValue>();

    for(int j = 1; j <= 8; j += 1) {
        AxisValue value = new AxisValue(j*10);
        value.setLabel(String.valueOf(j*10) + "g");
        axisValues.add(value);
    }
    yAxis.setTextColor(ChartUtils.COLOR_ORANGE);
    yAxis.setValues(axisValues);
    yAxis.setHasLines(true);
    yAxis.setMaxLabelChars(5);
    yAxis.setInside(true);
    return yAxis;
}
 
Example #12
Source File: LineColumnDependencyActivity.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
/**
 * Generates initial data for line chart. At the begining all Y values are equals 0. That will change when user
 * will select value on column chart.
 */
private void generateInitialLineData() {
    int numValues = 7;

    List<AxisValue> axisValues = new ArrayList<AxisValue>();
    List<PointValue> values = new ArrayList<PointValue>();
    for (int i = 0; i < numValues; ++i) {
        values.add(new PointValue(i, 0));
        axisValues.add(new AxisValue(i).setLabel(days[i]));
    }

    Line line = new Line(values);
    line.setColor(ChartUtils.COLOR_GREEN).setCubic(true);

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

    lineData = new LineChartData(lines);
    lineData.setAxisXBottom(new Axis(axisValues).setHasLines(true));
    lineData.setAxisYLeft(new Axis().setHasLines(true).setMaxLabelChars(3));

    chartTop.setLineChartData(lineData);

    // For build-up animation you have to disable viewport recalculation.
    chartTop.setViewportCalculationEnabled(false);

    // And set initial max viewport and current viewport- remember to set viewports after data.
    Viewport v = new Viewport(0, 110, 6, 0);
    chartTop.setMaximumViewport(v);
    chartTop.setCurrentViewport(v);

    chartTop.setZoomType(ZoomType.HORIZONTAL);
}
 
Example #13
Source File: BgGraph.java    From HAPP with GNU General Public License v3.0 5 votes vote down vote up
public Axis previewXAxis() {
    List<AxisValue> previewXaxisValues = new ArrayList<AxisValue>();
    //final java.text.DateFormat timeFormat = hourFormat();
    //timeFormat.setTimeZone(TimeZone.getDefault());
    for (int l = 0; l <= 26; l += hoursPreviewStep) {                                                  //Added 2 hours for future readings
        double timestamp = (endHour - (60000 * 60 * l));
        previewXaxisValues.add(new AxisValue((long) (timestamp), (sdfHour.format(timestamp)).toCharArray()));
    }
    Axis previewXaxis = new Axis();
    previewXaxis.setValues(previewXaxisValues);
    previewXaxis.setHasLines(true);
    previewXaxis.setTextSize(previewAxisTextSize);
    return previewXaxis;
}
 
Example #14
Source File: BgGraphBuilder.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
public Axis previewXAxis(){
    List<AxisValue> previewXaxisValues = new ArrayList<AxisValue>();
    final java.text.DateFormat timeFormat = hourFormat();
    timeFormat.setTimeZone(TimeZone.getDefault());
    for(int l=0; l<=24; l+=hoursPreviewStep) {
        double timestamp = (endHour - (60000 * 60 * l));
        previewXaxisValues.add(new AxisValue((long)(timestamp/fuzz), (timeFormat.format(timestamp)).toCharArray()));
    }
    Axis previewXaxis = new Axis();
    previewXaxis.setValues(previewXaxisValues);
    previewXaxis.setHasLines(true);
    previewXaxis.setTextSize(previewAxisTextSize);
    return previewXaxis;
}
 
Example #15
Source File: BgGraphBuilder.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public Axis previewXAxis(){
    List<AxisValue> previewXaxisValues = new ArrayList<AxisValue>();
    final java.text.DateFormat timeFormat = hourFormat();
    timeFormat.setTimeZone(TimeZone.getDefault());
    for(int l=0; l<=24; l+=hoursPreviewStep) {
        double timestamp = (endHour - (60000 * 60 * l));
        previewXaxisValues.add(new AxisValue((long)(timestamp/fuzzer), (timeFormat.format(timestamp)).toCharArray()));
    }
    Axis previewXaxis = new Axis();
    previewXaxis.setValues(previewXaxisValues);
    previewXaxis.setHasLines(true);
    previewXaxis.setTextSize(previewAxisTextSize);
    return previewXaxis;
}
 
Example #16
Source File: MetricAvailabilityFragment.java    From hawkular-android-client with Apache License 2.0 5 votes vote down vote up
private List<AxisValue> getChartAxisValues() {
    List<AxisValue> chartAxisValues = new ArrayList<>();

    chartAxisValues.add(new AxisValue(getColumnValue(MetricAvailability.UP) / 2)
            .setLabel(getString(R.string.label_availability_up)));
    chartAxisValues.add(new AxisValue(getColumnValue(MetricAvailability.DOWN) / 2)
            .setLabel(getString(R.string.label_availability_down)));

    return chartAxisValues;
}
 
Example #17
Source File: DataChartActivity.java    From Memory-capsule with Apache License 2.0 5 votes vote down vote up
private void initColumnChart(){//创建柱状图
    columnChartView=new ColumnChartView(this);
    int columnWidth=(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,400, getResources().getDisplayMetrics());
    int columnHeigth=(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,400, getResources().getDisplayMetrics());
    RelativeLayout.LayoutParams columnChartParams=new RelativeLayout.LayoutParams(columnWidth,columnHeigth);
    columnChartParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
    columnChartParams.addRule(RelativeLayout.CENTER_VERTICAL);
    List<Column>columnList=new ArrayList<>();
    List<SubcolumnValue> values;
    for (int i=0;i<5;++i){
        values=new ArrayList<SubcolumnValue>();
        values.add(new SubcolumnValue((float)typesNum.get(i),colorData[i]));
        Column column=new Column(values);
        column.setHasLabels(false);
        column.setHasLabelsOnlyForSelected(true);
        columnList.add(column);
    }
    ColumnChartData columnChartData=new ColumnChartData(columnList);
    Axis axis=new Axis();
    Axis axiy=new Axis().setHasLines(true);
    List<AxisValue>axisValues=new ArrayList<>();
    for (int j=0;j<5;++j){
        axisValues.add(new AxisValue(j).setLabel(stateChar[j]));
    }
    axis.setValues(axisValues);
    axis.setName("类别");
    axiy.setName("数量");
    columnChartData.setAxisXBottom(axis);
    columnChartData.setAxisYLeft(axiy);
    columnChartView.setColumnChartData(columnChartData);
    relativeLayout.addView(columnChartView,columnChartParams);
}
 
Example #18
Source File: MetricAvailabilityFragment.java    From hawkular-android-client with Apache License 2.0 5 votes vote down vote up
private void setUpChartColumns() {
    List<Column> chartColumns = getChartColumns();
    List<AxisValue> chartAxisPoints = getChartAxisPoints();
    List<AxisValue> chartAxisValues = getChartAxisValues();

    ColumnChartData chartData = new ColumnChartData()
            .setColumns(chartColumns);
    chartData.setAxisXBottom(new Axis()
            .setValues(chartAxisPoints));
    chartData.setAxisYLeft(new Axis()
            .setValues(chartAxisValues));

    chart.setColumnChartData(chartData);
}
 
Example #19
Source File: BgGraphBuilder.java    From NightWatch with GNU General Public License v3.0 5 votes vote down vote up
public Axis previewXAxis(){
    List<AxisValue> previewXaxisValues = new ArrayList<AxisValue>();
    final java.text.DateFormat timeFormat = hourFormat();
    timeFormat.setTimeZone(TimeZone.getDefault());
    for(int l=0; l<=24; l+=hoursPreviewStep) {
        double timestamp = (endHour - (60000 * 60 * l));
        previewXaxisValues.add(new AxisValue((long)(timestamp/fuzz), (timeFormat.format(timestamp)).toCharArray()));
    }
    Axis previewXaxis = new Axis();
    previewXaxis.setValues(previewXaxisValues);
    previewXaxis.setHasLines(true);
    previewXaxis.setTextSize(previewAxisTextSize);
    return previewXaxis;
}
 
Example #20
Source File: BasalChart.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
static private Axis chartXAxis(int size) {

        final Axis xAxis = new Axis();
        xAxis.setAutoGenerated(false);
        xAxis.setHasTiltedLabels(true);
        xAxis.setTiltAngle(-90f);
        xAxis.setMaxLabelChars(7);

        SimpleDateFormat sdf = new SimpleDateFormat(DateFormat.is24HourFormat(xdrip.getAppContext()) ? "HH:mm" : "a h:mm");

        DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault());
        // OVERRIDE SOME symbols WHILE RETAINING OTHERS
        symbols.setAmPmStrings(new String[] { "a", "p" });
        sdf.setDateFormatSymbols(symbols);

        final java.text.DateFormat timeFormat = sdf;
        timeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        final GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTimeInMillis(JoH.tsl());
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        xAxis.setAutoGenerated(false);

        // TODO make this a better am/pm/24 hour thingy by dividing a day down? DST??? how does that work?? - done on load of value?
        List<AxisValue> axisValues = new ArrayList<>();
        final int step = size / segments;
        final long dayStartMs = calendar.getTimeInMillis();
        final long increment = Constants.DAY_IN_MS / segments;
        for (int i = 0; i < size; i = i + step) {
            calendar.setTimeInMillis(dayStartMs + i*increment);
            axisValues.add(new AxisValue(i / step,  timeFormat.format(calendar.getTimeInMillis()).toCharArray()));
        }
        xAxis.setValues(axisValues);
        return xAxis;
    }
 
Example #21
Source File: BasalChart.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
static private Axis chartXAxis(int size) {

        final Axis xAxis = new Axis();
        xAxis.setAutoGenerated(false);
        xAxis.setHasTiltedLabels(true);
        xAxis.setTiltAngle(-90f);
        xAxis.setMaxLabelChars(7);

        SimpleDateFormat sdf = new SimpleDateFormat(DateFormat.is24HourFormat(xdrip.getAppContext()) ? "HH:mm" : "a h:mm");

        DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault());
        // OVERRIDE SOME symbols WHILE RETAINING OTHERS
        symbols.setAmPmStrings(new String[] { "a", "p" });
        sdf.setDateFormatSymbols(symbols);

        final java.text.DateFormat timeFormat = sdf;
        timeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        final GregorianCalendar calendar = new GregorianCalendar();
        calendar.setTimeInMillis(JoH.tsl());
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        xAxis.setAutoGenerated(false);

        // TODO make this a better am/pm/24 hour thingy by dividing a day down? DST??? how does that work?? - done on load of value?
        List<AxisValue> axisValues = new ArrayList<>();
        final int step = size / segments;
        final long dayStartMs = calendar.getTimeInMillis();
        final long increment = Constants.DAY_IN_MS / segments;
        for (int i = 0; i < size; i = i + step) {
            calendar.setTimeInMillis(dayStartMs + i*increment);
            axisValues.add(new AxisValue(i / step,  timeFormat.format(calendar.getTimeInMillis()).toCharArray()));
        }
        xAxis.setValues(axisValues);
        return xAxis;
    }
 
Example #22
Source File: ClimateFragment.java    From homeassist with Apache License 2.0 5 votes vote down vote up
private Axis getXAxis(ArrayList<DataItem> data) {
    long startTime = data.get(0).getXValue();
    long endTime = data.get(data.size() - 1).getXValue();
    long step = (endTime - startTime) / 10;
    List<AxisValue> xValues = new ArrayList<>();
    SimpleDateFormat df2 = new SimpleDateFormat("HH:mm", Locale.ENGLISH);

    for (long i = startTime; i < endTime; i += step) {
        xValues.add(new AxisValue(i).setLabel(df2.format(new Date(i))));
    }
    xValues.add(new AxisValue(endTime).setLabel(df2.format(new Date(endTime))));
    Axis axisX = new Axis(xValues);
    axisX.setName("Time (Last 24 Hours)");
    return axisX;
}
 
Example #23
Source File: MetricCounterFragment.java    From hawkular-android-client with Apache License 2.0 4 votes vote down vote up
private List<AxisValue> getChartAxisPoints() {
    List<AxisValue> chartAxisPoints = new ArrayList<>();

    Date chartStartTime = getMetricStartTime();
    Date chartFinishTime = getMetricFinishTime();

    Calendar chartCalendar = GregorianCalendar.getInstance();
    chartCalendar.setTime(chartStartTime);
    chartCalendar.set(Calendar.MINUTE, 0);
    chartCalendar.set(Calendar.SECOND, 0);
    chartCalendar.set(Calendar.MILLISECOND, 0);


    while (chartCalendar.getTime().before(chartFinishTime)) {
        float chartAxisPointHorizontal = getChartRelativeTimestamp(chartCalendar.getTime().getTime());
        String chartAxisPointHorizontalLabel = "";

        switch (timeMenu){
            case R.id.menu_time_hour:
                chartAxisPointHorizontalLabel = Formatter.formatTime(chartCalendar.getTime().getTime());

                chartAxisPoints.add(new AxisValue(chartAxisPointHorizontal)
                        .setLabel(chartAxisPointHorizontalLabel));
                chartCalendar.add(Calendar.MINUTE, 1);
                break;

            case R.id.menu_time_day:
                chartAxisPointHorizontalLabel = Formatter.formatTime(chartCalendar.getTime().getTime());

                chartAxisPoints.add(new AxisValue(chartAxisPointHorizontal)
                        .setLabel(chartAxisPointHorizontalLabel));
                chartCalendar.add(Calendar.HOUR, 1);
                break;

            case R.id.menu_time_week:
                chartAxisPointHorizontalLabel = Formatter.formatDate(chartCalendar.getTime().getTime());

                chartAxisPoints.add(new AxisValue(chartAxisPointHorizontal)
                        .setLabel(chartAxisPointHorizontalLabel));
                chartCalendar.add(Calendar.HOUR, 24);
                break;

            case R.id.menu_time_month:
                chartAxisPointHorizontalLabel = Formatter.formatDate(chartCalendar.getTime().getTime());

                chartAxisPoints.add(new AxisValue(chartAxisPointHorizontal)
                        .setLabel(chartAxisPointHorizontalLabel));
                chartCalendar.add(Calendar.HOUR, 24*3);
                break;

            case R.id.menu_time_year:
                chartAxisPointHorizontalLabel = Formatter.formatDate(chartCalendar.getTime().getTime());

                chartAxisPoints.add(new AxisValue(chartAxisPointHorizontal)
                        .setLabel(chartAxisPointHorizontalLabel));
                chartCalendar.add(Calendar.HOUR, 24*7);
                break;

            default:
                chartAxisPointHorizontalLabel = Formatter.formatTime(chartCalendar.getTime().getTime());

                chartAxisPoints.add(new AxisValue(chartAxisPointHorizontal)
                        .setLabel(chartAxisPointHorizontalLabel));
                chartCalendar.add(Calendar.MINUTE, 1);
        }

    }

    return chartAxisPoints;
}
 
Example #24
Source File: MetricGaugeFragment.java    From hawkular-android-client with Apache License 2.0 4 votes vote down vote up
private List<AxisValue> getChartAxisPoints() {
    List<AxisValue> chartAxisPoints = new ArrayList<>();

    Date chartStartTime = getMetricStartTime();
    Date chartFinishTime = getMetricFinishTime();

    Calendar chartCalendar = GregorianCalendar.getInstance();
    chartCalendar.setTime(chartStartTime);
    chartCalendar.set(Calendar.MINUTE, 0);
    chartCalendar.set(Calendar.SECOND, 0);
    chartCalendar.set(Calendar.MILLISECOND, 0);

    while (chartCalendar.getTime().before(chartFinishTime)) {
        float chartAxisPointHorizontal = getChartRelativeTimestamp(chartCalendar.getTime().getTime());
        String chartAxisPointHorizontalLabel = "";

        switch (timeMenu) {
            case R.id.menu_time_hour:
                chartAxisPointHorizontalLabel = Formatter.formatTime(chartCalendar.getTime().getTime());

                chartAxisPoints.add(new AxisValue(chartAxisPointHorizontal)
                        .setLabel(chartAxisPointHorizontalLabel));
                chartCalendar.add(Calendar.MINUTE, 1);
                break;

            case R.id.menu_time_day:
                chartAxisPointHorizontalLabel = Formatter.formatTime(chartCalendar.getTime().getTime());

                chartAxisPoints.add(new AxisValue(chartAxisPointHorizontal)
                        .setLabel(chartAxisPointHorizontalLabel));
                chartCalendar.add(Calendar.HOUR, 1);
                break;

            case R.id.menu_time_week:
                chartAxisPointHorizontalLabel = Formatter.formatDate(chartCalendar.getTime().getTime());

                chartAxisPoints.add(new AxisValue(chartAxisPointHorizontal)
                        .setLabel(chartAxisPointHorizontalLabel));
                chartCalendar.add(Calendar.HOUR, 24);
                break;

            case R.id.menu_time_month:
                chartAxisPointHorizontalLabel = Formatter.formatDate(chartCalendar.getTime().getTime());

                chartAxisPoints.add(new AxisValue(chartAxisPointHorizontal)
                        .setLabel(chartAxisPointHorizontalLabel));
                chartCalendar.add(Calendar.HOUR, 24 * 3);
                break;

            case R.id.menu_time_year:
                chartAxisPointHorizontalLabel = Formatter.formatDate(chartCalendar.getTime().getTime());

                chartAxisPoints.add(new AxisValue(chartAxisPointHorizontal)
                        .setLabel(chartAxisPointHorizontalLabel));
                chartCalendar.add(Calendar.HOUR, 24 * 7);
                break;

            default:
                chartAxisPointHorizontalLabel = Formatter.formatTime(chartCalendar.getTime().getTime());

                chartAxisPoints.add(new AxisValue(chartAxisPointHorizontal)
                        .setLabel(chartAxisPointHorizontalLabel));
                chartCalendar.add(Calendar.MINUTE, 1);
        }

    }

    return chartAxisPoints;
}
 
Example #25
Source File: IOBCOBBarGraph.java    From HAPP with GNU General Public License v3.0 4 votes vote down vote up
public ColumnChartData iobcobFutureChart() {
    Log.d(TAG, "iobcobFutureChart: START");

    if (!statList.isEmpty()) {

        List<Column> columnsData = new ArrayList<>();
        List<SubcolumnValue> values;
        List<AxisValue> xAxisValues = new ArrayList<AxisValue>();

        try {
            for (int v = 0; v < statList.size(); v++) {

                values = new ArrayList<>();

                //IOB
                if (statList.get(v).getIob() > yIOBMax) {
                    values.add(new SubcolumnValue((float) (fitIOB2COBRange(yIOBMax.floatValue())), ChartUtils.COLOR_BLUE));
                } else if (statList.get(v).getIob() < yIOBMin) {
                    values.add(new SubcolumnValue((float) (fitIOB2COBRange(yIOBMin.floatValue())), ChartUtils.COLOR_BLUE));
                } else {
                    values.add(new SubcolumnValue((float) (fitIOB2COBRange(statList.get(v).getIob())), ChartUtils.COLOR_BLUE));
                }
                //COB
                if (statList.get(v).getCob() > yCOBMax) {
                    values.add(new SubcolumnValue((float) (yCOBMax.floatValue()), ChartUtils.COLOR_ORANGE));
                } else {
                    values.add(new SubcolumnValue((float) (statList.get(v).getCob()), ChartUtils.COLOR_ORANGE));
                }

                Column column = new Column(values);
                column.setHasLabels(false);
                columnsData.add(column);

                AxisValue axisValue = new AxisValue(v);
                axisValue.setLabel(statList.get(v).when);
                xAxisValues.add(axisValue);
                //xAxisValues.  add(new AxisValue((long)0, iobcobValues.getJSONObject(v).getString("when")));
            }
        } catch (Exception e) {
            Crashlytics.logException(e);
        }

        columnData = new ColumnChartData(columnsData);
        Axis axisX = new Axis(xAxisValues).setHasLines(true);

        //columnData.setAxisYLeft(ycobiobAxis());
        columnData.setAxisYLeft(iobPastyAxis());
        columnData.setAxisYRight(cobPastyAxis());
        columnData.setAxisXBottom(axisX);

        Log.d(TAG, "iobcobFutureChart: FINISH");
        return columnData;

    } else{
        Log.d(TAG, "iobcobFutureChart: FINISH EMPTY REPLY");
        return new ColumnChartData(); //empty
    }
}
 
Example #26
Source File: LineChartPresenter.java    From MemoryCleaner with Apache License 2.0 4 votes vote down vote up
private void updateViews(int count, float percent) {
    //LineChartData updatedData = new LineChartData();
    mPointValues.add(new PointValue(count, percent));
    mAxisValues.add(
            new AxisValue(count).setLabel(TimeUtils.getSystemDate()));

    if (count > MAX_COUNT) {
        mPointValues.remove(0);
        mAxisValues.remove(0);
    }
    Line line = new Line(mPointValues).setColor(color)
                                      .setCubic(true)
                                      .setFilled(true)
                                      .setHasPoints(false);
    List<Line> lines = new ArrayList<>();
    lines.add(line);
    LineChartData updatedData = new LineChartData();
    updatedData.setLines(lines);
    // 坐标轴
    Axis axisX = new Axis(mAxisValues).setTextColor(color)
                                      .setHasLines(true)
                                      .setLineColor(color)
                                      .setTextSize(9)
                                      .setName("时间(HH:mm:ss)")
                                      .setMaxLabelChars(5); // X轴
    updatedData.setAxisXBottom(axisX);
    Axis axisY = new Axis().setHasLines(true)
                           .setTextColor(color)
                           .setLineColor(color)
                           .setMaxLabelChars(5)
                           .setName("内存占用率(%)"); // Y轴

    // 默认是3,只能看最后三个数字
    updatedData.setAxisYLeft(axisY);
    mLineChart.updateViews(percent, updatedData);
    // 设置行为属性,支持缩放、滑动以及平移
    //final Viewport v = new Viewport(mLineChartView.getMaximumViewport());
    ////v.top =v.top+10; //example max value
    ////v.bottom = v.bottom-10;  //example min value
    ////mLineChartView.setMaximumViewport(v);
    //v.left = v.left + 1; //current viewport will take only part of max viewport horizontally
    //v.right = v.right - 1;
    //mLineChartView.setCurrentViewport(v);
    ////Optional step: disable viewport recalculations, thanks to this animations will not change viewport automatically.
    //mLineChartView.setViewportCalculationEnabled(false);
}
 
Example #27
Source File: MainActivity.java    From healthgo with GNU General Public License v3.0 4 votes vote down vote up
public void drawChart() {

        // WeatherChartView mCharView = (WeatherChartView) findViewById(R.id.line_char);
        Date[] days = DateTimeHelper.get6days();

        Realm realm = Realm.getDefaultInstance();

        int[] data = new int[]{0, 0, 0, 0, 0, 0};
        int i = 0;
        for (Date d : days) {
            Log.d("eee","date "+d);
            if (i == 5) {
                data[i] = Integer.parseInt(String.valueOf(numSteps));
            }
            else {
                StepModel result = realm.where(StepModel.class)
                        .equalTo("date", d)
                        .findFirst();
                if (result != null) {
                    Log.d("eee","r !null  ");
                    data[i] = Integer.parseInt(String.valueOf(result.getNumSteps()));
                }
            }
            i++;
        }

        realm.close();

        String[] xValues = DateTimeHelper.get6days(true);


        lineChart = (LineChartView) findViewById(R.id.line_chart);
        for (i = 0; i < xValues.length; i++) {
            mAxisXValues.add(new AxisValue(i).setLabel(xValues[i]));
        }

        for (i = 0; i < data.length; i++) {
            mPointValues.add(new PointValue(i, data[i]));
        }
        initLineChart();//初始化

    }
 
Example #28
Source File: SimpleAxisValueFormatter.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
@Override
public int formatValueForManualAxis(char[] formattedValue, AxisValue axisValue) {
    final int charsNumber = valueFormatterHelper.formatFloatValueWithPrependedAndAppendedText(formattedValue,
            axisValue.getValue(), axisValue.getLabelAsChars());
    return charsNumber;
}
 
Example #29
Source File: AxesRenderer.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
private void prepareCustomAxis(Axis axis, int position) {
    final Viewport maxViewport = computator.getMaximumViewport();
    final Viewport visibleViewport = computator.getVisibleViewport();
    final Rect contentRect = computator.getContentRectMinusAllMargins();
    boolean isAxisVertical = isAxisVertical(position);
    float viewportMin, viewportMax;
    float scale = 1;
    if (isAxisVertical) {
        if (maxViewport.height() > 0 && visibleViewport.height() > 0) {
            scale = contentRect.height() * (maxViewport.height() / visibleViewport.height());
        }
        viewportMin = visibleViewport.bottom;
        viewportMax = visibleViewport.top;
    } else {
        if (maxViewport.width() > 0 && visibleViewport.width() > 0) {
            scale = contentRect.width() * (maxViewport.width() / visibleViewport.width());
        }
        viewportMin = visibleViewport.left;
        viewportMax = visibleViewport.right;
    }
    if (scale == 0) {
        scale = 1;
    }
    int module = (int) Math.max(1,
            Math.ceil((axis.getValues().size() * labelDimensionForStepsTab[position] * 1.5) / scale));
    //Reinitialize tab to hold lines coordinates.
    if (axis.hasLines() && (linesDrawBufferTab[position].length < axis.getValues().size() * 4)) {
        linesDrawBufferTab[position] = new float[axis.getValues().size() * 4];
    }
    //Reinitialize tabs to hold all raw values to draw.
    if (rawValuesTab[position].length < axis.getValues().size()) {
        rawValuesTab[position] = new float[axis.getValues().size()];
    }
    //Reinitialize tabs to hold all raw values to draw.
    if (valuesToDrawTab[position].length < axis.getValues().size()) {
        valuesToDrawTab[position] = new AxisValue[axis.getValues().size()];
    }

    float rawValue;
    int valueIndex = 0;
    int valueToDrawIndex = 0;
    for (AxisValue axisValue : axis.getValues()) {
        // Draw axis values that are within visible viewport.
        final float value = axisValue.getValue();
        if (value >= viewportMin && value <= viewportMax) {
            // Draw axis values that have 0 module value, this will hide some labels if there is no place for them.
            if (0 == valueIndex % module) {
                if (isAxisVertical) {
                    rawValue = computator.computeRawY(value);
                } else {
                    rawValue = computator.computeRawX(value);
                }
                if (checkRawValue(contentRect, rawValue, axis.isInside(), position, isAxisVertical)) {
                    rawValuesTab[position][valueToDrawIndex] = rawValue;
                    valuesToDrawTab[position][valueToDrawIndex] = axisValue;
                    ++valueToDrawIndex;
                }
            }
            // If within viewport - increment valueIndex;
            ++valueIndex;
        }
    }
    valuesToDrawNumTab[position] = valueToDrawIndex;
}
 
Example #30
Source File: AxesRenderer.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
private void drawAxisLabelsAndName(Canvas canvas, Axis axis, int position) {
    float labelX, labelY;
    labelX = labelY = 0;
    boolean isAxisVertical = isAxisVertical(position);
    if (LEFT == position || RIGHT == position) {
        labelX = labelBaselineTab[position];
    } else if (TOP == position || BOTTOM == position) {
        labelY = labelBaselineTab[position];
    }

    for (int valueToDrawIndex = 0; valueToDrawIndex < valuesToDrawNumTab[position]; ++valueToDrawIndex) {
        int charsNumber = 0;
        if (axis.isAutoGenerated()) {
            final float value = autoValuesToDrawTab[position][valueToDrawIndex];
            charsNumber = axis.getFormatter().formatValueForAutoGeneratedAxis(labelBuffer, value,
                    autoValuesBufferTab[position].decimals);
        } else {
            AxisValue axisValue = valuesToDrawTab[position][valueToDrawIndex];
            charsNumber = axis.getFormatter().formatValueForManualAxis(labelBuffer, axisValue);
        }

        if (isAxisVertical) {
            labelY = rawValuesTab[position][valueToDrawIndex];
        } else {
            labelX = rawValuesTab[position][valueToDrawIndex];
        }

        if (axis.hasTiltedLabels()) {
            canvas.save();
            canvas.translate(tiltedLabelXTranslation[position], tiltedLabelYTranslation[position]);
            canvas.rotate(-45, labelX, labelY);
            canvas.drawText(labelBuffer, labelBuffer.length - charsNumber, charsNumber, labelX, labelY,
                    labelPaintTab[position]);
            canvas.restore();
        } else {
            canvas.drawText(labelBuffer, labelBuffer.length - charsNumber, charsNumber, labelX, labelY,
                    labelPaintTab[position]);
        }
    }

    // Drawing axis name
    final Rect contentRectMargins = computator.getContentRectMinusAxesMargins();
    if (!TextUtils.isEmpty(axis.getName())) {
        if (isAxisVertical) {
            canvas.save();
            canvas.rotate(-90, contentRectMargins.centerY(), contentRectMargins.centerY());
            canvas.drawText(axis.getName(), contentRectMargins.centerY(), nameBaselineTab[position],
                    namePaintTab[position]);
            canvas.restore();
        } else {
            canvas.drawText(axis.getName(), contentRectMargins.centerX(), nameBaselineTab[position],
                    namePaintTab[position]);
        }
    }
}