Java Code Examples for com.github.mikephil.charting.components.XAxis#setGranularity()
The following examples show how to use
com.github.mikephil.charting.components.XAxis#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 setXlabels(List<String> labelList) { int valuesSelectedItemPos = cache.getValuesSpinner().getSelectedItemPosition(); String[] labels = new String[ labelList.size() ]; labelList.toArray(labels); PFAXAxisLabels xFormatter = new PFAXAxisLabels(labels); chart.setMarkerView(new PFAMarkerView(context, xFormatter, valuesSelectedItemPos, cache.getNumberScale())); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setDrawGridLines(false); xAxis.setGranularity(1f); xAxis.setLabelCount(5); xAxis.setValueFormatter(xFormatter); }
Example 2
Source File: BarChartHelper.java From Ticket-Analysis with MIT License | 5 votes |
public BarChart generateBarChartConfig(BarChart barChart) { XAxis xAxis = barChart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); //定制X轴是在图表上方还是下方。 xAxis.setDrawAxisLine(true); xAxis.setDrawGridLines(false); xAxis.setGranularity(1f);//放大的时候X值不增多 YAxis yAxisRight = barChart.getAxisRight(); yAxisRight.setEnabled(false); YAxis yAxisLeft = barChart.getAxisLeft(); yAxisLeft.setAxisMinimum(0); barChart.setDrawBarShadow(false); barChart.setPinchZoom(true); barChart.setFitBars(true); // if more than 60 entries are displayed in the chart, no values will be // drawn barChart.setMaxVisibleValueCount(60); barChart.setDrawValueAboveBar(true); barChart.getDescription().setEnabled(false); barChart.setNoDataText("无数据"); Legend l = barChart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER); l.setOrientation(Legend.LegendOrientation.HORIZONTAL); //设置单方向和双方向缩放 true x,y方向可以同时控制,false只能控制x方向的缩小放大或者Y方向的缩小放大 l.setDrawInside(false); l.setFormSize(8f); l.setXEntrySpace(4f); return barChart; }
Example 3
Source File: AnalysisFragment.java From outlay with Apache License 2.0 | 5 votes |
private void initChart() { barChart.setDrawBarShadow(false); barChart.setDrawValueAboveBar(true); barChart.getDescription().setEnabled(false); barChart.setPinchZoom(false); barChart.setMaxVisibleValueCount(60); barChart.getLegend().setEnabled(false); barChart.setDrawGridBackground(false); barChart.getAxisRight().setEnabled(false); barChart.setScaleYEnabled(false); dayAxisValueFormatter = new DayAxisValueFormatter(); XAxis xAxis = barChart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setLabelRotationAngle(270); xAxis.setDrawGridLines(false); xAxis.setGranularity(1f); xAxis.setTextColor(getOutlayTheme().secondaryTextColor); xAxis.setValueFormatter(dayAxisValueFormatter); YAxis leftAxis = barChart.getAxisLeft(); leftAxis.setValueFormatter(new AmountValueFormatter()); leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); leftAxis.setTextColor(getOutlayTheme().secondaryTextColor); leftAxis.setSpaceTop(15f); leftAxis.setAxisMinimum(0f); }
Example 4
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 5
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 6
Source File: ModelDetailActivity.java From Synapse with Apache License 2.0 | 5 votes |
private void setXAxis(int epochs) { final XAxis axis = mChart.getXAxis(); axis.setEnabled(true); axis.setAxisMinimum(1F); axis.setAxisMaximum(epochs); axis.setPosition(XAxis.XAxisPosition.BOTTOM); axis.setDrawAxisLine(true); axis.setDrawGridLines(false); axis.setGranularity(1F); axis.setAvoidFirstLastClipping(true); mChart.getAxisRight().setDrawAxisLine(true); }
Example 7
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 8
Source File: HorizontalBarChartActivity.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_horizontalbarchart); setTitle("HorizontalBarChartActivity"); tvX = findViewById(R.id.tvXMax); tvY = findViewById(R.id.tvYMax); seekBarX = findViewById(R.id.seekBar1); seekBarY = findViewById(R.id.seekBar2); seekBarY.setOnSeekBarChangeListener(this); seekBarX.setOnSeekBarChangeListener(this); chart = findViewById(R.id.chart1); chart.setOnChartValueSelectedListener(this); // chart.setHighlightEnabled(false); 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.setDrawGridBackground(false); XAxis xl = chart.getXAxis(); xl.setPosition(XAxisPosition.BOTTOM); xl.setTypeface(tfLight); xl.setDrawAxisLine(true); xl.setDrawGridLines(false); xl.setGranularity(10f); YAxis yl = chart.getAxisLeft(); yl.setTypeface(tfLight); yl.setDrawAxisLine(true); yl.setDrawGridLines(true); yl.setAxisMinimum(0f); // this replaces setStartAtZero(true) // yl.setInverted(true); YAxis yr = chart.getAxisRight(); yr.setTypeface(tfLight); yr.setDrawAxisLine(true); yr.setDrawGridLines(false); yr.setAxisMinimum(0f); // this replaces setStartAtZero(true) // yr.setInverted(true); chart.setFitBars(true); chart.animateY(2500); // setting data seekBarY.setProgress(50); seekBarX.setProgress(12); Legend l = chart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT); l.setOrientation(Legend.LegendOrientation.HORIZONTAL); l.setDrawInside(false); l.setFormSize(8f); l.setXEntrySpace(4f); }
Example 9
Source File: BarChartActivity.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("BarChartActivity"); tvX = findViewById(R.id.tvXMax); tvY = findViewById(R.id.tvYMax); seekBarX = findViewById(R.id.seekBar1); seekBarY = findViewById(R.id.seekBar2); seekBarY.setOnSeekBarChangeListener(this); seekBarX.setOnSeekBarChangeListener(this); chart = findViewById(R.id.chart1); chart.setOnChartValueSelectedListener(this); 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); chart.setDrawGridBackground(false); // chart.setDrawYLabels(false); ValueFormatter xAxisFormatter = new DayAxisValueFormatter(chart); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setTypeface(tfLight); xAxis.setDrawGridLines(false); xAxis.setGranularity(1f); // only intervals of 1 day xAxis.setLabelCount(7); xAxis.setValueFormatter(xAxisFormatter); ValueFormatter custom = new MyValueFormatter("$"); YAxis leftAxis = chart.getAxisLeft(); leftAxis.setTypeface(tfLight); leftAxis.setLabelCount(8, false); leftAxis.setValueFormatter(custom); leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART); leftAxis.setSpaceTop(15f); leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true) YAxis rightAxis = chart.getAxisRight(); rightAxis.setDrawGridLines(false); rightAxis.setTypeface(tfLight); rightAxis.setLabelCount(8, false); rightAxis.setValueFormatter(custom); rightAxis.setSpaceTop(15f); rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true) 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); XYMarkerView mv = new XYMarkerView(this, xAxisFormatter); mv.setChartView(chart); // For bounds control chart.setMarker(mv); // Set the marker to the chart // setting data seekBarY.setProgress(50); seekBarX.setProgress(12); // chart.setDrawLegend(false); }
Example 10
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 11
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 12
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 13
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 14
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); }
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: CombinedChartActivity.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_combined); setTitle("CombinedChartActivity"); chart = findViewById(R.id.chart1); chart.getDescription().setEnabled(false); chart.setBackgroundColor(Color.WHITE); chart.setDrawGridBackground(false); chart.setDrawBarShadow(false); chart.setHighlightFullBarEnabled(false); // draw bars behind lines chart.setDrawOrder(new DrawOrder[]{ DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER }); Legend l = chart.getLegend(); l.setWordWrapEnabled(true); l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER); l.setOrientation(Legend.LegendOrientation.HORIZONTAL); l.setDrawInside(false); YAxis rightAxis = chart.getAxisRight(); rightAxis.setDrawGridLines(false); rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true) YAxis leftAxis = chart.getAxisLeft(); leftAxis.setDrawGridLines(false); leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true) XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTH_SIDED); xAxis.setAxisMinimum(0f); xAxis.setGranularity(1f); xAxis.setValueFormatter(new ValueFormatter() { @Override public String getFormattedValue(float value) { return months[(int) value % months.length]; } }); CombinedData data = new CombinedData(); data.setData(generateLineData()); data.setData(generateBarData()); data.setData(generateBubbleData()); data.setData(generateScatterData()); data.setData(generateCandleData()); data.setValueTypeface(tfLight); xAxis.setAxisMaximum(data.getXMax() + 0.25f); chart.setData(data); chart.invalidate(); }
Example 17
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(); }