Java Code Examples for com.github.mikephil.charting.components.Legend#setForm()
The following examples show how to use
com.github.mikephil.charting.components.Legend#setForm() .
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: CurrencyActivity.java From Travel-Mate with MIT License | 6 votes |
void setupGraph(JSONArray currencyRateTrends) { if (currencyRateTrends == null || currencyRateTrends.length() == 0) { graph.setVisibility(View.GONE); chart_duration_spinner.setVisibility(View.INVISIBLE); } else { graph.setVisibility(View.VISIBLE); chart_duration_spinner.setVisibility(View.VISIBLE); graph.getXAxis().setEnabled(false); graph.getAxisLeft().setEnabled(false); graph.getAxisRight().setEnabled(false); graph.getDescription().setText(""); setGraphData(currencyRateTrends); graph.animateX(1000); Legend l = graph.getLegend(); l.setForm(Legend.LegendForm.LINE); } }
Example 2
Source File: GraphicActivity.java From ToDay with MIT License | 5 votes |
private void addDataSet() { Log.d(TAG, "addDataSet started"); ArrayList<PieEntry> yEntrys = new ArrayList<>(); ArrayList<String> xEntrys = new ArrayList<>(); for(int i = 0; i < yData.length; i++){ yEntrys.add(new PieEntry(yData[i] , i)); } for(int i = 1; i < xData.length; i++){ xEntrys.add(xData[i]); } //create the data set PieDataSet pieDataSet = new PieDataSet(yEntrys, "Төлөвлөгөөний үзүүлэлтлл"); pieDataSet.setSliceSpace(2); pieDataSet.setValueTextSize(12); //add colors to dataset ArrayList<Integer> colors = new ArrayList<>(); colors.add(Color.GRAY); colors.add(Color.BLUE); colors.add(Color.RED); colors.add(Color.GREEN); colors.add(Color.CYAN); colors.add(Color.YELLOW); colors.add(Color.MAGENTA); pieDataSet.setColors(colors); //add legend to chart Legend legend = pieChart.getLegend(); legend.setForm(Legend.LegendForm.CIRCLE); legend.setPosition(Legend.LegendPosition.LEFT_OF_CHART); //create pie data object PieData pieData = new PieData(pieDataSet); pieChart.setData(pieData); pieChart.invalidate(); }
Example 3
Source File: TempChart.java From octoandroid with GNU General Public License v3.0 | 5 votes |
/** * By calling setData initializes the rest of the view * @param data the chart data */ @Override public void setData(LineData data) { super.setData(data); setOnChartValueSelectedListener(this); setDescription(""); setNoDataTextDescription("No chart data"); setTouchEnabled(true); setScaleEnabled(true); setDragEnabled(true); setDrawGridBackground(true); setPinchZoom(true); Legend legend = getLegend(); legend.setForm(Legend.LegendForm.CIRCLE); legend.setWordWrapEnabled(true); XAxis xAxis = getXAxis(); xAxis.setAvoidFirstLastClipping(true); xAxis.setPosition(XAxis.XAxisPosition.TOP); YAxis yAxisLeft = getAxisLeft(); yAxisLeft.setAxisMinValue(0); YAxis yAxisRight = getAxisRight(); yAxisRight.setEnabled(false); }
Example 4
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 5
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 6
Source File: RealtimeLineChartActivity.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_realtime_linechart); setTitle("RealtimeLineChartActivity"); chart = findViewById(R.id.chart1); chart.setOnChartValueSelectedListener(this); // enable description text chart.getDescription().setEnabled(true); // enable touch gestures chart.setTouchEnabled(true); // enable scaling and dragging chart.setDragEnabled(true); chart.setScaleEnabled(true); chart.setDrawGridBackground(false); // if disabled, scaling can be done on x- and y-axis separately chart.setPinchZoom(true); // set an alternative background color chart.setBackgroundColor(Color.LTGRAY); LineData data = new LineData(); data.setValueTextColor(Color.WHITE); // add empty data chart.setData(data); // get the legend (only possible after setting data) Legend l = chart.getLegend(); // modify the legend ... l.setForm(LegendForm.LINE); l.setTypeface(tfLight); l.setTextColor(Color.WHITE); XAxis xl = chart.getXAxis(); xl.setTypeface(tfLight); xl.setTextColor(Color.WHITE); xl.setDrawGridLines(false); xl.setAvoidFirstLastClipping(true); xl.setEnabled(true); YAxis leftAxis = chart.getAxisLeft(); leftAxis.setTypeface(tfLight); leftAxis.setTextColor(Color.WHITE); leftAxis.setAxisMaximum(100f); leftAxis.setAxisMinimum(0f); leftAxis.setDrawGridLines(true); YAxis rightAxis = chart.getAxisRight(); rightAxis.setEnabled(false); }
Example 7
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 8
Source File: InvertedLineChartActivity.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("InvertedLineChartActivity"); 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.setDrawGridBackground(false); // no description text chart.getDescription().setEnabled(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(true); // set an alternative background color // chart.setBackgroundColor(Color.GRAY); // 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 XAxis xl = chart.getXAxis(); xl.setAvoidFirstLastClipping(true); xl.setAxisMinimum(0f); YAxis leftAxis = chart.getAxisLeft(); leftAxis.setInverted(true); leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true) YAxis rightAxis = chart.getAxisRight(); rightAxis.setEnabled(false); // add data seekBarX.setProgress(25); seekBarY.setProgress(50); // // restrain the maximum scale-out factor // chart.setScaleMinima(3f, 3f); // // // center the view to a specific position inside the chart // chart.centerViewPort(10, 50); // get the legend (only possible after setting data) Legend l = chart.getLegend(); // modify the legend ... l.setForm(LegendForm.LINE); // don't forget to refresh the drawing chart.invalidate(); }
Example 9
Source File: ChartUtil.java From PocketEOS-Android with GNU Lesser General Public License v3.0 | 4 votes |
/** * 显示图表 * * @param context 上下文 * @param lineChart 图表对象 * @param yDataList 数据 * @param title 图表标题(如:XXX趋势图) * @param curveLable 曲线图例名称(如:--用电量/时间) * @param unitName 坐标点击弹出提示框中数字单位(如:KWH) */ public static void showChart(Context context, LineChart lineChart, List<Entry> yDataList, String title, String curveLable, String unitName) { // 设置数据 lineChart.setData(setLineData(context, yDataList, curveLable)); // 描述的显示和隐藏 lineChart.getDescription().setEnabled(false); // 是否在折线图上添加边框 lineChart.setDrawBorders(true); // 如果没有数据的时候,会显示这个,类似文本框的placeholder lineChart.setNoDataText(context.getString(R.string.no_data_chart)); // 是否显示表格颜色 lineChart.setDrawGridBackground(false); // 禁止绘制图表边框的线 lineChart.setDrawBorders(false); // 表格的的颜色,在这里是是给颜色设置一个透明度 // lineChart.setGridBackgroundColor(Color.WHITE & 0x70FFFFFF); // 设置是否启动触摸响应 lineChart.setTouchEnabled(false); // 是否可以拖拽 lineChart.setDragEnabled(false); // 是否可以缩放 lineChart.setScaleEnabled(false); // 如果禁用,可以在x和y轴上分别进行缩放 lineChart.setPinchZoom(false); // lineChart.setMarkerView(mv); // 设置背景色 // lineChart.setBackgroundColor(getResources().getColor(R.color.bg_white)); // 图例对象 Legend mLegend = lineChart.getLegend(); // mLegend.setPosition(LegendPosition.BELOW_CHART_CENTER); // 图例样式 (CIRCLE圆形;LINE线性;SQUARE是方块) mLegend.setForm(LegendForm.SQUARE); // 图例大小 mLegend.setFormSize(8f); // 图例上的字体颜色 mLegend.setTextColor(context.getApplicationContext().getResources().getColor(R.color.theme_color)); mLegend.setTextSize(12f); // 图例字体 // mLegend.setTypeface(mTf); // 图例的显示和隐藏 mLegend.setEnabled(false); // 隐藏右侧Y轴(只在左侧的Y轴显示刻度) lineChart.getAxisRight().setEnabled(false); // 隐藏左侧Y轴(只在左侧的Y轴显示刻度) lineChart.getAxisLeft().setEnabled(false); XAxis xAxis = lineChart.getXAxis(); // 显示X轴上的刻度值 xAxis.setDrawLabels(false); // 设置X轴的数据显示在报表的下方 xAxis.setPosition(XAxisPosition.BOTTOM); // 轴线 xAxis.setDrawAxisLine(false); // 设置不从X轴发出纵向直线 xAxis.setDrawGridLines(false); // 执行的动画,x轴(动画持续时间) lineChart.animateX(1500); lineChart.notifyDataSetChanged(); }
Example 10
Source File: BarChartActivity.java From Stayfit with Apache License 2.0 | 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); tvX = (TextView) findViewById(R.id.tvXMax); tvY = (TextView) findViewById(R.id.tvYMax); mSeekBarX = (SeekBar) findViewById(R.id.seekBar1); mSeekBarY = (SeekBar) findViewById(R.id.seekBar2); mChart = (BarChart) findViewById(R.id.chart1); mChart.setOnChartValueSelectedListener(this); mChart.setDrawBarShadow(false); mChart.setDrawValueAboveBar(true); mChart.setDescription(""); // if more than 60 entries are displayed in the chart, no values will be // drawn mChart.setMaxVisibleValueCount(60); // scaling can now only be done on x- and y-axis separately mChart.setPinchZoom(false); mChart.setDrawGridBackground(false); // mChart.setDrawYLabels(false); mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); XAxis xAxis = mChart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setTypeface(mTf); xAxis.setDrawGridLines(false); xAxis.setSpaceBetweenLabels(2); YAxisValueFormatter custom = new MyYAxisValueFormatter(); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setTypeface(mTf); leftAxis.setLabelCount(8, false); leftAxis.setValueFormatter(custom); leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART); leftAxis.setSpaceTop(15f); leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true) YAxis rightAxis = mChart.getAxisRight(); rightAxis.setDrawGridLines(false); rightAxis.setTypeface(mTf); rightAxis.setLabelCount(8, false); rightAxis.setValueFormatter(custom); rightAxis.setSpaceTop(15f); rightAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true) Legend l = mChart.getLegend(); l.setPosition(LegendPosition.BELOW_CHART_LEFT); l.setForm(LegendForm.SQUARE); l.setFormSize(9f); l.setTextSize(11f); l.setXEntrySpace(4f); // l.setExtra(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc", // "def", "ghj", "ikl", "mno" }); // l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc", // "def", "ghj", "ikl", "mno" }); setData(12, 50); // setting data mSeekBarY.setProgress(50); mSeekBarX.setProgress(12); mSeekBarY.setOnSeekBarChangeListener(this); mSeekBarX.setOnSeekBarChangeListener(this); // mChart.setDrawLegend(false); }
Example 11
Source File: BarChartActivitySinus.java From Stayfit with Apache License 2.0 | 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); mSinusData = FileUtils.loadBarEntriesFromAssets(getAssets(),"othersine.txt"); tvX = (TextView) findViewById(R.id.tvValueCount); mSeekBarX = (SeekBar) findViewById(R.id.seekbarValues); mChart = (BarChart) findViewById(R.id.chart1); mChart.setDrawBarShadow(false); mChart.setDrawValueAboveBar(true); mChart.setDescription(""); // if more than 60 entries are displayed in the chart, no values will be // drawn mChart.setMaxVisibleValueCount(60); // scaling can now only be done on x- and y-axis separately mChart.setPinchZoom(false); // draw shadows for each bar that show the maximum value // mChart.setDrawBarShadow(true); // mChart.setDrawXLabels(false); mChart.setDrawGridBackground(false); // mChart.setDrawYLabels(false); mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); XAxis xAxis = mChart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setTypeface(mTf); xAxis.setDrawGridLines(false); xAxis.setEnabled(false); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setTypeface(mTf); leftAxis.setLabelCount(6, false); leftAxis.setAxisMinValue(-2.5f); leftAxis.setAxisMaxValue(2.5f); YAxis rightAxis = mChart.getAxisRight(); rightAxis.setDrawGridLines(false); rightAxis.setTypeface(mTf); rightAxis.setLabelCount(6, false); rightAxis.setAxisMinValue(-2.5f); rightAxis.setAxisMaxValue(2.5f); mSeekBarX.setOnSeekBarChangeListener(this); mSeekBarX.setProgress(150); // set data Legend l = mChart.getLegend(); l.setPosition(LegendPosition.BELOW_CHART_LEFT); l.setForm(LegendForm.SQUARE); l.setFormSize(9f); l.setTextSize(11f); l.setXEntrySpace(4f); mChart.animateXY(2000, 2000); }
Example 12
Source File: RealtimeLineChartActivity.java From Stayfit with Apache License 2.0 | 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_realtime_linechart); mChart = (LineChart) findViewById(R.id.chart1); mChart.setOnChartValueSelectedListener(this); // no description text mChart.setDescription(""); mChart.setNoDataTextDescription("You need to provide data for the chart."); // enable touch gestures mChart.setTouchEnabled(true); // enable scaling and dragging mChart.setDragEnabled(true); mChart.setScaleEnabled(true); mChart.setDrawGridBackground(false); // if disabled, scaling can be done on x- and y-axis separately mChart.setPinchZoom(true); // set an alternative background color mChart.setBackgroundColor(Color.LTGRAY); LineData data = new LineData(); data.setValueTextColor(Color.WHITE); // add empty data mChart.setData(data); Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); // get the legend (only possible after setting data) Legend l = mChart.getLegend(); // modify the legend ... // l.setPosition(LegendPosition.LEFT_OF_CHART); l.setForm(LegendForm.LINE); l.setTypeface(tf); l.setTextColor(Color.WHITE); XAxis xl = mChart.getXAxis(); xl.setTypeface(tf); xl.setTextColor(Color.WHITE); xl.setDrawGridLines(false); xl.setAvoidFirstLastClipping(true); xl.setSpaceBetweenLabels(5); xl.setEnabled(true); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setTypeface(tf); leftAxis.setTextColor(Color.WHITE); leftAxis.setAxisMaxValue(100f); leftAxis.setAxisMinValue(0f); leftAxis.setDrawGridLines(true); YAxis rightAxis = mChart.getAxisRight(); rightAxis.setEnabled(false); }
Example 13
Source File: LineChartActivity2.java From Stayfit with Apache License 2.0 | 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); tvX = (TextView) findViewById(R.id.tvXMax); tvY = (TextView) findViewById(R.id.tvYMax); mSeekBarX = (SeekBar) findViewById(R.id.seekBar1); mSeekBarY = (SeekBar) findViewById(R.id.seekBar2); mSeekBarX.setProgress(45); mSeekBarY.setProgress(100); mSeekBarY.setOnSeekBarChangeListener(this); mSeekBarX.setOnSeekBarChangeListener(this); mChart = (LineChart) findViewById(R.id.chart1); mChart.setOnChartValueSelectedListener(this); // no description text mChart.setDescription(""); mChart.setNoDataTextDescription("You need to provide data for the chart."); // enable touch gestures mChart.setTouchEnabled(true); mChart.setDragDecelerationFrictionCoef(0.9f); // enable scaling and dragging mChart.setDragEnabled(true); mChart.setScaleEnabled(true); mChart.setDrawGridBackground(false); mChart.setHighlightPerDragEnabled(true); // if disabled, scaling can be done on x- and y-axis separately mChart.setPinchZoom(true); // set an alternative background color mChart.setBackgroundColor(Color.LTGRAY); // add data setData(20, 30); mChart.animateX(2500); Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); // get the legend (only possible after setting data) Legend l = mChart.getLegend(); // modify the legend ... // l.setPosition(LegendPosition.LEFT_OF_CHART); l.setForm(LegendForm.LINE); l.setTypeface(tf); l.setTextSize(11f); l.setTextColor(Color.WHITE); l.setPosition(LegendPosition.BELOW_CHART_LEFT); // l.setYOffset(11f); XAxis xAxis = mChart.getXAxis(); xAxis.setTypeface(tf); xAxis.setTextSize(12f); xAxis.setTextColor(Color.WHITE); xAxis.setDrawGridLines(false); xAxis.setDrawAxisLine(false); xAxis.setSpaceBetweenLabels(1); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setTypeface(tf); leftAxis.setTextColor(ColorTemplate.getHoloBlue()); leftAxis.setAxisMaxValue(200f); leftAxis.setAxisMinValue(0f); leftAxis.setDrawGridLines(true); YAxis rightAxis = mChart.getAxisRight(); rightAxis.setTypeface(tf); rightAxis.setTextColor(Color.RED); rightAxis.setAxisMaxValue(900); rightAxis.setAxisMinValue(-200); rightAxis.setDrawGridLines(false); rightAxis.setDrawZeroLine(false); }
Example 14
Source File: InvertedLineChartActivity.java From Stayfit with Apache License 2.0 | 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); tvX = (TextView) findViewById(R.id.tvXMax); tvY = (TextView) findViewById(R.id.tvYMax); mSeekBarX = (SeekBar) findViewById(R.id.seekBar1); mSeekBarY = (SeekBar) findViewById(R.id.seekBar2); mSeekBarX.setProgress(45); mSeekBarY.setProgress(100); mSeekBarY.setOnSeekBarChangeListener(this); mSeekBarX.setOnSeekBarChangeListener(this); mChart = (LineChart) findViewById(R.id.chart1); mChart.setOnChartValueSelectedListener(this); mChart.setDrawGridBackground(false); // no description text mChart.setDescription(""); // enable touch gestures mChart.setTouchEnabled(true); // enable scaling and dragging mChart.setDragEnabled(true); mChart.setScaleEnabled(true); // if disabled, scaling can be done on x- and y-axis separately mChart.setPinchZoom(true); // set an alternative background color // mChart.setBackgroundColor(Color.GRAY); // create a custom MarkerView (extend MarkerView) and specify the layout // to use for it MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view); // set the marker to the chart mChart.setMarkerView(mv); XAxis xl = mChart.getXAxis(); xl.setAvoidFirstLastClipping(true); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setInverted(true); leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true) YAxis rightAxis = mChart.getAxisRight(); rightAxis.setEnabled(false); // add data setData(25, 50); // // restrain the maximum scale-out factor // mChart.setScaleMinima(3f, 3f); // // // center the view to a specific position inside the chart // mChart.centerViewPort(10, 50); // get the legend (only possible after setting data) Legend l = mChart.getLegend(); // modify the legend ... // l.setPosition(LegendPosition.LEFT_OF_CHART); l.setForm(LegendForm.LINE); // dont forget to refresh the drawing mChart.invalidate(); }
Example 15
Source File: ChartBaseManager.java From react-native-mp-android-chart with MIT License | 4 votes |
/** * More details about legend customization: https://github.com/PhilJay/MPAndroidChart/wiki/Legend */ @ReactProp(name = "legend") public void setLegend(T chart, ReadableMap propMap) { Legend legend = chart.getLegend(); if (BridgeUtils.validate(propMap, ReadableType.Boolean, "enabled")) { legend.setEnabled(propMap.getBoolean("enabled")); } // Styling if (BridgeUtils.validate(propMap, ReadableType.String, "textColor")) { legend.setTextColor(Color.parseColor(propMap.getString("textColor"))); } if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) { legend.setTextSize((float) propMap.getDouble("textSize")); } if (BridgeUtils.validate(propMap, ReadableType.String, "fontFamily") || BridgeUtils.validate(propMap, ReadableType.Number, "fontStyle")) { legend.setTypeface(BridgeUtils.parseTypeface(chart.getContext(), propMap, "fontStyle", "fontFamily")); } // Wrapping / clipping avoidance if (BridgeUtils.validate(propMap, ReadableType.Boolean, "wordWrapEnabled")) { legend.setWordWrapEnabled(propMap.getBoolean("wordWrapEnabled")); } if (BridgeUtils.validate(propMap, ReadableType.Number, "maxSizePercent")) { legend.setMaxSizePercent((float) propMap.getDouble("maxSizePercent")); } // Customizing if (BridgeUtils.validate(propMap, ReadableType.String, "position")) { legend.setPosition(LegendPosition.valueOf(propMap.getString("position").toUpperCase())); } if (BridgeUtils.validate(propMap, ReadableType.String, "form")) { legend.setForm(LegendForm.valueOf(propMap.getString("form").toUpperCase())); } if (BridgeUtils.validate(propMap, ReadableType.Number, "formSize")) { legend.setFormSize((float) propMap.getDouble("formSize")); } if (BridgeUtils.validate(propMap, ReadableType.Number, "xEntrySpace")) { legend.setXEntrySpace((float) propMap.getDouble("xEntrySpace")); } if (BridgeUtils.validate(propMap, ReadableType.Number, "yEntrySpace")) { legend.setYEntrySpace((float) propMap.getDouble("yEntrySpace")); } if (BridgeUtils.validate(propMap, ReadableType.Number, "formToTextSpace")) { legend.setFormToTextSpace((float) propMap.getDouble("formToTextSpace")); } // Custom labels & colors if (BridgeUtils.validate(propMap, ReadableType.Map, "custom")) { ReadableMap customMap = propMap.getMap("custom"); if (BridgeUtils.validate(customMap, ReadableType.Array, "colors") && BridgeUtils.validate(customMap, ReadableType.Array, "labels")) { ReadableArray colorsArray = customMap.getArray("colors"); ReadableArray labelsArray = customMap.getArray("labels"); if (colorsArray.size() == labelsArray.size()) { // TODO null label should start a group // TODO -2 color should avoid drawing a form String[] labels = BridgeUtils.convertToStringArray(labelsArray); String[] colors = BridgeUtils.convertToStringArray(colorsArray); int[] colorsParsed = new int[colors.length]; for (int i = 0; i < colors.length; i++) { colorsParsed[i] = Color.parseColor(colors[i]); } legend.setCustom(colorsParsed, labels); } } } // TODO resetCustom function // TODO extra chart.invalidate(); // TODO is this necessary? Looks like enabled is not refreshing without it }