lecho.lib.hellocharts.model.ColumnChartData Java Examples

The following examples show how to use lecho.lib.hellocharts.model.ColumnChartData. 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: StatisticViewModel.java    From OmniList with GNU Affero General Public License v3.0 6 votes vote down vote up
public ColumnChartData getDefaultModelsData() {
    ColumnChartData data = new ColumnChartData(Arrays.asList(
            getColumn(DEFAULT_TOTAL_VALUE, PalmApp.getColorCompact(R.color.md_lime_600)),
            getColumn(DEFAULT_TOTAL_VALUE, PalmApp.getColorCompact(R.color.md_light_blue_500)),
            getColumn(DEFAULT_TOTAL_VALUE, PalmApp.getColorCompact(R.color.md_green_600)),
            getColumn(DEFAULT_TOTAL_VALUE, PalmApp.getColorCompact(R.color.md_pink_500)),
            getColumn(DEFAULT_TOTAL_VALUE, PalmApp.getColorCompact(R.color.md_red_500))));

    Axis axisX = Axis.generateAxisFromCollection(Arrays.asList(0.0f, 1.0f, 2.0f, 3.0f, 4.0f),
            Arrays.asList(PalmApp.getStringCompact(R.string.model_name_category),
                    PalmApp.getStringCompact(R.string.model_name_assignment),
                    PalmApp.getStringCompact(R.string.model_name_sub_assignment),
                    PalmApp.getStringCompact(R.string.model_name_attachment),
                    PalmApp.getStringCompact(R.string.model_name_location)));

    data.setAxisXBottom(axisX);
    data.setAxisYLeft(null);

    return data;
}
 
Example #2
Source File: StatisticViewModel.java    From OmniList with GNU Affero General Public License v3.0 6 votes vote down vote up
public ColumnChartData getDefaultAttachmentData() {
    ColumnChartData data = new ColumnChartData(Arrays.asList(
            getColumn(DEFAULT_TOTAL_VALUE, PalmApp.getColorCompact(R.color.md_lime_600)),
            getColumn(DEFAULT_TOTAL_VALUE, PalmApp.getColorCompact(R.color.md_light_blue_500)),
            getColumn(DEFAULT_TOTAL_VALUE, PalmApp.getColorCompact(R.color.md_pink_500)),
            getColumn(DEFAULT_TOTAL_VALUE, PalmApp.getColorCompact(R.color.md_green_600)),
            getColumn(DEFAULT_TOTAL_VALUE, PalmApp.getColorCompact(R.color.md_red_500))));

    Axis axisX = Axis.generateAxisFromCollection(Arrays.asList(0.0f, 1.0f, 2.0f, 3.0f, 4.0f),
            Arrays.asList(PalmApp.getStringCompact(R.string.attachment_type_files),
                    PalmApp.getStringCompact(R.string.attachment_type_images),
                    PalmApp.getStringCompact(R.string.attachment_type_sketches),
                    PalmApp.getStringCompact(R.string.attachment_type_videos),
                    PalmApp.getStringCompact(R.string.attachment_type_recordings)));

    data.setAxisXBottom(axisX);
    data.setAxisYLeft(null);

    return data;
}
 
Example #3
Source File: ComboLineColumnChartActivity.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
private ColumnChartData generateColumnData() {
    int numSubcolumns = 1;
    int numColumns = 12;
    // Column can have many subcolumns, here by default I use 1 subcolumn in each of 8 columns.
    List<Column> columns = new ArrayList<Column>();
    List<SubcolumnValue> values;
    for (int i = 0; i < numColumns; ++i) {

        values = new ArrayList<SubcolumnValue>();
        for (int j = 0; j < numSubcolumns; ++j) {
            values.add(new SubcolumnValue((float) Math.random() * 50 + 5, ChartUtils.COLOR_GREEN));
        }

        columns.add(new Column(values));
    }

    ColumnChartData columnChartData = new ColumnChartData(columns);
    return columnChartData;
}
 
Example #4
Source File: ViewPagerChartsActivity.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
private ColumnChartData generateColumnChartData() {
    int numSubcolumns = 1;
    int numColumns = 12;
    // Column can have many subcolumns, here by default I use 1 subcolumn in each of 8 columns.
    List<Column> columns = new ArrayList<Column>();
    List<SubcolumnValue> values;
    for (int i = 0; i < numColumns; ++i) {

        values = new ArrayList<SubcolumnValue>();
        for (int j = 0; j < numSubcolumns; ++j) {
            values.add(new SubcolumnValue((float) Math.random() * 50f + 5, ChartUtils.pickColor()));
        }

        columns.add(new Column(values));
    }

    ColumnChartData data = new ColumnChartData(columns);

    data.setAxisXBottom(new Axis().setName("Axis X"));
    data.setAxisYLeft(new Axis().setName("Axis Y").setHasLines(true));
    return data;

}
 
