lecho.lib.hellocharts.model.SubcolumnValue Java Examples

The following examples show how to use lecho.lib.hellocharts.model.SubcolumnValue. 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: 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 #2
Source File: BasalChart.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static List<Column> getColumns(@ColorInt int color) {
    final List<Column> columns = new ArrayList<>();
    for (int i = 0; i < segments; i++) {

        final List<SubcolumnValue> values = new ArrayList<>();
        SubcolumnValue val = new SubcolumnValue(((float) ((int) (Math.random() * 10f))) / 10 + 0, color);

        setLabelForSubcolumn(val);
        values.add(val);
        // SubcolumnValue valBehind = new SubcolumnValue(val.getValue(), Color.GREEN);
        //setLabelForSubcolumn(val);
        // values.add(valBehind);

        final Column column = new Column(values);
        column.setHasImmutable(true);
        column.setHasLabels(true);
        column.setHasLabelsOnlyForSelected(true);
        columns.add(column);
    }

    return columns;
}
 
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: BasalChart.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static List<Column> getColumns(@ColorInt int color) {
    final List<Column> columns = new ArrayList<>();
    for (int i = 0; i < segments; i++) {

        final List<SubcolumnValue> values = new ArrayList<>();
        SubcolumnValue val = new SubcolumnValue(((float) ((int) (Math.random() * 10f))) / 10 + 0, color);

        setLabelForSubcolumn(val);
        values.add(val);
        // SubcolumnValue valBehind = new SubcolumnValue(val.getValue(), Color.GREEN);
        //setLabelForSubcolumn(val);
        // values.add(valBehind);

        final Column column = new Column(values);
        column.setHasImmutable(true);
        column.setHasLabels(true);
        column.setHasLabelsOnlyForSelected(true);
        columns.add(column);
    }

    return columns;
}
 
Example #5
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 #6
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 #7
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void calculateRectToDraw(SubcolumnValue columnValue, float left, float right, float rawBaseY, float rawY) {
    // Calculate rect that will be drawn as column, subcolumn or label background.
    drawRect.left = left;
    drawRect.right = right;
    if (columnValue.getValue() >= baseValue) {
        drawRect.top = rawY;
        drawRect.bottom = rawBaseY - subcolumnSpacing;
    } else {
        drawRect.bottom = rawY;
        drawRect.top = rawBaseY + subcolumnSpacing;
    }
}
 
Example #8
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void highlightSubcolumn(Canvas canvas, Column column, SubcolumnValue columnValue, int valueIndex,
                                boolean isStacked) {
    if (selectedValue.getSecondIndex() == valueIndex) {
        columnPaint.setColor(columnValue.getDarkenColor());
        canvas.drawRect(drawRect.left - touchAdditionalWidth, drawRect.top, drawRect.right + touchAdditionalWidth,
                drawRect.bottom, columnPaint);
        if (column.hasLabels() || column.hasLabelsOnlyForSelected()) {
            drawLabel(canvas, column, columnValue, isStacked, labelOffset);
        }
    }
}
 
Example #9
Source File: ColumnChartRenderer.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
private void processColumnForStacked(Canvas canvas, Column column, float columnWidth, int columnIndex, int mode) {
    final float rawX = computator.computeRawX(columnIndex);
    final float halfColumnWidth = columnWidth / 2;
    float mostPositiveValue = baseValue;
    float mostNegativeValue = baseValue;
    float subcolumnBaseValue = baseValue;
    int valueIndex = 0;
    for (SubcolumnValue columnValue : column.getValues()) {
        columnPaint.setColor(columnValue.getColor());
        if (columnValue.getValue() >= baseValue) {
            // Using values instead of raw pixels make code easier to
            // understand(for me)
            subcolumnBaseValue = mostPositiveValue;
            mostPositiveValue += columnValue.getValue();
        } else {
            subcolumnBaseValue = mostNegativeValue;
            mostNegativeValue += columnValue.getValue();
        }
        final float rawBaseY = computator.computeRawY(subcolumnBaseValue);
        final float rawY = computator.computeRawY(subcolumnBaseValue + columnValue.getValue());
        calculateRectToDraw(columnValue, rawX - halfColumnWidth, rawX + halfColumnWidth, rawBaseY, rawY);
        switch (mode) {
            case MODE_DRAW:
                drawSubcolumn(canvas, column, columnValue, true);
                break;
            case MODE_HIGHLIGHT:
                highlightSubcolumn(canvas, column, columnValue, valueIndex, true);
                break;
            case MODE_CHECK_TOUCH:
                checkRectToDraw(columnIndex, valueIndex);
                break;
            default:
                // There no else, every case should be handled or exception will
                // be thrown
                throw new IllegalStateException("Cannot process column in mode: " + mode);
        }
        ++valueIndex;
    }
}
 
