Java Code Examples for com.github.mikephil.charting.components.XAxis#setCenterAxisLabels()
The following examples show how to use
com.github.mikephil.charting.components.XAxis#setCenterAxisLabels() .
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: TrafficFragment.java From gito-github-client with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") private void chartXAxisStyling(XAxis xAxis) { xAxis.setPosition(XAxis.XAxisPosition.TOP); xAxis.setTextColor(getResources().getColor(R.color.traffic_chart_text_color_light)); xAxis.setDrawAxisLine(true); xAxis.setDrawGridLines(false); xAxis.setCenterAxisLabels(true); xAxis.setValueFormatter(new AxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { return Utils.humanReadable((long) value); } @Override public int getDecimalDigits() { return 0; } }); }
Example 2
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 3
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 4
Source File: StackedBarActivityNegative.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_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 5
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 6
Source File: LineChartTime.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_linechart_time); setTitle("LineChartTime"); tvX = findViewById(R.id.tvXMax); seekBarX = findViewById(R.id.seekBar1); seekBarX.setOnSeekBarChangeListener(this); chart = findViewById(R.id.chart1); // no description text chart.getDescription().setEnabled(false); // enable touch gestures chart.setTouchEnabled(true); chart.setDragDecelerationFrictionCoef(0.9f); // enable scaling and dragging chart.setDragEnabled(true); chart.setScaleEnabled(true); chart.setDrawGridBackground(false); chart.setHighlightPerDragEnabled(true); // set an alternative background color chart.setBackgroundColor(Color.WHITE); chart.setViewPortOffsets(0f, 0f, 0f, 0f); // add data seekBarX.setProgress(100); // get the legend (only possible after setting data) Legend l = chart.getLegend(); l.setEnabled(false); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.TOP_INSIDE); xAxis.setTypeface(tfLight); xAxis.setTextSize(10f); xAxis.setTextColor(Color.WHITE); xAxis.setDrawAxisLine(false); xAxis.setDrawGridLines(true); xAxis.setTextColor(Color.rgb(255, 192, 56)); xAxis.setCenterAxisLabels(true); xAxis.setGranularity(1f); // one hour xAxis.setValueFormatter(new ValueFormatter() { private final SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH); @Override public String getFormattedValue(float value) { long millis = TimeUnit.HOURS.toMillis((long) value); return mFormat.format(new Date(millis)); } }); YAxis leftAxis = chart.getAxisLeft(); leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART); leftAxis.setTypeface(tfLight); leftAxis.setTextColor(ColorTemplate.getHoloBlue()); leftAxis.setDrawGridLines(true); leftAxis.setGranularityEnabled(true); leftAxis.setAxisMinimum(0f); leftAxis.setAxisMaximum(170f); leftAxis.setYOffset(-9f); leftAxis.setTextColor(Color.rgb(255, 192, 56)); YAxis rightAxis = chart.getAxisRight(); rightAxis.setEnabled(false); }
Example 7
Source File: BarChartPositiveNegative.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_noseekbar); setTitle("BarChartPositiveNegative"); chart = findViewById(R.id.chart1); chart.setBackgroundColor(Color.WHITE); chart.setExtraTopOffset(-30f); chart.setExtraBottomOffset(10f); chart.setExtraLeftOffset(70f); chart.setExtraRightOffset(70f); chart.setDrawBarShadow(false); chart.setDrawValueAboveBar(true); chart.getDescription().setEnabled(false); // scaling can now only be done on x- and y-axis separately chart.setPinchZoom(false); chart.setDrawGridBackground(false); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setTypeface(tfRegular); xAxis.setDrawGridLines(false); xAxis.setDrawAxisLine(false); xAxis.setTextColor(Color.LTGRAY); xAxis.setTextSize(13f); xAxis.setLabelCount(5); xAxis.setCenterAxisLabels(true); xAxis.setGranularity(1f); YAxis left = chart.getAxisLeft(); left.setDrawLabels(false); left.setSpaceTop(25f); left.setSpaceBottom(25f); left.setDrawAxisLine(false); left.setDrawGridLines(false); left.setDrawZeroLine(true); // draw a zero line left.setZeroLineColor(Color.GRAY); left.setZeroLineWidth(0.7f); chart.getAxisRight().setEnabled(false); chart.getLegend().setEnabled(false); // THIS IS THE ORIGINAL DATA YOU WANT TO PLOT final List<Data> data = new ArrayList<>(); data.add(new Data(0f, -224.1f, "12-29")); data.add(new Data(1f, 238.5f, "12-30")); data.add(new Data(2f, 1280.1f, "12-31")); data.add(new Data(3f, -442.3f, "01-01")); data.add(new Data(4f, -2280.1f, "01-02")); xAxis.setValueFormatter(new ValueFormatter() { @Override public String getFormattedValue(float value) { return data.get(Math.min(Math.max((int) value, 0), data.size()-1)).xAxisValue; } }); setData(data); }
Example 8
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 9
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 10
Source File: MiniDateGraph.java From fastnfitness with BSD 3-Clause "New" or "Revised" License | 4 votes |
public MiniDateGraph(Context context, LineChart chart, String name) { mChart = chart; mChartName = name; mChart.getDescription().setEnabled(false); mChart.setDoubleTapToZoomEnabled(false); mChart.setHorizontalScrollBarEnabled(false); mChart.setVerticalScrollBarEnabled(false); mChart.setAutoScaleMinMaxEnabled(false); mChart.setDrawBorders(false); mChart.setViewPortOffsets(6f, 6f, 6f, 6f); mChart.animateY(1000, Easing.EaseInOutBack); // animate horizontal 3000 milliseconds mChart.setClickable(false); mChart.getAxisRight().setDrawLabels(false); mChart.getAxisLeft().setDrawLabels(false); mChart.getLegend().setEnabled(false); mChart.setPinchZoom(false); mChart.setDescription(null); mChart.setTouchEnabled(false); mChart.setDoubleTapToZoomEnabled(false); 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.setDrawLabels(false); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setTextColor(ColorTemplate.getHoloBlue()); xAxis.setDrawAxisLine(false); xAxis.setDrawGridLines(false); xAxis.setCenterAxisLabels(false); xAxis.setGranularity(1); // 1 jour YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setEnabled(false); leftAxis.setDrawZeroLine(false); leftAxis.setDrawLabels(false); leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); leftAxis.setTextColor(ColorTemplate.getHoloBlue()); leftAxis.setDrawGridLines(false); leftAxis.setGranularityEnabled(false); mChart.getAxisRight().setEnabled(false); }