Example #5
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 6 votes vote down vote up
private void calculateMaxViewportForStacked(ColumnChartData data) {
    for (Column column : data.getColumns()) {
        float sumPositive = baseValue;
        float sumNegative = baseValue;
        for (SubcolumnValue columnValue : column.getValues()) {
            if (columnValue.getValue() >= baseValue) {
                sumPositive += columnValue.getValue();
            } else {
                sumNegative += columnValue.getValue();
            }
        }
        if (sumPositive > tempMaximumViewport.top) {
            tempMaximumViewport.top = sumPositive;
        }
        if (sumNegative < tempMaximumViewport.bottom) {
            tempMaximumViewport.bottom = sumNegative;
        }
    }
}
 
Example #6
Source File: PreviewColumnChartView.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
public PreviewColumnChartView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    chartComputator = new PreviewChartComputator();
    previewChartRenderer = new PreviewColumnChartRenderer(context, this, this);
    touchHandler = new PreviewChartTouchHandler(context, this);
    setChartRenderer(previewChartRenderer);
    setColumnChartData(ColumnChartData.generateDummyData());
}
 
Example #7
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onChartDataChanged() {
    super.onChartDataChanged();
    ColumnChartData data = dataProvider.getColumnChartData();
    fillRatio = data.getFillRatio();
    baseValue = data.getBaseValue();

    onChartViewportChanged();
}
 
Example #8
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 #9
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
public void draw(Canvas canvas) {
    final ColumnChartData data = dataProvider.getColumnChartData();
    if (data.isStacked()) {
        drawColumnForStacked(canvas);
        if (isTouched()) {
            highlightColumnForStacked(canvas);
        }
    } else {
        drawColumnsForSubcolumns(canvas);
        if (isTouched()) {
            highlightColumnsForSubcolumns(canvas);
        }
    }
}
 
Example #10
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
public boolean checkTouch(float touchX, float touchY) {
    selectedValue.clear();
    final ColumnChartData data = dataProvider.getColumnChartData();
    if (data.isStacked()) {
        checkTouchForStacked(touchX, touchY);
    } else {
        checkTouchForSubcolumns(touchX, touchY);
    }
    return isTouched();
}
 
Example #11
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void calculateMaxViewport() {
    final ColumnChartData data = dataProvider.getColumnChartData();
    // Column chart always has X values from 0 to numColumns-1, to add some margin on the left and right I added
    // extra 0.5 to the each side, that margins will be negative scaled according to number of columns, so for more
    // columns there will be less margin.
    tempMaximumViewport.set(-0.5f, baseValue, data.getColumns().size() - 0.5f, baseValue);
    if (data.isStacked()) {
        calculateMaxViewportForStacked(data);
    } else {
        calculateMaxViewportForSubcolumns(data);
    }
}
 
Example #12
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void calculateMaxViewportForSubcolumns(ColumnChartData data) {
    for (Column column : data.getColumns()) {
        for (SubcolumnValue columnValue : column.getValues()) {
            if (columnValue.getValue() >= baseValue && columnValue.getValue() > tempMaximumViewport.top) {
                tempMaximumViewport.top = columnValue.getValue();
            }
            if (columnValue.getValue() < baseValue && columnValue.getValue() < tempMaximumViewport.bottom) {
                tempMaximumViewport.bottom = columnValue.getValue();
            }
        }
    }
}
 
Example #13
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void drawColumnsForSubcolumns(Canvas canvas) {
    final ColumnChartData data = dataProvider.getColumnChartData();
    final float columnWidth = calculateColumnWidth();
    int columnIndex = 0;
    for (Column column : data.getColumns()) {
        processColumnForSubcolumns(canvas, column, columnWidth, columnIndex, MODE_DRAW);
        ++columnIndex;
    }
}
 
Example #14
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void checkTouchForSubcolumns(float touchX, float touchY) {
    // Using member variable to hold touch point to avoid too much parameters in methods.
    touchedPoint.x = touchX;
    touchedPoint.y = touchY;
    final ColumnChartData data = dataProvider.getColumnChartData();
    final float columnWidth = calculateColumnWidth();
    int columnIndex = 0;
    for (Column column : data.getColumns()) {
        // canvas is not needed for checking touch
        processColumnForSubcolumns(null, column, columnWidth, columnIndex, MODE_CHECK_TOUCH);
        ++columnIndex;
    }
}
 
