Java Code Examples for com.github.mikephil.charting.data.BarDataSet#setStackLabels()

The following examples show how to use com.github.mikephil.charting.data.BarDataSet#setStackLabels() . 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: BarChartManager.java    From react-native-mp-android-chart with MIT License 6 votes vote down vote up
@Override
void dataSetConfig(IDataSet<BarEntry> dataSet, ReadableMap config) {
    BarDataSet barDataSet = (BarDataSet) dataSet;

    ChartDataSetConfigUtils.commonConfig(barDataSet, config);
    ChartDataSetConfigUtils.commonBarLineScatterCandleBubbleConfig(barDataSet, config);

    if (BridgeUtils.validate(config, ReadableType.Number, "barSpacePercent")) {
        barDataSet.setBarSpacePercent((float) config.getDouble("barSpacePercent"));
    }
    if (BridgeUtils.validate(config, ReadableType.String, "barShadowColor")) {
        barDataSet.setBarShadowColor(Color.parseColor(config.getString("barShadowColor")));
    }
    if (BridgeUtils.validate(config, ReadableType.Number, "highlightAlpha")) {
        barDataSet.setHighLightAlpha(config.getInt("highlightAlpha"));
    }
    if (BridgeUtils.validate(config, ReadableType.Array, "stackLabels")) {
        barDataSet.setStackLabels(BridgeUtils.convertToStringArray(config.getArray("stackLabels")));
    }
}
 
Example 2
Source File: GraphLayout.java    From voice-pitch-analyzer with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * get bar chart data for male/female vocal ranges
 * to display them as bars beneath other chart data
 *
 * @param amount amount of entries needed
 * @return bar data to add to chart
 */
public static BarDataSet getOverallRange(Context context, int amount)
{
    BarDataSet set = new BarDataSet(GraphLayout.getRangeEntries(amount), "");
    set.setDrawValues(false);
    set.setColors(new int[]{context.getResources().getColor(R.color.male_range),
                            context.getResources().getColor(R.color.androgynous_range),
                            context.getResources().getColor(R.color.female_range)});
    set.setStackLabels(new String[]{context.getResources().getString(R.string.male_range),
                                    context.getResources().getString(R.string.androgynous_range),
                                    context.getResources().getString(R.string.female_range)
    });

    //        List<BarDataSet> setList = new ArrayList<BarDataSet>();
    //        setList.add(set);
    //
    //        return setList;

    return set;
}
 
Example 3
Source File: CombinedChartActivity.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
private BarData generateBarData() {

        ArrayList<BarEntry> entries1 = new ArrayList<>();
        ArrayList<BarEntry> entries2 = new ArrayList<>();

        for (int index = 0; index < count; index++) {
            entries1.add(new BarEntry(0, getRandom(25, 25)));

            // stacked
            entries2.add(new BarEntry(0, new float[]{getRandom(13, 12), getRandom(13, 12)}));
        }

        BarDataSet set1 = new BarDataSet(entries1, "Bar 1");
        set1.setColor(Color.rgb(60, 220, 78));
        set1.setValueTextColor(Color.rgb(60, 220, 78));
        set1.setValueTextSize(10f);
        set1.setAxisDependency(YAxis.AxisDependency.LEFT);

        BarDataSet set2 = new BarDataSet(entries2, "");
        set2.setStackLabels(new String[]{"Stack 1", "Stack 2"});
        set2.setColors(Color.rgb(61, 165, 255), Color.rgb(23, 197, 255));
        set2.setValueTextColor(Color.rgb(61, 165, 255));
        set2.setValueTextSize(10f);
        set2.setAxisDependency(YAxis.AxisDependency.LEFT);

        float groupSpace = 0.06f;
        float barSpace = 0.02f; // x2 dataset
        float barWidth = 0.45f; // x2 dataset
        // (0.45 + 0.02) * 2 + 0.06 = 1.00 -> interval per "group"

        BarData d = new BarData(set1, set2);
        d.setBarWidth(barWidth);

        // make this BarData object grouped
        d.groupBars(0, groupSpace, barSpace); // start at x = 0

        return d;
    }
 
Example 4
Source File: BarChartHelper.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
public IBarDataSet generateBarDataSet(List<BarEntry> entries, String[] describle, List<Integer> colors) {
        BarDataSet dataSet = new BarDataSet(entries, describle.length > 1 ? "" : describle[0]);
        dataSet.setColors(colors);
        dataSet.setStackLabels(describle);
//        dataSet.setValueTextSize(11f);
        int highLightColor = 0x20ffffff;
        dataSet.setHighLightColor(highLightColor);
        return dataSet;
    }
 
