com.github.mikephil.charting.formatter.IAxisValueFormatter Java Examples
The following examples show how to use
com.github.mikephil.charting.formatter.IAxisValueFormatter.
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: QuotationFragment.java From bitshares_wallet with MIT License | 6 votes |
private void updateChartData(List<HistoryPrice> historyPriceList) { class xAxisValueFormater implements IAxisValueFormatter { private List<HistoryPrice> mListPrices; public xAxisValueFormater(List<HistoryPrice> listPrices) { mListPrices = listPrices; } @Override public String getFormattedValue(float value, AxisBase axis) { int nValue = (int)value; if (nValue < mListPrices.size()) { Date date = mListPrices.get(nValue).date; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd HH:mm"); return simpleDateFormat.format(date); } else { return ""; } } } initializeData(historyPriceList); IAxisValueFormatter xvalueFormater = new xAxisValueFormater(historyPriceList); mChart.getXAxis().setValueFormatter(xvalueFormater); }
Example #2
Source File: XYMarkerView.java From mobikul-standalone-pos with MIT License | 5 votes |
public XYMarkerView(Context context, IAxisValueFormatter xAxisValueFormatter) { super(context, R.layout.custom_marker_view); this.xAxisValueFormatter = xAxisValueFormatter; tvContent = (TextView) findViewById(R.id.tvContent); format = new DecimalFormat("###.0"); }
Example #3
Source File: RecordingFragment.java From go-bees with GNU General Public License v3.0 | 5 votes |
/** * Configure styles of weather charts. * * @param entries chart data. * @param formatter value formatter. * @param minVal min value to show. * @param maxVal max value to show. * @return chart formatted. */ private LineDataSet configureWeatherChart( LineChart chart, int chartName, int colorLineTempChart, int colorFillTempChart, List<Entry> entries, IAxisValueFormatter formatter, double minVal, double maxVal) { LineDataSet lineDataSet = new LineDataSet(entries, getString(chartName)); lineDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER); lineDataSet.setDrawValues(false); lineDataSet.setValueTextSize(10f); lineDataSet.setDrawCircles(false); lineDataSet.setLineWidth(1.8f); lineDataSet.setColor(ContextCompat.getColor(getContext(), colorLineTempChart)); lineDataSet.setLineWidth(2f); lineDataSet.setDrawFilled(true); lineDataSet.setFillColor(ContextCompat.getColor(getContext(), colorFillTempChart)); lineDataSet.setFillAlpha(255); // General setup chart.setDrawGridBackground(false); chart.setDrawBorders(false); chart.setViewPortOffsets(0, 0, 0, 0); chart.getDescription().setEnabled(false); chart.getLegend().setEnabled(false); chart.setTouchEnabled(false); // X axis setup XAxis xAxis = chart.getXAxis(); xAxis.setEnabled(false); xAxis.setAxisMinimum(0); xAxis.setAxisMaximum(lastTimestamp); // Y axis setup YAxis leftAxis = chart.getAxisLeft(); leftAxis.setEnabled(false); leftAxis.setAxisMaximum((float) (maxVal)); leftAxis.setAxisMinimum((float) (minVal)); YAxis rightAxis = chart.getAxisRight(); rightAxis.setAxisMaximum((float) (maxVal)); rightAxis.setAxisMinimum((float) (minVal)); rightAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART); rightAxis.setValueFormatter(formatter); return lineDataSet; }
Example #4
Source File: RecordingsAdapter.java From go-bees with GNU General Public License v3.0 | 5 votes |
/** * Setup chart (axis, grid, etc.). * * @param lineChart chart to setup. * @param data chart with the data. * @param firstTimestamp seconds timestamp of the first record (used as initial reference). */ private void setupChart(LineChart lineChart, LineData data, long firstTimestamp) { // General setup lineChart.setDrawGridBackground(false); lineChart.setDrawBorders(false); lineChart.setViewPortOffsets(50, 0, 50, 50); lineChart.getDescription().setEnabled(false); lineChart.getLegend().setEnabled(false); lineChart.setTouchEnabled(false); lineChart.setNoDataText(context.getString(R.string.no_flight_act_data_available)); // X axis setup IAxisValueFormatter xAxisFormatter = new HourAxisValueFormatter(firstTimestamp); XAxis xAxis = lineChart.getXAxis(); xAxis.setValueFormatter(xAxisFormatter); xAxis.setDrawGridLines(false); xAxis.setDrawAxisLine(false); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setCenterAxisLabels(false); xAxis.setTextColor(ContextCompat.getColor(context, R.color.colorIcons)); // Y axis setup YAxis yAxis = lineChart.getAxisLeft(); yAxis.setAxisMaximum(40); yAxis.setAxisMinimum(0); yAxis.setDrawLabels(false); yAxis.setDrawAxisLine(false); yAxis.setDrawGridLines(true); lineChart.getAxisRight().setEnabled(false); // Add data lineChart.setData(data); }
Example #5
Source File: StatActivity.java From ankihelper with GNU General Public License v3.0 | 5 votes |
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: TestSuiteFragment.java From SQLite-Performance with The Unlicense | 5 votes |
private void setupXAxis(BarLineChartBase chart, IAxisValueFormatter formatter) { XAxis x = chart.getXAxis(); x.setGranularity(1.0f); x.setDrawGridLines(false); x.setPosition(XAxis.XAxisPosition.BOTTOM); x.setDrawAxisLine(false); x.setCenterAxisLabels(true); x.setAxisMinimum(2.0f); x.setAxisMaximum(5.0f); x.setValueFormatter(formatter); }
Example #7
Source File: TimeLineView.java From android-kline with Apache License 2.0 | 4 votes |
public void initDatas(List<HisData>... hisDatas) { // 设置标签数量,并让标签居中显示 XAxis xAxis = mChartVolume.getXAxis(); xAxis.setLabelCount(hisDatas.length + 1, true); xAxis.setAvoidFirstLastClipping(false); xAxis.setCenterAxisLabels(true); xAxis.setValueFormatter(new IAxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { value += 1; // 这里不设置+1会有bug if (mData.isEmpty()) { return ""; } if (value < 0) { value = 0; } if (value < mData.size()) { return DateUtils.formatDate(mData.get((int) value).getDate(), mDateFormat); } return ""; } }); mData.clear(); ArrayList<ILineDataSet> sets = new ArrayList<>(); ArrayList<IBarDataSet> barSets = new ArrayList<>(); for (List<HisData> hisData : hisDatas) { hisData = DataUtils.calculateHisData(hisData); ArrayList<Entry> priceEntries = new ArrayList<>(INIT_COUNT); ArrayList<Entry> aveEntries = new ArrayList<>(INIT_COUNT); ArrayList<Entry> paddingEntries = new ArrayList<>(INIT_COUNT); ArrayList<BarEntry> barPaddingEntries = new ArrayList<>(INIT_COUNT); ArrayList<BarEntry> barEntries = new ArrayList<>(INIT_COUNT); for (int i = 0; i < hisData.size(); i++) { HisData t = hisData.get(i); priceEntries.add(new Entry(i + mData.size(), (float) t.getClose())); aveEntries.add(new Entry(i + mData.size(), (float) t.getAvePrice())); barEntries.add(new BarEntry(i + mData.size(), (float) t.getVol(), t)); } if (!hisData.isEmpty() && hisData.size() < INIT_COUNT / hisDatas.length) { for (int i = hisData.size(); i < INIT_COUNT / hisDatas.length; i++) { paddingEntries.add(new Entry(i, (float) hisData.get(hisData.size() - 1).getClose())); barPaddingEntries.add(new BarEntry(i, (float) hisData.get(hisData.size() - 1).getClose())); } } sets.add(setLine(NORMAL_LINE_5DAY, priceEntries)); sets.add(setLine(AVE_LINE, aveEntries)); sets.add(setLine(INVISIABLE_LINE, paddingEntries)); barSets.add(setBar(barEntries, NORMAL_LINE)); barSets.add(setBar(barPaddingEntries, INVISIABLE_LINE)); barSets.add(setBar(barPaddingEntries, INVISIABLE_LINE)); mData.addAll(hisData); } LineData lineData = new LineData(sets); CombinedData combinedData = new CombinedData(); combinedData.setData(lineData); mChartPrice.setData(combinedData); mChartPrice.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartPrice.notifyDataSetChanged(); // mChartPrice.moveViewToX(combinedData.getEntryCount()); moveToLast(mChartVolume); BarData barData = new BarData(barSets); barData.setBarWidth(0.75f); CombinedData combinedData2 = new CombinedData(); combinedData2.setData(barData); mChartVolume.setData(combinedData2); mChartVolume.setVisibleXRange(MAX_COUNT, MIN_COUNT); mChartVolume.notifyDataSetChanged(); mChartVolume.moveViewToX(combinedData2.getEntryCount()); mChartPrice.getXAxis().setAxisMaximum(combinedData.getXMax() + 0.5f); mChartVolume.getXAxis().setAxisMaximum(mChartVolume.getData().getXMax() + 0.5f); mChartPrice.zoom(MAX_COUNT * 1f / INIT_COUNT, 0, 0, 0); mChartVolume.zoom(MAX_COUNT * 1f / INIT_COUNT, 0, 0, 0); setDescription(mChartVolume, "成交量 " + getLastData().getVol()); }
Example #8
Source File: BaseView.java From android-kline with Apache License 2.0 | 4 votes |
protected void initBottomChart(AppCombinedChart chart) { chart.setScaleEnabled(true); chart.setDrawBorders(false); chart.setBorderWidth(1); chart.setDragEnabled(true); chart.setScaleYEnabled(false); chart.setAutoScaleMinMaxEnabled(true); chart.setDragDecelerationEnabled(false); chart.setHighlightPerDragEnabled(false); Legend lineChartLegend = chart.getLegend(); lineChartLegend.setEnabled(false); XAxis xAxisVolume = chart.getXAxis(); xAxisVolume.setDrawLabels(true); xAxisVolume.setDrawAxisLine(false); xAxisVolume.setDrawGridLines(false); xAxisVolume.setTextColor(mAxisColor); xAxisVolume.setPosition(XAxis.XAxisPosition.BOTTOM); xAxisVolume.setLabelCount(3, true); xAxisVolume.setAvoidFirstLastClipping(true); xAxisVolume.setAxisMinimum(-0.5f); xAxisVolume.setValueFormatter(new IAxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { if (mData.isEmpty()) { return ""; } if (value < 0) { value = 0; } if (value < mData.size()) { return DateUtils.formatDate(mData.get((int) value).getDate(), mDateFormat); } return ""; } }); YAxis axisLeftVolume = chart.getAxisLeft(); axisLeftVolume.setDrawLabels(true); axisLeftVolume.setDrawGridLines(false); axisLeftVolume.setLabelCount(3, true); axisLeftVolume.setDrawAxisLine(false); axisLeftVolume.setTextColor(mAxisColor); axisLeftVolume.setSpaceTop(10); axisLeftVolume.setSpaceBottom(0); axisLeftVolume.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART); /*axisLeftVolume.setValueFormatter(new IAxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { String s; if (value > 10000) { s = (int) (value / 10000) + "w"; } else if (value > 1000) { s = (int) (value / 1000) + "k"; } else { s = (int) value + ""; } return String.format(Locale.getDefault(), "%1$5s", s); } }); */ Transformer leftYTransformer = chart.getRendererLeftYAxis().getTransformer(); ColorContentYAxisRenderer leftColorContentYAxisRenderer = new ColorContentYAxisRenderer(chart.getViewPortHandler(), chart.getAxisLeft(), leftYTransformer); leftColorContentYAxisRenderer.setLabelInContent(true); leftColorContentYAxisRenderer.setUseDefaultLabelXOffset(false); chart.setRendererLeftYAxis(leftColorContentYAxisRenderer); //右边y YAxis axisRightVolume = chart.getAxisRight(); axisRightVolume.setDrawLabels(false); axisRightVolume.setDrawGridLines(false); axisRightVolume.setDrawAxisLine(false); }
Example #9
Source File: StatActivity.java From ankihelper with GNU General Public License v3.0 | 4 votes |
private void drawLastDaysChart(int[][] data) { List<Entry> lookupEntries = new ArrayList<>(); List<Entry> cardaddEntries = new ArrayList<>(); for(int i = 0; i < data[0].length; i ++){ lookupEntries.add(new Entry(i, data[1][i])); cardaddEntries.add(new Entry(i, data[2][i])); } if(lookupEntries.size() <= 1){ mLastDaysChart.setVisibility(View.INVISIBLE); }else{ mLastDaysChart.setVisibility(View.VISIBLE); } float lineWidth = 2; LineDataSet lineDataSet2 = new LineDataSet(lookupEntries, "Lookups"); lineDataSet2.setColor(DARK_PINK); lineDataSet2.setLineWidth(lineWidth); lineDataSet2.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER); lineDataSet2.setDrawCircles(false); lineDataSet2.setDrawValues(false); LineDataSet lineDataSet3 = new LineDataSet(cardaddEntries, "Cards"); lineDataSet3.setColor(DARK_GREEN); lineDataSet3.setLineWidth(lineWidth); lineDataSet3.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER); lineDataSet3.setDrawCircles(false); lineDataSet3.setDrawValues(false); List<ILineDataSet> dataSets = new ArrayList<ILineDataSet>(); dataSets.add(lineDataSet2); dataSets.add(lineDataSet3); mLastDaysChart.setData(new LineData(dataSets)); mLastDaysChart.getDescription().setText(""); //mHourChart.getDescription().setTextAlign(); mLastDaysChart.getXAxis().setDrawGridLines(false); mLastDaysChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM); mLastDaysChart.getAxisRight().setEnabled(false); //mHourChart.getAxisLeft().setDrawGridLines(false); mLastDaysChart.getXAxis().setValueFormatter( new IAxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { return + ((int)(-mLastDays + value + 1)) + "d"; } } ); mLastDaysChart.getLegend().setPosition(Legend.LegendPosition.BELOW_CHART_CENTER); mLastDaysChart.invalidate(); }
Example #10
Source File: MainActivity.java From Machine-Learning-Projects-for-Mobile-Applications with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the model and labels. try { classifier = new DigitClassifierModel(this); } catch (IOException e) { Log.e(TAG, "Failed to initialize an image classifier.", e); } //startBackgroundThread(); setContentView(R.layout.activity_main); paintView = (FreeHandView) findViewById(R.id.paintView); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); BarChart barChart = (BarChart) findViewById(R.id.barChart); barChart.animateY(3000); barChart.getXAxis().setEnabled(true); barChart.getAxisRight().setEnabled(false); barChart.getAxisLeft().setAxisMinimum(0.0f); // start at zero barChart.getAxisLeft().setAxisMaximum(1.0f); // the axis maximum is 100 barChart.getDescription().setEnabled(false); barChart.getLegend().setEnabled(false); // the labels that should be drawn on the XAxis final String[] barLabels = new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; IAxisValueFormatter formatter = new IAxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { return barLabels[(int) value]; } }; barChart.getXAxis().setGranularity(0f); // minimum axis-step (interval) is 1 barChart.getXAxis().setValueFormatter(formatter); barChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM); barChart.getXAxis().setTextSize(5f); BARENTRY = new ArrayList<>(); initializeBARENTRY(); Bardataset = new BarDataSet(BARENTRY, "project"); BARDATA = new BarData(Bardataset); barChart.setData(BARDATA); paintView.init(metrics, classifier, barChart); Button resetButton = (Button) findViewById(R.id.resetButton); resetButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { paintView.clear(); } }); }
Example #11
Source File: DateGraph.java From fastnfitness with BSD 3-Clause "New" or "Revised" License | 4 votes |
public DateGraph(Context context, LineChart chart, String name) { mChart = chart; mChartName = name; mChart.setDoubleTapToZoomEnabled(true); mChart.setHorizontalScrollBarEnabled(true); mChart.setVerticalScrollBarEnabled(true); mChart.setAutoScaleMinMaxEnabled(true); mChart.setDrawBorders(true); mChart.setNoDataText(context.getString(R.string.no_chart_data_available)); IMarker marker = new DateGraphMarkerView(mChart.getContext(), R.layout.graph_markerview, mChart); mChart.setMarker(marker); mContext = context; // get the legend (only possible after setting data) Legend l = mChart.getLegend(); l.setEnabled(false); XAxis xAxis = mChart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setTextColor(ColorTemplate.getHoloBlue()); xAxis.setDrawAxisLine(true); xAxis.setDrawGridLines(true); xAxis.setCenterAxisLabels(false); xAxis.setGranularity(1); // 1 jour xAxis.setValueFormatter(new IAxisValueFormatter() { private SimpleDateFormat mFormat = new SimpleDateFormat("dd-MMM"); // HH:mm:ss @Override public String getFormattedValue(float value, AxisBase axis) { //long millis = TimeUnit.HOURS.toMillis((long) value); mFormat.setTimeZone(TimeZone.getTimeZone("GMT")); Date tmpDate = new Date((long) DateConverter.nbMilliseconds(value)); // Convert days in milliseconds return mFormat.format(tmpDate); } }); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); leftAxis.setTextColor(ColorTemplate.getHoloBlue()); leftAxis.setDrawGridLines(true); leftAxis.setGranularityEnabled(true); leftAxis.setGranularity((float) 0.5); leftAxis.resetAxisMinimum(); mChart.getAxisRight().setEnabled(false); }
Example #12
Source File: FreeHandView.java From Machine-Learning-Projects-for-Mobile-Applications with MIT License | 4 votes |
@Override public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); BarData exampleData; switch(event.getAction()) { case MotionEvent.ACTION_DOWN : touchStart(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE : touchMove(x, y); invalidate(); break; case MotionEvent.ACTION_UP : touchUp(); //toGrayscale(mBitmap); Bitmap scaledBitmap = Bitmap.createScaledBitmap(mBitmap, mClassifier.getImageSizeX(), mClassifier.getImageSizeY(), true); Random rng = new Random(); try { File mFile; mFile = this.getContext().getExternalFilesDir(String.valueOf(rng.nextLong() + ".png")); FileOutputStream pngFile = new FileOutputStream(mFile); } catch (Exception e){ } //scaledBitmap.compress(Bitmap.CompressFormat.PNG, 90, pngFile); Float prediction = mClassifier.classifyFrame(scaledBitmap); exampleData = updateBarEntry(); barChart.animateY(1000, Easing.EasingOption.EaseOutQuad); XAxis xAxis = barChart.getXAxis(); xAxis.setValueFormatter(new IAxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { return xAxisLabel.get((int) value); } }); barChart.setData(exampleData); exampleData.notifyDataChanged(); // let the data know a dataSet changed barChart.notifyDataSetChanged(); // let the chart know it's data changed break; } return true; }
Example #13
Source File: RecordingFragment.java From go-bees with GNU General Public License v3.0 | 4 votes |
/** * Configure bees chart and the data. * * @param recordsList list of records. */ private void setupBeesChart(List<Record> recordsList) { // Setup data referenceTimestamp = recordsList.get(0).getTimestamp().getTime() / 1000; Record[] records = recordsList.toArray(new Record[recordsList.size()]); List<Entry> entries = new ArrayList<>(); int maxNumBees = 0; for (Record record : records) { // Convert timestamp to seconds and relative to first timestamp long timestamp = record.getTimestamp().getTime() / 1000 - referenceTimestamp; int numBees = record.getNumBees(); entries.add(new Entry(timestamp, numBees)); // Get max num of bees if (numBees > maxNumBees) { maxNumBees = numBees; } } lastTimestamp = (long) entries.get(entries.size() - 1).getX(); // Style char lines (type, color, etc.) LineDataSet lineDataSet = new LineDataSet(entries, getString(R.string.num_bees)); lineDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER); lineDataSet.setCubicIntensity(0.2f); lineDataSet.setDrawValues(false); lineDataSet.setDrawCircles(false); lineDataSet.setLineWidth(1.8f); lineDataSet.setColor(ContextCompat.getColor(getContext(), R.color.colorAccent)); // General setup beesChart.setDrawGridBackground(false); beesChart.setDrawBorders(false); beesChart.setViewPortOffsets(80, 40, 80, 50); beesChart.getDescription().setEnabled(false); beesChart.getLegend().setEnabled(false); beesChart.setTouchEnabled(true); beesChart.setDragEnabled(false); beesChart.setScaleEnabled(false); beesChart.setPinchZoom(false); BeesMarkerView mv = new BeesMarkerView(getContext(), R.layout.recording_bees_marker_vew); mv.setChartView(beesChart); beesChart.setMarker(mv); beesChart.setNoDataText(getString(R.string.no_flight_act_data_available)); // X axis setup IAxisValueFormatter xAxisFormatter = new HourAxisValueFormatter(referenceTimestamp); XAxis xAxis = beesChart.getXAxis(); xAxis.setValueFormatter(xAxisFormatter); xAxis.setDrawGridLines(false); xAxis.setDrawAxisLine(false); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setTextColor(Color.BLACK); // Y axis setup YAxis leftAxis = beesChart.getAxisLeft(); leftAxis.setAxisMaximum(maxNumBees > 40 ? maxNumBees + 2 : 40); leftAxis.setAxisMinimum(0); leftAxis.setDrawGridLines(true); leftAxis.setDrawAxisLine(false); YAxis rightAxis = beesChart.getAxisRight(); rightAxis.setAxisMaximum(maxNumBees > 40 ? maxNumBees + 2 : 40); rightAxis.setAxisMinimum(0); rightAxis.setDrawGridLines(true); rightAxis.setDrawAxisLine(false); // Add data beesChart.setData(new LineData(lineDataSet)); }
Example #14
Source File: RevenueReportFragment.java From mobikul-standalone-pos with MIT License | 4 votes |
private void setRevenueChart() { DataBaseController.getInstanse().getAllCashHistory(getActivity(), new DataBaseCallBack() { @Override public void onSuccess(Object responseData, String successMsg) { // binding.revenueChart.setOnChartValueSelectedListener(SalesAndReportingActivity.this); binding.revenueChart.setDrawBarShadow(false); binding.revenueChart.setDrawValueAboveBar(true); binding.revenueChart.getDescription().setEnabled(false); // if more than 60 entries are displayed in the chart, no values will be // drawn binding.revenueChart.setMaxVisibleValueCount(60); // scaling can now only be done on x- and y-axis separately binding.revenueChart.setPinchZoom(false); binding.revenueChart.setDrawGridBackground(false); // binding.revenueChart.setDrawYLabels(false); List<Integer> xAxisEntry = new ArrayList<>(); for (CashDrawerModel cashDrawerModel : ((List<CashDrawerModel>) responseData)) { xAxisEntry.add(getCountOfDays(cashDrawerModel.getDate())); } IAxisValueFormatter xAxisFormatter = new DayAxisValueFormatter(binding.revenueChart, xAxisEntry); XAxis xAxis = binding.revenueChart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setDrawGridLines(false); xAxis.setLabelCount(7); xAxis.setGranularity(1); xAxis.setAvoidFirstLastClipping(false); xAxis.setValueFormatter(xAxisFormatter); // Log.d(TAG, "onSuccess: " + xAxisFormatter.getFormattedValue(77, xAxis)); Legend l = binding.revenueChart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT); l.setOrientation(Legend.LegendOrientation.HORIZONTAL); l.setDrawInside(false); l.setForm(Legend.LegendForm.CIRCLE); l.setFormSize(9f); l.setTextSize(11f); l.setXEntrySpace(4f); // XYMarkerView mv = new XYMarkerView(SalesAndReportingActivity.this, xAxisFormatter); // mv.setChartView(binding.revenueChart); // For bounds control // binding.revenueChart.setMarker(mv); // Set the marker to the chart setData((List<CashDrawerModel>) responseData); } @Override public void onFailure(int errorCode, String errorMsg) { } }); }
Example #15
Source File: HistogramChart.java From walt with Apache License 2.0 | 4 votes |
public HistogramChart(Context context, AttributeSet attrs) { super(context, attrs); inflate(getContext(), R.layout.histogram, this); barChart = (BarChart) findViewById(R.id.bar_chart); findViewById(R.id.button_close_bar_chart).setOnClickListener(this); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HistogramChart); final String descString; final int numDataSets; final float binWidth; try { descString = a.getString(R.styleable.HistogramChart_description); numDataSets = a.getInteger(R.styleable.HistogramChart_numDataSets, 1); binWidth = a.getFloat(R.styleable.HistogramChart_binWidth, 5f); } finally { a.recycle(); } ArrayList<IBarDataSet> dataSets = new ArrayList<>(numDataSets); for (int i = 0; i < numDataSets; i++) { final BarDataSet dataSet = new BarDataSet(new ArrayList<BarEntry>(), ""); dataSet.setColor(ColorTemplate.MATERIAL_COLORS[i]); dataSets.add(dataSet); } BarData barData = new BarData(dataSets); barData.setBarWidth((1f - GROUP_SPACE)/numDataSets); barChart.setData(barData); histogramData = new HistogramData(numDataSets, binWidth); groupBars(barData); final Description desc = new Description(); desc.setText(descString); desc.setTextSize(12f); barChart.setDescription(desc); XAxis xAxis = barChart.getXAxis(); xAxis.setGranularityEnabled(true); xAxis.setGranularity(1); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setValueFormatter(new IAxisValueFormatter() { DecimalFormat df = new DecimalFormat("#.##"); @Override public String getFormattedValue(float value, AxisBase axis) { return df.format(histogramData.getDisplayValue(value)); } }); barChart.setFitBars(true); barChart.invalidate(); }
Example #16
Source File: AxisBase.java From android-kline with Apache License 2.0 | 3 votes |
/** * Sets the formatter to be used for formatting the axis labels. If no formatter is set, the * chart will * automatically determine a reasonable formatting (concerning decimals) for all the values * that are drawn inside * the chart. Use chart.getDefaultValueFormatter() to use the formatter calculated by the chart. * * @param f */ public void setValueFormatter(IAxisValueFormatter f) { if (f == null) mAxisValueFormatter = new DefaultAxisValueFormatter(mDecimals); else mAxisValueFormatter = f; }
Example #17
Source File: AxisBase.java From Ticket-Analysis with MIT License | 3 votes |
/** * Sets the formatter to be used for formatting the axis labels. If no formatter is set, the * chart will * automatically determine a reasonable formatting (concerning decimals) for all the values * that are drawn inside * the chart. Use chart.getDefaultValueFormatter() to use the formatter calculated by the chart. * * @param f */ public void setValueFormatter(IAxisValueFormatter f) { if (f == null) mAxisValueFormatter = new DefaultAxisValueFormatter(mDecimals); else mAxisValueFormatter = f; }