Example #15
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void drawColumnForStacked(Canvas canvas) {
    final ColumnChartData data = dataProvider.getColumnChartData();
    final float columnWidth = calculateColumnWidth();
    // Columns are indexes from 0 to n, column index is also column X value
    int columnIndex = 0;
    for (Column column : data.getColumns()) {
        processColumnForStacked(canvas, column, columnWidth, columnIndex, MODE_DRAW);
        ++columnIndex;
    }
}
 
Example #16
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void highlightColumnForStacked(Canvas canvas) {
    final ColumnChartData data = dataProvider.getColumnChartData();
    final float columnWidth = calculateColumnWidth();
    // Columns are indexes from 0 to n, column index is also column X value
    Column column = data.getColumns().get(selectedValue.getFirstIndex());
    processColumnForStacked(canvas, column, columnWidth, selectedValue.getFirstIndex(), MODE_HIGHLIGHT);
}
 
Example #17
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void checkTouchForStacked(float touchX, float touchY) {
    touchedPoint.x = touchX;
    touchedPoint.y = touchY;
    final ColumnChartData data = dataProvider.getColumnChartData();
    final float columnWidth = calculateColumnWidth();
    int columnIndex = 0;
    for (Column column : data.getColumns()) {
        // canvas is not needed for checking touch
        processColumnForStacked(null, column, columnWidth, columnIndex, MODE_CHECK_TOUCH);
        ++columnIndex;
    }
}
 
Example #18
Source File: PreviewColumnChartActivity.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void generateDefaultData() {
    int numSubcolumns = 1;
    int numColumns = 50;
    List<Column> columns = new ArrayList<Column>();
    List<SubcolumnValue> values;
    for (int i = 0; i < numColumns; ++i) {

        values = new ArrayList<SubcolumnValue>();
        for (int j = 0; j < numSubcolumns; ++j) {
            values.add(new SubcolumnValue((float) Math.random() * 50f + 5, ChartUtils.pickColor()));
        }

        columns.add(new Column(values));
    }

    data = new ColumnChartData(columns);
    data.setAxisXBottom(new Axis());
    data.setAxisYLeft(new Axis().setHasLines(true));

    // prepare preview data, is better to use separate deep copy for preview chart.
    // set color to grey to make preview area more visible.
    previewData = new ColumnChartData(data);
    for (Column column : previewData.getColumns()) {
        for (SubcolumnValue value : column.getValues()) {
            value.setColor(ChartUtils.DEFAULT_DARKEN_COLOR);
        }
    }

}
 
Example #19
Source File: ColumnChartActivity.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void generateDefaultData() {
    int numSubcolumns = 1;
    int numColumns = 8;
    // Column can have many subcolumns, here by default I use 1 subcolumn in each of 8 columns.
    List<Column> columns = new ArrayList<Column>();
    List<SubcolumnValue> values;
    for (int i = 0; i < numColumns; ++i) {

        values = new ArrayList<SubcolumnValue>();
        for (int j = 0; j < numSubcolumns; ++j) {
            values.add(new SubcolumnValue((float) Math.random() * 50f + 5, ChartUtils.pickColor()));
        }

        Column column = new Column(values);
        column.setHasLabels(hasLabels);
        column.setHasLabelsOnlyForSelected(hasLabelForSelected);
        columns.add(column);
    }

    data = new ColumnChartData(columns);

    if (hasAxes) {
        Axis axisX = new Axis();
        Axis axisY = new Axis().setHasLines(true);
        if (hasAxesNames) {
            axisX.setName("Axis X");
            axisY.setName("Axis Y");
        }
        data.setAxisXBottom(axisX);
        data.setAxisYLeft(axisY);
    } else {
        data.setAxisXBottom(null);
        data.setAxisYLeft(null);
    }

    chart.setColumnChartData(data);

}
 
Example #20
Source File: ColumnChartActivity.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
/**
 * Generates columns with subcolumns, columns have larger separation than subcolumns.
 */
private void generateSubcolumnsData() {
    int numSubcolumns = 4;
    int numColumns = 4;
    // Column can have many subcolumns, here I use 4 subcolumn in each of 8 columns.
    List<Column> columns = new ArrayList<Column>();
    List<SubcolumnValue> values;
    for (int i = 0; i < numColumns; ++i) {

        values = new ArrayList<SubcolumnValue>();
        for (int j = 0; j < numSubcolumns; ++j) {
            values.add(new SubcolumnValue((float) Math.random() * 50f + 5, ChartUtils.pickColor()));
        }

        Column column = new Column(values);
        column.setHasLabels(hasLabels);
        column.setHasLabelsOnlyForSelected(hasLabelForSelected);
        columns.add(column);
    }

    data = new ColumnChartData(columns);

    if (hasAxes) {
        Axis axisX = new Axis();
        Axis axisY = new Axis().setHasLines(true);
        if (hasAxesNames) {
            axisX.setName("Axis X");
            axisY.setName("Axis Y");
        }
        data.setAxisXBottom(axisX);
        data.setAxisYLeft(axisY);
    } else {
        data.setAxisXBottom(null);
        data.setAxisYLeft(null);
    }

    chart.setColumnChartData(data);

}
 
