com.github.mikephil.charting.formatter.LargeValueFormatter Java Examples
The following examples show how to use
com.github.mikephil.charting.formatter.LargeValueFormatter.
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: LargeValueFormatterTest.java From StockChart-MPAndroidChart with MIT License | 4 votes |
@Test public void test() { LargeValueFormatter formatter = new LargeValueFormatter(); String result = formatter.getFormattedValue(5f, null); assertEquals("5", result); result = formatter.getFormattedValue(5.5f, null); assertEquals("5.5", result); result = formatter.getFormattedValue(50f, null); assertEquals("50", result); result = formatter.getFormattedValue(50.5f, null); assertEquals("50.5", result); result = formatter.getFormattedValue(500f, null); assertEquals("500", result); result = formatter.getFormattedValue(1100f, null); assertEquals("1.1k", result); result = formatter.getFormattedValue(10000f, null); assertEquals("10k", result); result = formatter.getFormattedValue(10500f, null); assertEquals("10.5k", result); result = formatter.getFormattedValue(100000f, null); assertEquals("100k", result); result = formatter.getFormattedValue(1000000f, null); assertEquals("1m", result); result = formatter.getFormattedValue(1500000f, null); assertEquals("1.5m", result); result = formatter.getFormattedValue(9500000f, null); assertEquals("9.5m", result); result = formatter.getFormattedValue(22200000f, null); assertEquals("22.2m", result); result = formatter.getFormattedValue(222000000f, null); assertEquals("222m", result); result = formatter.getFormattedValue(1000000000f, null); assertEquals("1b", result); result = formatter.getFormattedValue(9900000000f, null); assertEquals("9.9b", result); result = formatter.getFormattedValue(99000000000f, null); assertEquals("99b", result); result = formatter.getFormattedValue(99500000000f, null); assertEquals("99.5b", result); result = formatter.getFormattedValue(999000000000f, null); assertEquals("999b", result); result = formatter.getFormattedValue(1000000000000f, null); assertEquals("1t", result); formatter.setSuffix(new String[]{"", "k", "m", "b", "t", "q"}); // quadrillion support result = formatter.getFormattedValue(1000000000000000f, null); assertEquals("1q", result); result = formatter.getFormattedValue(1100000000000000f, null); assertEquals("1.1q", result); result = formatter.getFormattedValue(10000000000000000f, null); assertEquals("10q", result); result = formatter.getFormattedValue(13300000000000000f, null); assertEquals("13.3q", result); result = formatter.getFormattedValue(100000000000000000f, null); assertEquals("100q", result); }
Example #2
Source File: BarChartActivityMultiDataset.java From StockChart-MPAndroidChart with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_barchart); setTitle("BarChartActivityMultiDataset"); tvX = findViewById(R.id.tvXMax); tvX.setTextSize(10); tvY = findViewById(R.id.tvYMax); seekBarX = findViewById(R.id.seekBar1); seekBarX.setMax(50); seekBarX.setOnSeekBarChangeListener(this); seekBarY = findViewById(R.id.seekBar2); seekBarY.setOnSeekBarChangeListener(this); chart = findViewById(R.id.chart1); chart.setOnChartValueSelectedListener(this); chart.getDescription().setEnabled(false); // chart.setDrawBorders(true); // scaling can now only be done on x- and y-axis separately chart.setPinchZoom(false); chart.setDrawBarShadow(false); chart.setDrawGridBackground(false); // create a custom MarkerView (extend MarkerView) and specify the layout // to use for it MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view); mv.setChartView(chart); // For bounds control chart.setMarker(mv); // Set the marker to the chart seekBarX.setProgress(10); seekBarY.setProgress(100); Legend l = chart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); l.setOrientation(Legend.LegendOrientation.VERTICAL); l.setDrawInside(true); l.setTypeface(tfLight); l.setYOffset(0f); l.setXOffset(10f); l.setYEntrySpace(0f); l.setTextSize(8f); XAxis xAxis = chart.getXAxis(); xAxis.setTypeface(tfLight); xAxis.setGranularity(1f); xAxis.setCenterAxisLabels(true); xAxis.setValueFormatter(new ValueFormatter() { @Override public String getFormattedValue(float value) { return String.valueOf((int) value); } }); YAxis leftAxis = chart.getAxisLeft(); leftAxis.setTypeface(tfLight); leftAxis.setValueFormatter(new LargeValueFormatter()); leftAxis.setDrawGridLines(false); leftAxis.setSpaceTop(35f); leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true) chart.getAxisRight().setEnabled(false); }
Example #3
Source File: LargeValueFormatterTest.java From Ticket-Analysis with MIT License | 4 votes |
@Test public void test() { LargeValueFormatter formatter = new LargeValueFormatter(); String result = formatter.getFormattedValue(5f, null); assertEquals("5", result); result = formatter.getFormattedValue(5.5f, null); assertEquals("5.5", result); result = formatter.getFormattedValue(50f, null); assertEquals("50", result); result = formatter.getFormattedValue(50.5f, null); assertEquals("50.5", result); result = formatter.getFormattedValue(500f, null); assertEquals("500", result); result = formatter.getFormattedValue(1100f, null); assertEquals("1.1k", result); result = formatter.getFormattedValue(10000f, null); assertEquals("10k", result); result = formatter.getFormattedValue(10500f, null); assertEquals("10.5k", result); result = formatter.getFormattedValue(100000f, null); assertEquals("100k", result); result = formatter.getFormattedValue(1000000f, null); assertEquals("1m", result); result = formatter.getFormattedValue(1500000f, null); assertEquals("1.5m", result); result = formatter.getFormattedValue(9500000f, null); assertEquals("9.5m", result); result = formatter.getFormattedValue(22200000f, null); assertEquals("22.2m", result); result = formatter.getFormattedValue(222000000f, null); assertEquals("222m", result); result = formatter.getFormattedValue(1000000000f, null); assertEquals("1b", result); result = formatter.getFormattedValue(9900000000f, null); assertEquals("9.9b", result); result = formatter.getFormattedValue(99000000000f, null); assertEquals("99b", result); result = formatter.getFormattedValue(99500000000f, null); assertEquals("99.5b", result); result = formatter.getFormattedValue(999000000000f, null); assertEquals("999b", result); result = formatter.getFormattedValue(1000000000000f, null); assertEquals("1t", result); formatter.setSuffix(new String[]{"", "k", "m", "b", "t", "q"}); // quadrillion support result = formatter.getFormattedValue(1000000000000000f, null); assertEquals("1q", result); result = formatter.getFormattedValue(1100000000000000f, null); assertEquals("1.1q", result); result = formatter.getFormattedValue(10000000000000000f, null); assertEquals("10q", result); result = formatter.getFormattedValue(13300000000000000f, null); assertEquals("13.3q", result); result = formatter.getFormattedValue(100000000000000000f, null); assertEquals("100q", result); }
Example #4
Source File: LargeValueFormatterTest.java From android-kline with Apache License 2.0 | 4 votes |
@Test public void test() { LargeValueFormatter formatter = new LargeValueFormatter(); String result = formatter.getFormattedValue(5f, null); assertEquals("5", result); result = formatter.getFormattedValue(5.5f, null); assertEquals("5.5", result); result = formatter.getFormattedValue(50f, null); assertEquals("50", result); result = formatter.getFormattedValue(50.5f, null); assertEquals("50.5", result); result = formatter.getFormattedValue(500f, null); assertEquals("500", result); result = formatter.getFormattedValue(1100f, null); assertEquals("1.1k", result); result = formatter.getFormattedValue(10000f, null); assertEquals("10k", result); result = formatter.getFormattedValue(10500f, null); assertEquals("10.5k", result); result = formatter.getFormattedValue(100000f, null); assertEquals("100k", result); result = formatter.getFormattedValue(1000000f, null); assertEquals("1m", result); result = formatter.getFormattedValue(1500000f, null); assertEquals("1.5m", result); result = formatter.getFormattedValue(9500000f, null); assertEquals("9.5m", result); result = formatter.getFormattedValue(22200000f, null); assertEquals("22.2m", result); result = formatter.getFormattedValue(222000000f, null); assertEquals("222m", result); result = formatter.getFormattedValue(1000000000f, null); assertEquals("1b", result); result = formatter.getFormattedValue(9900000000f, null); assertEquals("9.9b", result); result = formatter.getFormattedValue(99000000000f, null); assertEquals("99b", result); result = formatter.getFormattedValue(99500000000f, null); assertEquals("99.5b", result); result = formatter.getFormattedValue(999000000000f, null); assertEquals("999b", result); result = formatter.getFormattedValue(1000000000000f, null); assertEquals("1t", result); formatter.setSuffix(new String[]{"", "k", "m", "b", "t", "q"}); // quadrillion support result = formatter.getFormattedValue(1000000000000000f, null); assertEquals("1q", result); result = formatter.getFormattedValue(1100000000000000f, null); assertEquals("1.1q", result); result = formatter.getFormattedValue(10000000000000000f, null); assertEquals("10q", result); result = formatter.getFormattedValue(13300000000000000f, null); assertEquals("13.3q", result); result = formatter.getFormattedValue(100000000000000000f, null); assertEquals("100q", result); }
Example #5
Source File: BarChartActivityMultiDataset.java From Stayfit with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_barchart); tvX = (TextView) findViewById(R.id.tvXMax); tvY = (TextView) findViewById(R.id.tvYMax); mSeekBarX = (SeekBar) findViewById(R.id.seekBar1); mSeekBarX.setOnSeekBarChangeListener(this); mSeekBarY = (SeekBar) findViewById(R.id.seekBar2); mSeekBarY.setOnSeekBarChangeListener(this); mChart = (BarChart) findViewById(R.id.chart1); mChart.setOnChartValueSelectedListener(this); mChart.setDescription(""); // mChart.setDrawBorders(true); // scaling can now only be done on x- and y-axis separately mChart.setPinchZoom(false); mChart.setDrawBarShadow(false); mChart.setDrawGridBackground(false); // create a custom MarkerView (extend MarkerView) and specify the layout // to use for it MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view); // define an offset to change the original position of the marker // (optional) // mv.setOffsets(-mv.getMeasuredWidth() / 2, -mv.getMeasuredHeight()); // set the marker to the chart mChart.setMarkerView(mv); mSeekBarX.setProgress(10); mSeekBarY.setProgress(100); tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); Legend l = mChart.getLegend(); l.setPosition(LegendPosition.RIGHT_OF_CHART_INSIDE); l.setTypeface(tf); l.setYOffset(0f); l.setYEntrySpace(0f); l.setTextSize(8f); XAxis xl = mChart.getXAxis(); xl.setTypeface(tf); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setTypeface(tf); leftAxis.setValueFormatter(new LargeValueFormatter()); leftAxis.setDrawGridLines(false); leftAxis.setSpaceTop(30f); leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true) mChart.getAxisRight().setEnabled(false); }
Example #6
Source File: YAxisChartBase.java From react-native-mp-android-chart with MIT License | 4 votes |
protected void setYAxisConfig(YAxis axis, ReadableMap propMap) { if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMaxValue")) { axis.setAxisMaxValue((float) propMap.getDouble("axisMaxValue")); } if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMinValue")) { axis.setAxisMinValue((float) propMap.getDouble("axisMinValue")); } if (BridgeUtils.validate(propMap, ReadableType.Boolean, "inverted")) { axis.setInverted(propMap.getBoolean("inverted")); } if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceTop")) { axis.setSpaceTop((float) propMap.getDouble("spaceTop")); } if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceBottom")) { axis.setSpaceBottom((float) propMap.getDouble("spaceBottom")); } if (BridgeUtils.validate(propMap, ReadableType.Boolean, "showOnlyMinMax")) { axis.setShowOnlyMinMax(propMap.getBoolean("showOnlyMinMax")); } if (BridgeUtils.validate(propMap, ReadableType.Number, "labelCount")) { boolean labelCountForce = false; if (BridgeUtils.validate(propMap, ReadableType.Boolean, "labelCountForce")) { labelCountForce = propMap.getBoolean("labelCountForce"); } axis.setLabelCount(propMap.getInt("labelCount"), labelCountForce); } if (BridgeUtils.validate(propMap, ReadableType.String, "position")) { axis.setPosition(YAxis.YAxisLabelPosition.valueOf(propMap.getString("position"))); } if (BridgeUtils.validate(propMap, ReadableType.Number, "granularity")) { axis.setGranularity((float) propMap.getDouble("granularity")); } if (BridgeUtils.validate(propMap, ReadableType.Boolean, "granularityEnabled")) { axis.setGranularityEnabled(propMap.getBoolean("granularityEnabled")); } // formatting if (BridgeUtils.validate(propMap, ReadableType.String, "valueFormatter")) { String valueFormatter = propMap.getString("valueFormatter"); if ("largeValue".equals(valueFormatter)) { axis.setValueFormatter(new LargeValueFormatter()); } else if ("percent".equals(valueFormatter)) { axis.setValueFormatter(new PercentFormatter()); } else { axis.setValueFormatter(new CustomFormatter(valueFormatter)); } } // TODO docs says the remaining config needs to be applied before setting data. Test it // zero line if (BridgeUtils.validate(propMap, ReadableType.Map, "zeroLine")) { ReadableMap zeroLineConfig = propMap.getMap("zeroLine"); if (BridgeUtils.validate(zeroLineConfig, ReadableType.Boolean, "enabled")) { axis.setDrawZeroLine(zeroLineConfig.getBoolean("enabled")); } if (BridgeUtils.validate(zeroLineConfig, ReadableType.Number, "lineWidth")) { axis.setZeroLineWidth((float) zeroLineConfig.getDouble("lineWidth")); } if (BridgeUtils.validate(zeroLineConfig, ReadableType.String, "lineColor")) { axis.setZeroLineColor(Color.parseColor(zeroLineConfig.getString("lineColor"))); } } }