Java Code Examples for com.github.mikephil.charting.components.YAxis#setGranularity()
The following examples show how to use
com.github.mikephil.charting.components.YAxis#setGranularity() .
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: PFAChart.java From privacy-friendly-shopping-list with Apache License 2.0 | 6 votes |
private void setupYAxis() { int valuesSelectedItemPos = cache.getValuesSpinner().getSelectedItemPosition(); YAxis leftAxis = this.chart.getAxisLeft(); leftAxis.setLabelCount(10, false); leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); leftAxis.setSpaceTop(20f); leftAxis.setAxisMinValue(0f); leftAxis.setValueFormatter(new PFAYAxisLabels(context, valuesSelectedItemPos, cache.getNumberScale())); if ( valuesSelectedItemPos == StatisticsQuery.QUANTITY ) { leftAxis.setGranularity(1f); // interval 1 } YAxis rightAxis = this.chart.getAxisRight(); rightAxis.setEnabled(false); }
Example 2
Source File: LineChartHelper.java From Ticket-Analysis with MIT License | 5 votes |
public LineChart generateLineChartConfig(LineChart lineChart) { //XY轴配置 XAxis xAxis = lineChart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); //定制X轴是在图表上方还是下方。 xAxis.setDrawGridLines(false); xAxis.setGranularity(1); YAxis yAxisRight = lineChart.getAxisRight(); yAxisRight.setEnabled(false); YAxis yAxisLeft = lineChart.getAxisLeft(); yAxisLeft.setAxisMinimum(0); yAxisLeft.setGranularity(1); //背景设置 lineChart.setDrawGridBackground(false);//表格背景绘制 lineChart.setBackgroundColor(AppContext.getContext().getResources().getColor(R.color.white)); //Legend定制 lineChart.getLegend().setPosition(Legend.LegendPosition.ABOVE_CHART_LEFT); lineChart.getLegend().setForm(Legend.LegendForm.CIRCLE);//Legend样式 //图表描述 lineChart.setDescription(null); // 设置无数据文本提示 lineChart.setNoDataText("暂无数据"); //设置单方向和双方向缩放 true x,y方向可以同时控制,false只能控制x方向的缩小放大或者Y方向的缩小放大 lineChart.setPinchZoom(true); return lineChart; }
Example 3
Source File: BarGraph.java From fastnfitness with BSD 3-Clause "New" or "Revised" License | 5 votes |
public BarGraph(Context context, BarChart chart, String name) { mChart = chart; mChartName = name; mChart.setHorizontalScrollBarEnabled(true); mChart.setVerticalScrollBarEnabled(true); mChart.setDrawBorders(true); mChart.setNoDataText(context.getString(R.string.no_chart_data_available)); 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(false); xAxis.setGranularityEnabled(true); xAxis.setGranularity(1f); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setAxisMinimum(0f); leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); leftAxis.setTextColor(ColorTemplate.getHoloBlue()); leftAxis.setGranularityEnabled(true); leftAxis.setGranularity((float) 1); mChart.setFitBars(true); leftAxis.setAxisMinimum(0f); mChart.getAxisRight().setEnabled(false); }
Example 4
Source File: BarChartActivitySinus.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_sinus); setTitle("BarChartActivitySinus"); data = FileUtils.loadBarEntriesFromAssets(getAssets(), "othersine.txt"); tvX = findViewById(R.id.tvValueCount); seekBarX = findViewById(R.id.seekbarValues); chart = findViewById(R.id.chart1); chart.setDrawBarShadow(false); chart.setDrawValueAboveBar(true); chart.getDescription().setEnabled(false); // if more than 60 entries are displayed in the chart, no values will be // drawn chart.setMaxVisibleValueCount(60); // scaling can now only be done on x- and y-axis separately chart.setPinchZoom(false); // draw shadows for each bar that show the maximum value // chart.setDrawBarShadow(true); // chart.setDrawXLabels(false); chart.setDrawGridBackground(false); // chart.setDrawYLabels(false); XAxis xAxis = chart.getXAxis(); xAxis.setEnabled(false); YAxis leftAxis = chart.getAxisLeft(); leftAxis.setTypeface(tfLight); leftAxis.setLabelCount(6, false); leftAxis.setAxisMinimum(-2.5f); leftAxis.setAxisMaximum(2.5f); leftAxis.setGranularityEnabled(true); leftAxis.setGranularity(0.1f); YAxis rightAxis = chart.getAxisRight(); rightAxis.setDrawGridLines(false); rightAxis.setTypeface(tfLight); rightAxis.setLabelCount(6, false); rightAxis.setAxisMinimum(-2.5f); rightAxis.setAxisMaximum(2.5f); rightAxis.setGranularity(0.1f); seekBarX.setOnSeekBarChangeListener(this); seekBarX.setProgress(150); // set data Legend l = chart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT); l.setOrientation(Legend.LegendOrientation.HORIZONTAL); l.setDrawInside(false); l.setForm(LegendForm.SQUARE); l.setFormSize(9f); l.setTextSize(11f); l.setXEntrySpace(4f); chart.animateXY(1500, 1500); }
Example 5
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 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"))); } } }