Example #10
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: ColumnChartView.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
@Override
public void callTouchListener() {
    SelectedValue selectedValue = chartRenderer.getSelectedValue();

    if (selectedValue.isSet()) {
        SubcolumnValue value = data.getColumns().get(selectedValue.getFirstIndex()).getValues()
                .get(selectedValue.getSecondIndex());
        onValueTouchListener.onValueSelected(selectedValue.getFirstIndex(), selectedValue.getSecondIndex(), value);
    } else {
        onValueTouchListener.onValueDeselected();
    }
}
 
Example #16
Source File: ColumnChartActivity.java    From hellocharts-android with Apache License 2.0 5 votes vote down vote up
/**
 * To animate values you have to change targets values and then call {@link Chart#startDataAnimation()}
 * method(don't confuse with View.animate()).
 */
private void prepareDataAnimation() {
    for (Column column : data.getColumns()) {
        for (SubcolumnValue value : column.getValues()) {
            value.setTarget((float) Math.random() * 100);
        }
    }
}
 
Example #17
Source File: BasalProfileEditor.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onAnimationFinished() {
    UserError.Log.d(TAG, "Animation finished");

    // TODO DO ALL COLUMNS??
    for (int col : getSelectColumnList()) {
        final SubcolumnValue v = chart.getChartData().getColumns().get(col).getValues().get(0);
        BasalChart.setLabelForSubcolumn(v);
    }

    refreshScreenElements();
    controlsLocked = false;
}
 
Example #18
Source File: BasalProfileEditor.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void adjustSelectedColumns(final float adjust, final boolean set) {
    if (controlsLocked) {
        UserError.Log.d(TAG, "controls locked");
        return;
    }
    final List<SubcolumnValue> changed = new ArrayList<>(48);
    for (int col : getSelectColumnList()) {
        final SubcolumnValue v = chart.getChartData().getColumns().get(col).getValues().get(0);
        if (set) {
            //v.setValue(Math.max(0, adjust));
            v.setTarget(Math.max(0, adjust));
        } else {
            //v.setValue(Math.max(0, v.getValue() + adjust));
            v.setTarget(Math.max(0, v.getValue() + adjust));
            UserError.Log.d(TAG, "SET TARGET: " + v.getValue());
        }

        changed.add(v);
    }
  /*  Inevitable.stackableTask("refresh-columns", 100, new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 15; i++) {
                for (SubcolumnValue v : changed) {
                    BasalChart.setLabelForSubcolumn(v);
                  //  refreshScreenElements();
                    JoH.threadSleep(100);
                }

            }
        }
    });
    //BasalChart.refreshAxis(chart.getChartData());*/

    chart.startDataAnimation(); // best way to refresh? seems to reset zoom
}
 
Example #19
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;
}
 
Example #20
Source File: BasalProfileEditor.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onAnimationFinished() {
    UserError.Log.d(TAG, "Animation finished");

    // TODO DO ALL COLUMNS??
    for (int col : getSelectColumnList()) {
        final SubcolumnValue v = chart.getChartData().getColumns().get(col).getValues().get(0);
        BasalChart.setLabelForSubcolumn(v);
    }

    refreshScreenElements();
    controlsLocked = false;
}
 
Example #21
Source File: BasalProfileEditor.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void adjustSelectedColumns(final float adjust, final boolean set) {
    if (controlsLocked) {
        UserError.Log.d(TAG, "controls locked");
        return;
    }
    final List<SubcolumnValue> changed = new ArrayList<>(48);
    for (int col : getSelectColumnList()) {
        final SubcolumnValue v = chart.getChartData().getColumns().get(col).getValues().get(0);
        if (set) {
            //v.setValue(Math.max(0, adjust));
            v.setTarget(Math.max(0, adjust));
        } else {
            //v.setValue(Math.max(0, v.getValue() + adjust));
            v.setTarget(Math.max(0, v.getValue() + adjust));
            UserError.Log.d(TAG, "SET TARGET: " + v.getValue());
        }

        changed.add(v);
    }
  /*  Inevitable.stackableTask("refresh-columns", 100, new Runnable() {
        @Override
        public void run() {
            for (int i = 0; i < 15; i++) {
                for (SubcolumnValue v : changed) {
                    BasalChart.setLabelForSubcolumn(v);
                  //  refreshScreenElements();
                    JoH.threadSleep(100);
                }

            }
        }
    });
    //BasalChart.refreshAxis(chart.getChartData());*/

    chart.startDataAnimation(); // best way to refresh? seems to reset zoom
}
 