Example 5
Source File: StatActivity.java    From ankihelper with GNU General Public License v3.0 5 votes vote down vote up
private void drawHourChart(int[][] data){
//        List<BarEntry> popupEntries = new ArrayList<>();
        List<BarEntry> lookupEntries = new ArrayList<>();
        List<BarEntry> cardaddEntries = new ArrayList<>();
        for(int i = 0; i < 24; i ++){
//            popupEntries.add(new BarEntry(i, data[0][i]));
            lookupEntries.add(new BarEntry(i, new float[] {data[1][i], data[2][i]}));
        }
        BarDataSet barDataSet = new BarDataSet(lookupEntries, "Bar");
        barDataSet.setStackLabels(new String[]{"Lookups", "Cards"});
        barDataSet.setDrawValues(false);
        barDataSet.setColors(DARK_PINK, DARK_GREEN);
        BarData barData = new BarData(barDataSet);
        mHourChart.setData(barData);
        mHourChart.getDescription().setText("hour");
        //mHourChart.getDescription().setTextAlign();
        mHourChart.getXAxis().setDrawGridLines(false);
        mHourChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
        mHourChart.getAxisRight().setEnabled(false);
        //mHourChart.getAxisLeft().setDrawGridLines(false);
        mHourChart.getXAxis().setValueFormatter(
                new IAxisValueFormatter() {
                    @Override
                    public String getFormattedValue(float value, AxisBase axis) {
                        return ((int) value) + "";
                    }
                }
        );
        mHourChart.getXAxis().setLabelCount(24);
        mHourChart.getXAxis().setAxisMinimum(-0.5f);
        mHourChart.getXAxis().setAxisMaximum(23.5f);
        mHourChart.getLegend().setEnabled(false);
        mHourChart.invalidate();
    }
 
Example 6
Source File: StackedBarActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

	tvX.setText("" + (mSeekBarX.getProgress() + 1));
	tvY.setText("" + (mSeekBarY.getProgress()));

	ArrayList<String> xVals = new ArrayList<String>();
	for (int i = 0; i < mSeekBarX.getProgress() + 1; i++) {
		xVals.add(mMonths[i % mMonths.length]);
	}

	ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();

	for (int i = 0; i < mSeekBarX.getProgress() + 1; i++) {
		float mult = (mSeekBarY.getProgress() + 1);
		float val1 = (float) (Math.random() * mult) + mult / 3;
		float val2 = (float) (Math.random() * mult) + mult / 3;
		float val3 = (float) (Math.random() * mult) + mult / 3;

		yVals1.add(new BarEntry(new float[] { val1, val2, val3 }, i));
	}

	BarDataSet set1 = new BarDataSet(yVals1, "Statistics Vienna 2014");
	set1.setColors(getColors());
	set1.setStackLabels(new String[] { "Births", "Divorces", "Marriages" });

	ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
	dataSets.add(set1);

	BarData data = new BarData(xVals, dataSets);
	data.setValueFormatter(new MyValueFormatter());

	mChart.setData(data);
	mChart.invalidate();
}
 
Example 7
Source File: MeasurementActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private void updateSpectrumGUI() {


        ArrayList<String> xVals = new ArrayList<String>();
        ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
        double[] freqLabels = measurementService.getAudioProcess().getRealtimeCenterFrequency();
        float[] freqValues = measurementService.getAudioProcess().getThirdOctaveFrequencySPL();
        for(int idfreq =0; idfreq < freqLabels.length; idfreq++) {
            xVals.add(Spectrogram.formatFrequency((int)freqLabels[idfreq]));
            // Sum values
            // Compute frequency range covered by frequency
            yVals1.add(new BarEntry(new float[] {freqValues[idfreq]}, idfreq));
        }

        BarDataSet set1 = new BarDataSet(yVals1, "DataSet");
        set1.setColor(Color.rgb(102, 178, 255));
        set1.setStackLabels(new String[]{
                "SL"
        });

        ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
        dataSets.add(set1);

        BarData data = new BarData(xVals, dataSets);
        data.setValueTextSize(10f);

        BarChart sChart = getSpectrum();
        if(sChart != null){
            sChart.setData(data);
            sChart.setPadding(0, 0, 0, 0);
            sChart.setViewPortOffsets(0,0,0,0);
            sChart.invalidate(); // refresh
        }
    }
 
