Java Code Examples for com.github.mikephil.charting.components.Legend#setVerticalAlignment()
The following examples show how to use
com.github.mikephil.charting.components.Legend#setVerticalAlignment() .
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: KlineFragment.java From shinny-futures-android with GNU General Public License v3.0 | 6 votes |
/** * date: 2019/7/31 * author: chenli * description: 刷新均线图标值 */ private void refreshTopChartLegend(int index) { List<LegendEntry> legendEntries = new ArrayList<>(); for (int i = 0; i < mas.size(); i++) { int para = mas.get(i); Entry entry = mLineData.getDataSetByIndex(i).getEntryForXValue(index, 0.0f); String data = ":"; if (entry != null) data = data + MathUtils.round(entry.getY()+"", 2); LegendEntry ma = new LegendEntry("MA" + para + data, Legend.LegendForm.NONE, NaN, NaN, null, mColorMas[i]); legendEntries.add(ma); } Legend legend = mTopChartViewBase.getLegend(); legend.setCustom(legendEntries); legend.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); }
Example 2
Source File: BaseChartFragment.java From shinny-futures-android with GNU General Public License v3.0 | 5 votes |
/** * date: 2019/7/31 * author: chenli * description: 刷新中部图标值 */ protected void refreshChartLegend(int index){ Map<String, KlineEntity.DataEntity> dataEntities = mKlineEntity.getData(); int middleIndex = index; if (!CURRENT_DAY_FRAGMENT.equals(mFragmentType)) middleIndex = middleIndex + mBaseIndex; KlineEntity.DataEntity dataEntity = dataEntities.get(String.valueOf(middleIndex)); if (dataEntity != null){ List<LegendEntry> legendEntriesMiddle = new ArrayList<>(); legendEntriesMiddle.add(new LegendEntry("OI:"+dataEntity.getClose_oi(), Legend.LegendForm.NONE, NaN, NaN, null, mOIColor)); legendEntriesMiddle.add(new LegendEntry("VOL:"+dataEntity.getVolume(), Legend.LegendForm.NONE, NaN, NaN, null, mIncreasingColor)); Legend legendMiddle = mMiddleChartViewBase.getLegend(); legendMiddle.setCustom(legendEntriesMiddle); legendMiddle.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); legendMiddle.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); } Float emasF = mEMAs.get(index); Float emalF = mEMAl.get(index); if (emasF != null && emalF != null){ float emas = mEMAs.get(index); float emal = mEMAl.get(index); String dif = MathUtils.round((emas - emal) + "", 2); String dea = MathUtils.round(mDEA.get(index) + "", 2); List<LegendEntry> legendEntriesBottom = new ArrayList<>(); legendEntriesBottom.add(new LegendEntry("MACD(12,26,9)" , Legend.LegendForm.NONE, NaN, NaN, null, mDeaColor)); legendEntriesBottom.add(new LegendEntry("DIFF:"+dif, Legend.LegendForm.NONE, NaN, NaN, null, mDiffColor)); legendEntriesBottom.add(new LegendEntry("DEA:"+dea, Legend.LegendForm.NONE, NaN, NaN, null, mDeaColor)); Legend legendBottom = mBottomChartViewBase.getLegend(); legendBottom.setCustom(legendEntriesBottom); legendBottom.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); legendBottom.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); } }
Example 3
Source File: PieChartFrag.java From StockChart-MPAndroidChart with MIT License | 5 votes |
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.frag_simple_pie, container, false); chart = v.findViewById(R.id.pieChart1); chart.getDescription().setEnabled(false); Typeface tf = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf"); chart.setCenterTextTypeface(tf); chart.setCenterText(generateCenterText()); chart.setCenterTextSize(10f); chart.setCenterTextTypeface(tf); // radius of the center hole in percent of maximum radius chart.setHoleRadius(45f); chart.setTransparentCircleRadius(50f); Legend l = chart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); l.setOrientation(Legend.LegendOrientation.VERTICAL); l.setDrawInside(false); chart.setData(generatePieData()); return v; }
Example 4
Source File: NodeInfoFragment.java From android-wallet-app with GNU General Public License v3.0 | 5 votes |
private void initializeChart() { chart.setUsePercentValues(true); chart.getDescription().setEnabled(false); chart.setDragDecelerationFrictionCoef(0.95f); chart.setCenterText(generateCenterSpannableText()); chart.setExtraOffsets(15.f, 15.f, 15.f, 15.f); chart.setDrawHoleEnabled(true); chart.setHoleColor(Color.WHITE); chart.setTransparentCircleColor(Color.WHITE); chart.setTransparentCircleAlpha(110); chart.setHoleRadius(58f); chart.setTransparentCircleRadius(61f); chart.setDrawCenterText(true); chart.setRotationAngle(0); // enable rotation of the chart by touch chart.setRotationEnabled(true); chart.setHighlightPerTapEnabled(true); // add a selection listener chart.setOnChartValueSelectedListener(this); Legend l = chart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT); l.setOrientation(Legend.LegendOrientation.HORIZONTAL); l.setDrawInside(false); l.setEnabled(true); }
Example 5
Source File: TestSuiteFragment.java From SQLite-Performance with The Unlicense | 5 votes |
public void runTests() { for (TestCaseRunner runner : mRunners) { runner.cancel(true); } mRunners.clear(); mChart.clear(); BarData data = new BarData(); mChart.setData(data); MetricsVariableAxisFormatter formatter = new MetricsVariableAxisFormatter(getMetricsTransformer()); setupYAxes(mChart); setupXAxis(mChart, formatter); setupDescription(mChart); Legend legend = mChart.getLegend(); legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER); legend.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM); legend.setWordWrapEnabled(true); legend.setOrientation(Legend.LegendOrientation.HORIZONTAL); legend.setDrawInside(false); mChart.invalidate(); Map<TestScenarioMetadata, TestCase[]> scenarios = getTestScenarios(); for (Map.Entry<TestScenarioMetadata, TestCase[]> scenario : scenarios.entrySet()) { TestScenarioMetadata d = scenario.getKey(); TestCaseRunner r = new TestCaseRunner(d.iterations, mChart, d.title, d.color, formatter); r.executeOnExecutor(TestCaseRunner.SERIAL_EXECUTOR, scenario.getValue()); mRunners.add(r); } }
Example 6
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 7
Source File: MultiLineChartActivity.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); setTitle("MultiLineChartActivity"); tvX = findViewById(R.id.tvXMax); tvY = findViewById(R.id.tvYMax); seekBarX = findViewById(R.id.seekBar1); seekBarX.setOnSeekBarChangeListener(this); seekBarY = findViewById(R.id.seekBar2); seekBarY.setOnSeekBarChangeListener(this); chart = findViewById(R.id.chart1); chart.setOnChartValueSelectedListener(this); chart.setDrawGridBackground(false); chart.getDescription().setEnabled(false); chart.setDrawBorders(false); chart.getAxisLeft().setEnabled(false); chart.getAxisRight().setDrawAxisLine(false); chart.getAxisRight().setDrawGridLines(false); chart.getXAxis().setDrawAxisLine(false); chart.getXAxis().setDrawGridLines(false); // enable touch gestures chart.setTouchEnabled(true); // enable scaling and dragging chart.setDragEnabled(true); chart.setScaleEnabled(true); // if disabled, scaling can be done on x- and y-axis separately chart.setPinchZoom(false); seekBarX.setProgress(20); seekBarY.setProgress(100); Legend l = chart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); l.setOrientation(Legend.LegendOrientation.VERTICAL); l.setDrawInside(false); }
Example 8
Source File: PieChartItem.java From StockChart-MPAndroidChart with MIT License | 4 votes |
@SuppressLint("InflateParams") @Override public View getView(int position, View convertView, Context c) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = LayoutInflater.from(c).inflate( R.layout.list_item_piechart, null); holder.chart = convertView.findViewById(R.id.chart); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // apply styling holder.chart.getDescription().setEnabled(false); holder.chart.setHoleRadius(52f); holder.chart.setTransparentCircleRadius(57f); holder.chart.setCenterText(mCenterText); holder.chart.setCenterTextTypeface(mTf); holder.chart.setCenterTextSize(9f); holder.chart.setUsePercentValues(true); holder.chart.setExtraOffsets(5, 10, 50, 10); mChartData.setValueFormatter(new PercentFormatter()); mChartData.setValueTypeface(mTf); mChartData.setValueTextSize(11f); mChartData.setValueTextColor(Color.WHITE); // set data holder.chart.setData((PieData) mChartData); Legend l = holder.chart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); l.setOrientation(Legend.LegendOrientation.VERTICAL); l.setDrawInside(false); l.setYEntrySpace(0f); l.setYOffset(0f); // do not forget to refresh the chart // holder.chart.invalidate(); holder.chart.animateY(900); return convertView; }
Example 9
Source File: LineChartActivity2.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); setTitle("LineChartActivity2"); tvX = findViewById(R.id.tvXMax); tvY = findViewById(R.id.tvYMax); seekBarX = findViewById(R.id.seekBar1); seekBarX.setOnSeekBarChangeListener(this); seekBarY = findViewById(R.id.seekBar2); seekBarY.setOnSeekBarChangeListener(this); chart = findViewById(R.id.chart1); chart.setOnChartValueSelectedListener(this); // 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); // if disabled, scaling can be done on x- and y-axis separately chart.setPinchZoom(true); // set an alternative background color chart.setBackgroundColor(Color.LTGRAY); // add data seekBarX.setProgress(20); seekBarY.setProgress(30); chart.animateX(1500); // get the legend (only possible after setting data) Legend l = chart.getLegend(); // modify the legend ... l.setForm(LegendForm.LINE); l.setTypeface(tfLight); l.setTextSize(11f); l.setTextColor(Color.WHITE); l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT); l.setOrientation(Legend.LegendOrientation.HORIZONTAL); l.setDrawInside(false); // l.setYOffset(11f); XAxis xAxis = chart.getXAxis(); xAxis.setTypeface(tfLight); xAxis.setTextSize(11f); xAxis.setTextColor(Color.WHITE); xAxis.setDrawGridLines(false); xAxis.setDrawAxisLine(false); YAxis leftAxis = chart.getAxisLeft(); leftAxis.setTypeface(tfLight); leftAxis.setTextColor(ColorTemplate.getHoloBlue()); leftAxis.setAxisMaximum(200f); leftAxis.setAxisMinimum(0f); leftAxis.setDrawGridLines(true); leftAxis.setGranularityEnabled(true); YAxis rightAxis = chart.getAxisRight(); rightAxis.setTypeface(tfLight); rightAxis.setTextColor(Color.RED); rightAxis.setAxisMaximum(900); rightAxis.setAxisMinimum(-200); rightAxis.setDrawGridLines(false); rightAxis.setDrawZeroLine(false); rightAxis.setGranularityEnabled(false); }
Example 10
Source File: BubbleChartActivity.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_bubblechart); setTitle("BubbleChartActivity"); tvX = findViewById(R.id.tvXMax); tvY = findViewById(R.id.tvYMax); seekBarX = findViewById(R.id.seekBar1); seekBarX.setOnSeekBarChangeListener(this); seekBarY = findViewById(R.id.seekBar2); seekBarY.setOnSeekBarChangeListener(this); chart = findViewById(R.id.chart1); chart.getDescription().setEnabled(false); chart.setOnChartValueSelectedListener(this); chart.setDrawGridBackground(false); chart.setTouchEnabled(true); // enable scaling and dragging chart.setDragEnabled(true); chart.setScaleEnabled(true); chart.setMaxVisibleValueCount(200); chart.setPinchZoom(true); seekBarX.setProgress(10); seekBarY.setProgress(50); Legend l = chart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); l.setOrientation(Legend.LegendOrientation.VERTICAL); l.setDrawInside(false); l.setTypeface(tfLight); YAxis yl = chart.getAxisLeft(); yl.setTypeface(tfLight); yl.setSpaceTop(30f); yl.setSpaceBottom(30f); yl.setDrawZeroLine(false); chart.getAxisRight().setEnabled(false); XAxis xl = chart.getXAxis(); xl.setPosition(XAxis.XAxisPosition.BOTTOM); xl.setTypeface(tfLight); }
Example 11
Source File: HalfPieChartActivity.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_piechart_half); setTitle("HalfPieChartActivity"); chart = findViewById(R.id.chart1); chart.setBackgroundColor(Color.WHITE); moveOffScreen(); chart.setUsePercentValues(true); chart.getDescription().setEnabled(false); chart.setCenterTextTypeface(tfLight); chart.setCenterText(generateCenterSpannableText()); chart.setDrawHoleEnabled(true); chart.setHoleColor(Color.WHITE); chart.setTransparentCircleColor(Color.WHITE); chart.setTransparentCircleAlpha(110); chart.setHoleRadius(58f); chart.setTransparentCircleRadius(61f); chart.setDrawCenterText(true); chart.setRotationEnabled(false); chart.setHighlightPerTapEnabled(true); chart.setMaxAngle(180f); // HALF CHART chart.setRotationAngle(180f); chart.setCenterTextOffset(0, -20); setData(4, 100); chart.animateY(1400, Easing.EaseInOutQuad); Legend l = chart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER); l.setOrientation(Legend.LegendOrientation.HORIZONTAL); l.setDrawInside(false); l.setXEntrySpace(7f); l.setYEntrySpace(0f); l.setYOffset(0f); // entry label styling chart.setEntryLabelColor(Color.WHITE); chart.setEntryLabelTypeface(tfRegular); chart.setEntryLabelTextSize(12f); }
Example 12
Source File: PieChartActivity.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_piechart); setTitle("PieChartActivity"); tvX = findViewById(R.id.tvXMax); tvY = findViewById(R.id.tvYMax); seekBarX = findViewById(R.id.seekBar1); seekBarY = findViewById(R.id.seekBar2); seekBarX.setOnSeekBarChangeListener(this); seekBarY.setOnSeekBarChangeListener(this); chart = findViewById(R.id.chart1); chart.setUsePercentValues(true); chart.getDescription().setEnabled(false); chart.setExtraOffsets(5, 10, 5, 5); chart.setDragDecelerationFrictionCoef(0.95f); chart.setCenterTextTypeface(tfLight); chart.setCenterText(generateCenterSpannableText()); chart.setDrawHoleEnabled(true); chart.setHoleColor(Color.WHITE); chart.setTransparentCircleColor(Color.WHITE); chart.setTransparentCircleAlpha(110); chart.setHoleRadius(58f); chart.setTransparentCircleRadius(61f); chart.setDrawCenterText(true); chart.setRotationAngle(0); // enable rotation of the chart by touch chart.setRotationEnabled(true); chart.setHighlightPerTapEnabled(true); // chart.setUnit(" €"); // chart.setDrawUnitsInChart(true); // add a selection listener chart.setOnChartValueSelectedListener(this); seekBarX.setProgress(4); seekBarY.setProgress(10); chart.animateY(1400, Easing.EaseInOutQuad); // chart.spin(2000, 0, 360); Legend l = chart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); l.setOrientation(Legend.LegendOrientation.VERTICAL); l.setDrawInside(false); l.setXEntrySpace(7f); l.setYEntrySpace(0f); l.setYOffset(0f); // entry label styling chart.setEntryLabelColor(Color.WHITE); chart.setEntryLabelTypeface(tfRegular); chart.setEntryLabelTextSize(12f); }
Example 13
Source File: ScatterChartActivity.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_scatterchart); setTitle("ScatterChartActivity"); tvX = findViewById(R.id.tvXMax); tvY = findViewById(R.id.tvYMax); seekBarX = findViewById(R.id.seekBar1); seekBarX.setOnSeekBarChangeListener(this); seekBarY = findViewById(R.id.seekBar2); seekBarY.setOnSeekBarChangeListener(this); chart = findViewById(R.id.chart1); chart.getDescription().setEnabled(false); chart.setOnChartValueSelectedListener(this); chart.setDrawGridBackground(false); chart.setTouchEnabled(true); chart.setMaxHighlightDistance(50f); // enable scaling and dragging chart.setDragEnabled(true); chart.setScaleEnabled(true); chart.setMaxVisibleValueCount(200); chart.setPinchZoom(true); seekBarX.setProgress(45); seekBarY.setProgress(100); Legend l = chart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); l.setOrientation(Legend.LegendOrientation.VERTICAL); l.setDrawInside(false); l.setTypeface(tfLight); l.setXOffset(5f); YAxis yl = chart.getAxisLeft(); yl.setTypeface(tfLight); yl.setAxisMinimum(0f); // this replaces setStartAtZero(true) chart.getAxisRight().setEnabled(false); XAxis xl = chart.getXAxis(); xl.setTypeface(tfLight); xl.setDrawGridLines(false); }
Example 14
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 15
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 16
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 17
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 18
Source File: StackedBarActivity.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("StackedBarActivity"); tvX = findViewById(R.id.tvXMax); tvY = findViewById(R.id.tvYMax); seekBarX = findViewById(R.id.seekBar1); seekBarX.setOnSeekBarChangeListener(this); seekBarY = findViewById(R.id.seekBar2); seekBarY.setOnSeekBarChangeListener(this); chart = findViewById(R.id.chart1); chart.setOnChartValueSelectedListener(this); chart.getDescription().setEnabled(false); // if more than 60 entries are displayed in the chart, no values will be // drawn chart.setMaxVisibleValueCount(40); // scaling can now only be done on x- and y-axis separately chart.setPinchZoom(false); chart.setDrawGridBackground(false); chart.setDrawBarShadow(false); chart.setDrawValueAboveBar(false); chart.setHighlightFullBarEnabled(false); // change the position of the y-labels YAxis leftAxis = chart.getAxisLeft(); leftAxis.setValueFormatter(new MyValueFormatter("K")); leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true) chart.getAxisRight().setEnabled(false); XAxis xLabels = chart.getXAxis(); xLabels.setPosition(XAxisPosition.TOP); // chart.setDrawXLabels(false); // chart.setDrawYLabels(false); // setting data seekBarX.setProgress(12); seekBarY.setProgress(100); 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); // chart.setDrawLegend(false); }
Example 19
Source File: InventoryReportFragment.java From mobikul-standalone-pos with MIT License | 4 votes |
private void setSalesProductChart(List<SalesProductReportModel> soldProducts) { binding.productChart.setUsePercentValues(true); binding.productChart.getDescription().setEnabled(false); // binding.productChart.setExtraOffsets(5, 10, 10, 5); // holder.chart.setExtraOffsets(5, 10, 50, 10); binding.productChart.setDragDecelerationFrictionCoef(0.95f); binding.productChart.setCenterText(generateCenterSpannableText()); binding.productChart.setDrawHoleEnabled(true); binding.productChart.setHoleColor(Color.WHITE); binding.productChart.setTransparentCircleColor(Color.WHITE); binding.productChart.setTransparentCircleAlpha(90); binding.productChart.setHoleRadius(50f); binding.productChart.setTransparentCircleRadius(55f); binding.productChart.setDrawCenterText(true); binding.productChart.setRotationAngle(0); // enable rotation of the chart by touch binding.productChart.setRotationEnabled(true); binding.productChart.setHighlightPerTapEnabled(true); // binding.productChart.setUnit(" €"); // binding.productChart.setDrawUnitsInChart(true); // add a selection listener // binding.productChart.setOnChartValueSelectedListener(this); setData(soldProducts, 10); binding.productChart.animateY(1400, Easing.EasingOption.EaseInOutQuad); // binding.productChart.spin(2000, 0, 360); Legend l = binding.productChart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); l.setOrientation(Legend.LegendOrientation.VERTICAL); l.setDrawInside(false); // l.setXEntrySpace(7f); l.setYEntrySpace(0f); l.setYOffset(0f); // entry label styling binding.productChart.setEntryLabelColor(Color.WHITE); binding.productChart.setEntryLabelTextSize(12f); }
Example 20
Source File: PieChartItem.java From memorize with MIT License | 4 votes |
@SuppressLint("InflateParams") @Override public View getView(int position, View convertView, Context c) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = LayoutInflater.from(c).inflate( R.layout.stats_item_piechart, null); holder.chart = convertView.findViewById(R.id.chart); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // apply styling holder.chart.getDescription().setEnabled(false); holder.chart.setHoleRadius(52f); holder.chart.setTransparentCircleRadius(57f); holder.chart.setCenterText(mCenterText); holder.chart.setCenterTextSize(9f); holder.chart.setUsePercentValues(true); holder.chart.setExtraOffsets(5, 10, 50, 10); mChartData.setValueFormatter(new PercentFormatter()); mChartData.setValueTextSize(11f); mChartData.setValueTextColor(Color.WHITE); // set data holder.chart.setData((PieData) mChartData); Legend l = holder.chart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); l.setOrientation(Legend.LegendOrientation.VERTICAL); l.setDrawInside(false); l.setYEntrySpace(0f); l.setYOffset(0f); holder.chart.animateY(900); return convertView; }