Example #22
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 #23
Source File: StatisticsFragment.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
private void outputAttachmentStats(List<Integer> attachments) {
    int i = 0;
    for (Column column : getBinding().ccvAttachment.getChartData().getColumns()) {
        for (SubcolumnValue subcolumnValue : column.getValues()) {
            subcolumnValue.setTarget(attachments.get(i));
        }
        i++;
    }
    getBinding().ccvAttachment.startDataAnimation();
}
 
Example #24
Source File: StatisticsFragment.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
private void outputModelsStats(List<Integer> addedModels) {
    int i = 0;
    for (Column column : getBinding().ccvModels.getChartData().getColumns()) {
        for (SubcolumnValue subcolumnValue : column.getValues()) {
            subcolumnValue.setTarget(addedModels.get(i));
        }
        i++;
    }
    getBinding().ccvModels.startDataAnimation();
}
 
Example #25
Source File: ColumnChartActivity.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onValueSelected(int columnIndex, int subcolumnIndex, SubcolumnValue value) {
    Toast.makeText(getActivity(), "Selected: " + value, Toast.LENGTH_SHORT).show();
}
 
Example #26
Source File: LineColumnDependencyActivity.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onValueSelected(int columnIndex, int subcolumnIndex, SubcolumnValue value) {
    generateLineData(value.getColor(), 100);
}
 
Example #27
Source File: ColumnChartActivity.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
private void generateNegativeStackedData() {

            int numSubcolumns = 4;
            int numColumns = 8;
            // Column can have many stacked subcolumns, here I use 4 stacke subcolumn in each of 4 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) {
                    int sign = getSign();
                    values.add(new SubcolumnValue((float) Math.random() * 20f * sign + 5 * sign, ChartUtils.pickColor()));
                }

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

            data = new ColumnChartData(columns);

            // Set stacked flag.
            data.setStacked(true);

            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 #28
Source File: ColumnChartActivity.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
/**
 * Generates columns with stacked subcolumns.
 */
private void generateStackedData() {
    int numSubcolumns = 4;
    int numColumns = 8;
    // Column can have many stacked subcolumns, here I use 4 stacke subcolumn in each of 4 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() * 20f + 5, ChartUtils.pickColor()));
        }

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

    data = new ColumnChartData(columns);

    // Set stacked flag.
    data.setStacked(true);

    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 #29
Source File: ComboLineColumnChartActivity.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onColumnValueSelected(int columnIndex, int subcolumnIndex, SubcolumnValue value) {
    Toast.makeText(getActivity(), "Selected column: " + value, Toast.LENGTH_SHORT).show();
}
 
Example #30
Source File: LineColumnDependencyActivity.java    From hellocharts-android with Apache License 2.0 4 votes vote down vote up
private void generateColumnData() {

            int numSubcolumns = 1;
            int numColumns = months.length;

            List<AxisValue> axisValues = new ArrayList<AxisValue>();
            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()));
                }

                axisValues.add(new AxisValue(i).setLabel(months[i]));

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

            columnData = new ColumnChartData(columns);

            columnData.setAxisXBottom(new Axis(axisValues).setHasLines(true));
            columnData.setAxisYLeft(new Axis().setHasLines(true).setMaxLabelChars(2));

            chartBottom.setColumnChartData(columnData);

            // Set value touch listener that will trigger changes for chartTop.
            chartBottom.setOnValueTouchListener(new ValueTouchListener());

            // Set selection mode to keep selected month column highlighted.
            chartBottom.setValueSelectionEnabled(true);

            chartBottom.setZoomType(ZoomType.HORIZONTAL);

            // chartBottom.setOnClickListener(new View.OnClickListener() {
            //
            // @Override
            // public void onClick(View v) {
            // SelectedValue sv = chartBottom.getSelectedValue();
            // if (!sv.isSet()) {
            // generateInitialLineData();
            // }
            //
            // }
            // });

        }