Example 8
Source File: StackedBarActivityNegative.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_age_distribution);

    setTitle("StackedBarActivityNegative");

    chart = findViewById(R.id.chart1);
    chart.setOnChartValueSelectedListener(this);
    chart.setDrawGridBackground(false);
    chart.getDescription().setEnabled(false);

    // scaling can now only be done on x- and y-axis separately
    chart.setPinchZoom(false);

    chart.setDrawBarShadow(false);
    chart.setDrawValueAboveBar(true);
    chart.setHighlightFullBarEnabled(false);

    chart.getAxisLeft().setEnabled(false);
    chart.getAxisRight().setAxisMaximum(25f);
    chart.getAxisRight().setAxisMinimum(-25f);
    chart.getAxisRight().setDrawGridLines(false);
    chart.getAxisRight().setDrawZeroLine(true);
    chart.getAxisRight().setLabelCount(7, false);
    chart.getAxisRight().setValueFormatter(new CustomFormatter());
    chart.getAxisRight().setTextSize(9f);

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextSize(9f);
    xAxis.setAxisMinimum(0f);
    xAxis.setAxisMaximum(110f);
    xAxis.setCenterAxisLabels(true);
    xAxis.setLabelCount(12);
    xAxis.setGranularity(10f);
    xAxis.setValueFormatter(new ValueFormatter() {

        private final DecimalFormat format = new DecimalFormat("###");

        @Override
        public String getFormattedValue(float value) {
            return format.format(value) + "-" + format.format(value + 10);
        }
    });

    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setFormSize(8f);
    l.setFormToTextSpace(4f);
    l.setXEntrySpace(6f);

    // IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
    ArrayList<BarEntry> values = new ArrayList<>();
    values.add(new BarEntry(5, new float[]{ -10, 10 }));
    values.add(new BarEntry(15, new float[]{ -12, 13 }));
    values.add(new BarEntry(25, new float[]{ -15, 15 }));
    values.add(new BarEntry(35, new float[]{ -17, 17 }));
    values.add(new BarEntry(45, new float[]{ -19, 20 }));
    values.add(new BarEntry(45, new float[]{ -19, 20 }, getResources().getDrawable(R.drawable.star)));
    values.add(new BarEntry(55, new float[]{ -19, 19 }));
    values.add(new BarEntry(65, new float[]{ -16, 16 }));
    values.add(new BarEntry(75, new float[]{ -13, 14 }));
    values.add(new BarEntry(85, new float[]{ -10, 11 }));
    values.add(new BarEntry(95, new float[]{ -5, 6 }));
    values.add(new BarEntry(105, new float[]{ -1, 2 }));

    BarDataSet set = new BarDataSet(values, "Age Distribution");
    set.setDrawIcons(false);
    set.setValueFormatter(new CustomFormatter());
    set.setValueTextSize(7f);
    set.setAxisDependency(YAxis.AxisDependency.RIGHT);
    set.setColors(Color.rgb(67,67,72), Color.rgb(124,181,236));
    set.setStackLabels(new String[]{
            "Men", "Women"
    });

    BarData data = new BarData(set);
    data.setBarWidth(8.5f);
    chart.setData(data);
    chart.invalidate();
}
 
Example 9
Source File: StackedBarActivityNegative.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_age_distribution);

    setTitle("Age Distribution Austria");

    mChart = (HorizontalBarChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawGridBackground(false);
    mChart.setDescription("");

    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);

    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);
    
    mChart.getAxisLeft().setEnabled(false);
    mChart.getAxisRight().setAxisMaxValue(25f);
    mChart.getAxisRight().setAxisMinValue(-25f);
    mChart.getAxisRight().setDrawGridLines(false);
    mChart.getAxisRight().setDrawZeroLine(true);
    mChart.getAxisRight().setLabelCount(7, false);
    mChart.getAxisRight().setValueFormatter(new CustomFormatter());
    mChart.getAxisRight().setTextSize(9f);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextSize(9f);

    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.BELOW_CHART_RIGHT);
    l.setFormSize(8f);
    l.setFormToTextSpace(4f);
    l.setXEntrySpace(6f);

    // IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
    ArrayList<BarEntry> yValues = new ArrayList<BarEntry>();
    yValues.add(new BarEntry(new float[]{ -10, 10 }, 0));
    yValues.add(new BarEntry(new float[]{ -12, 13 }, 1));
    yValues.add(new BarEntry(new float[]{ -15, 15 }, 2));
    yValues.add(new BarEntry(new float[]{ -17, 17 }, 3));
    yValues.add(new BarEntry(new float[]{ -19, 20 }, 4));
    yValues.add(new BarEntry(new float[]{ -19, 19 }, 5));
    yValues.add(new BarEntry(new float[]{ -16, 16 }, 6));
    yValues.add(new BarEntry(new float[]{ -13, 14 }, 7));
    yValues.add(new BarEntry(new float[]{ -10, 11 }, 8));
    yValues.add(new BarEntry(new float[]{ -5, 6 }, 9));
    yValues.add(new BarEntry(new float[]{ -1, 2 }, 10));

    BarDataSet set = new BarDataSet(yValues, "Age Distribution");
    set.setValueFormatter(new CustomFormatter());
    set.setValueTextSize(7f);
    set.setAxisDependency(YAxis.AxisDependency.RIGHT);
    set.setBarSpacePercent(40f);
    set.setColors(new int[] {Color.rgb(67,67,72), Color.rgb(124,181,236)});
    set.setStackLabels(new String[]{
            "Men", "Women"
    });

    String []xVals = new String[]{"0-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80", "80-90", "90-100", "100+"};

    BarData data = new BarData(xVals, set);
    mChart.setData(data);
    mChart.invalidate();
}