Example #21
Source File: ColumnChartActivity.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void generateNegativeSubcolumnsData() {

            int numSubcolumns = 4;
            int numColumns = 4;
            List<Column> columns = new ArrayList<Column>();
            List<SubcolumnValue> values;
            for (int i = 0; i < numColumns; ++i) {

                values = new ArrayList<SubcolumnValue>();
                for (int j = 0; j < numSubcolumns; ++j) {
                    int sign = getSign();
                    values.add(new SubcolumnValue((float) Math.random() * 50f * sign + 5 * sign, ChartUtils.pickColor
                            ()));
                }

                Column column = new Column(values);
                column.setHasLabels(hasLabels);
                column.setHasLabelsOnlyForSelected(hasLabelForSelected);
                columns.add(column);
            }

            data = new ColumnChartData(columns);

            if (hasAxes) {
                Axis axisX = new Axis();
                Axis axisY = new Axis().setHasLines(true);
                if (hasAxesNames) {
                    axisX.setName("Axis X");
                    axisY.setName("Axis Y");
                }
                data.setAxisXBottom(axisX);
                data.setAxisYLeft(axisY);
            } else {
                data.setAxisXBottom(null);
                data.setAxisYLeft(null);
            }

            chart.setColumnChartData(data);
        }
 
Example #22
Source File: ColumnChartView.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
@Override
public void setColumnChartData(ColumnChartData data) {
    if (BuildConfig.DEBUG) {
        Log.d(TAG, "Setting data for ColumnChartView");
    }

    if (null == data) {
        this.data = ColumnChartData.generateDummyData();
    } else {
        this.data = data;
    }

    super.onChartDataChange();

}
 
Example #23
Source File: BasalChart.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static float getTotalBasal(final ColumnChartData columnChartData) {
    float total = 0;
    for (final Column column : columnChartData.getColumns()) {
        total += column.getValues().get(0).getValue();
    }
    return total;
}
 
Example #24
Source File: BasalChart.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static float getTotalImmutableBasal(final ColumnChartData columnChartData) {
    float total = 0;
    for (final Column column : columnChartData.getColumns()) {
        total += column.getValues().get(0).getImmutableOriginValue();
    }
    return total;
}
 
Example #25
Source File: MainActivity.java    From HAPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPostExecute(ColumnChartData result) {
    //Write some code you want to execute on UI after doInBackground() completes
    iobcobchartLoading.setVisibility(View.GONE);
    iobcobChart.setVisibility(View.VISIBLE);
    iobcobChart.setColumnChartData(result);
}
 
Example #26
Source File: MainActivity.java    From HAPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected ColumnChartData doInBackground(ColumnChartData... arg0) {
    Realm realm = new RealmManager().getRealm();
    ColumnChartData columnChartData;
    try {
        iobcobBarGraph  = new IOBCOBBarGraph(realm);
        columnChartData = iobcobBarGraph.iobcobFutureChart();
    } finally {
        realm.close();
    }
    return columnChartData;
}
 
Example #27
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 #28
Source File: BasalChart.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static float getMaxYvalue(ColumnChartData lineData) {
    float max_height = 0.2f;
    for (Column col : lineData.getColumns()) {
        final SubcolumnValue sub = col.getValues().get(0);
        final float val = Math.max(sub.getValue(), sub.getImmutableOriginValue());
        if (val > max_height) {
            max_height = val;
        }
    }
    return max_height;
}
 
Example #29
Source File: BasalChart.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static float getTotalImmutableBasal(final ColumnChartData columnChartData) {
    float total = 0;
    for (final Column column : columnChartData.getColumns()) {
        total += column.getValues().get(0).getImmutableOriginValue();
    }
    return total;
}
 
Example #30
Source File: BasalChart.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static float getMaxYvalue(ColumnChartData lineData) {
    float max_height = 0.2f;
    for (Column col : lineData.getColumns()) {
        final SubcolumnValue sub = col.getValues().get(0);
        final float val = Math.max(sub.getValue(), sub.getImmutableOriginValue());
        if (val > max_height) {
            max_height = val;
        }
    }
    return max_height;
}