Java Code Examples for com.github.mikephil.charting.components.YAxis#setPosition()
The following examples show how to use
com.github.mikephil.charting.components.YAxis#setPosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PFAChart.java From privacy-friendly-shopping-list with Apache License 2.0 | 6 votes |
private void setupYAxis() { int valuesSelectedItemPos = cache.getValuesSpinner().getSelectedItemPosition(); YAxis leftAxis = this.chart.getAxisLeft(); leftAxis.setLabelCount(10, false); leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); leftAxis.setSpaceTop(20f); leftAxis.setAxisMinValue(0f); leftAxis.setValueFormatter(new PFAYAxisLabels(context, valuesSelectedItemPos, cache.getNumberScale())); if ( valuesSelectedItemPos == StatisticsQuery.QUANTITY ) { leftAxis.setGranularity(1f); // interval 1 } YAxis rightAxis = this.chart.getAxisRight(); rightAxis.setEnabled(false); }
Example 2
Source File: PowerChart.java From AndroidApp with GNU Affero General Public License v3.0 | 5 votes |
private void setFormatting() { powerChart.setDrawGridBackground(false); powerChart.getLegend().setEnabled(false); powerChart.getAxisRight().setEnabled(false); powerChart.getDescription().setEnabled(false); powerChart.setNoDataText(""); powerChart.setHardwareAccelerationEnabled(true); YAxis yAxis = powerChart.getAxisLeft(); yAxis.setEnabled(true); yAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART); yAxis.setDrawTopYLabelEntry(false); yAxis.setDrawGridLines(false); yAxis.setDrawAxisLine(false); yAxis.setTextColor(ContextCompat.getColor(context, R.color.lightGrey)); yAxis.setTextSize(context.getResources().getInteger(R.integer.chartDateTextSize)); yAxis.setValueFormatter(new IntegerYAxisValueFormatter()); XAxis xAxis = powerChart.getXAxis(); xAxis.setDrawAxisLine(false); xAxis.setDrawGridLines(false); xAxis.setDrawLabels(true); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setTextColor(ContextCompat.getColor(context, R.color.lightGrey)); xAxis.setValueFormatter(new HoursMinutesXAxisValueFormatter(chartLabels)); xAxis.setTextSize(context.getResources().getInteger(R.integer.chartDateTextSize)); }
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: RecordingFragment.java From go-bees with GNU General Public License v3.0 | 5 votes |
/** * Configure styles of weather charts. * * @param entries chart data. * @param formatter value formatter. * @param minVal min value to show. * @param maxVal max value to show. * @return chart formatted. */ private LineDataSet configureWeatherChart( LineChart chart, int chartName, int colorLineTempChart, int colorFillTempChart, List<Entry> entries, IAxisValueFormatter formatter, double minVal, double maxVal) { LineDataSet lineDataSet = new LineDataSet(entries, getString(chartName)); lineDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER); lineDataSet.setDrawValues(false); lineDataSet.setValueTextSize(10f); lineDataSet.setDrawCircles(false); lineDataSet.setLineWidth(1.8f); lineDataSet.setColor(ContextCompat.getColor(getContext(), colorLineTempChart)); lineDataSet.setLineWidth(2f); lineDataSet.setDrawFilled(true); lineDataSet.setFillColor(ContextCompat.getColor(getContext(), colorFillTempChart)); lineDataSet.setFillAlpha(255); // General setup chart.setDrawGridBackground(false); chart.setDrawBorders(false); chart.setViewPortOffsets(0, 0, 0, 0); chart.getDescription().setEnabled(false); chart.getLegend().setEnabled(false); chart.setTouchEnabled(false); // X axis setup XAxis xAxis = chart.getXAxis(); xAxis.setEnabled(false); xAxis.setAxisMinimum(0); xAxis.setAxisMaximum(lastTimestamp); // Y axis setup YAxis leftAxis = chart.getAxisLeft(); leftAxis.setEnabled(false); leftAxis.setAxisMaximum((float) (maxVal)); leftAxis.setAxisMinimum((float) (minVal)); YAxis rightAxis = chart.getAxisRight(); rightAxis.setAxisMaximum((float) (maxVal)); rightAxis.setAxisMinimum((float) (minVal)); rightAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART); rightAxis.setValueFormatter(formatter); return lineDataSet; }
Example 5
Source File: TrafficFragment.java From gito-github-client with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") private void chartYAxisStyling(YAxis yAxis) { yAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); yAxis.setTextColor(SettingsActivity.ThemePreferenceFragment.isLight(getContext()) ? getResources().getColor(R.color.traffic_chart_text_color_light) : getResources().getColor(R.color.traffic_chart_text_color_dark)); yAxis.setDrawGridLines(false); yAxis.setGranularityEnabled(true); yAxis.setDrawAxisLine(true); }
Example 6
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 7
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 8
Source File: YAxisChartBase.java From react-native-mp-android-chart with MIT License | 4 votes |
protected void setYAxisConfig(YAxis axis, ReadableMap propMap) { if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMaxValue")) { axis.setAxisMaxValue((float) propMap.getDouble("axisMaxValue")); } if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMinValue")) { axis.setAxisMinValue((float) propMap.getDouble("axisMinValue")); } if (BridgeUtils.validate(propMap, ReadableType.Boolean, "inverted")) { axis.setInverted(propMap.getBoolean("inverted")); } if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceTop")) { axis.setSpaceTop((float) propMap.getDouble("spaceTop")); } if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceBottom")) { axis.setSpaceBottom((float) propMap.getDouble("spaceBottom")); } if (BridgeUtils.validate(propMap, ReadableType.Boolean, "showOnlyMinMax")) { axis.setShowOnlyMinMax(propMap.getBoolean("showOnlyMinMax")); } if (BridgeUtils.validate(propMap, ReadableType.Number, "labelCount")) { boolean labelCountForce = false; if (BridgeUtils.validate(propMap, ReadableType.Boolean, "labelCountForce")) { labelCountForce = propMap.getBoolean("labelCountForce"); } axis.setLabelCount(propMap.getInt("labelCount"), labelCountForce); } if (BridgeUtils.validate(propMap, ReadableType.String, "position")) { axis.setPosition(YAxis.YAxisLabelPosition.valueOf(propMap.getString("position"))); } if (BridgeUtils.validate(propMap, ReadableType.Number, "granularity")) { axis.setGranularity((float) propMap.getDouble("granularity")); } if (BridgeUtils.validate(propMap, ReadableType.Boolean, "granularityEnabled")) { axis.setGranularityEnabled(propMap.getBoolean("granularityEnabled")); } // formatting if (BridgeUtils.validate(propMap, ReadableType.String, "valueFormatter")) { String valueFormatter = propMap.getString("valueFormatter"); if ("largeValue".equals(valueFormatter)) { axis.setValueFormatter(new LargeValueFormatter()); } else if ("percent".equals(valueFormatter)) { axis.setValueFormatter(new PercentFormatter()); } else { axis.setValueFormatter(new CustomFormatter(valueFormatter)); } } // TODO docs says the remaining config needs to be applied before setting data. Test it // zero line if (BridgeUtils.validate(propMap, ReadableType.Map, "zeroLine")) { ReadableMap zeroLineConfig = propMap.getMap("zeroLine"); if (BridgeUtils.validate(zeroLineConfig, ReadableType.Boolean, "enabled")) { axis.setDrawZeroLine(zeroLineConfig.getBoolean("enabled")); } if (BridgeUtils.validate(zeroLineConfig, ReadableType.Number, "lineWidth")) { axis.setZeroLineWidth((float) zeroLineConfig.getDouble("lineWidth")); } if (BridgeUtils.validate(zeroLineConfig, ReadableType.String, "lineColor")) { axis.setZeroLineColor(Color.parseColor(zeroLineConfig.getString("lineColor"))); } } }
Example 9
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 10
Source File: FragmentPrice.java From bcm-android with GNU General Public License v3.0 | 4 votes |
private void setupChart(LineChart chart, LineData data, int color) { ((LineDataSet) data.getDataSetByIndex(0)).setCircleColorHole(color); chart.getDescription().setEnabled(false); chart.setDrawGridBackground(false); chart.setTouchEnabled(false); chart.setDragEnabled(false); chart.setScaleEnabled(true); chart.setPinchZoom(false); chart.setBackgroundColor(color); chart.setViewPortOffsets(0, 23, 0, 0); chart.setData(data); Legend l = chart.getLegend(); l.setEnabled(false); chart.getAxisLeft().setEnabled(true); chart.getAxisLeft().setDrawGridLines(false); chart.getAxisLeft().setDrawAxisLine(false); chart.getAxisLeft().setSpaceTop(10); chart.getAxisLeft().setSpaceBottom(30); chart.getAxisLeft().setAxisLineColor(0xFFFFFF); chart.getAxisLeft().setTextColor(0xFFFFFF); chart.getAxisLeft().setDrawTopYLabelEntry(true); chart.getAxisLeft().setLabelCount(10); chart.getXAxis().setEnabled(true); chart.getXAxis().setDrawGridLines(false); chart.getXAxis().setDrawAxisLine(false); chart.getXAxis().setAxisLineColor(0xFFFFFF); chart.getXAxis().setTextColor(0xFFFFFF); Typeface tf = Typeface.DEFAULT; // X Axis XAxis xAxis = chart.getXAxis(); xAxis.setTypeface(tf); xAxis.removeAllLimitLines(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE); xAxis.setTextColor(Color.argb(150, 255, 255, 255)); if (displayType == 1 || displayType == 2) // Week and Month xAxis.setValueFormatter(new WeekXFormatter()); else if (displayType == 0) // Day xAxis.setValueFormatter(new HourXFormatter()); else xAxis.setValueFormatter(new YearXFormatter()); // Year // Y Axis YAxis leftAxis = chart.getAxisLeft(); leftAxis.removeAllLimitLines(); leftAxis.setTypeface(tf); leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART); leftAxis.setTextColor(Color.argb(150, 255, 255, 255)); leftAxis.setValueFormatter(new DontShowNegativeFormatter(displayInUsd)); chart.getAxisRight().setEnabled(false); // Deactivates horizontal lines chart.animateX(1300); chart.notifyDataSetChanged(); }
Example 11
Source File: CubicLineChartActivity.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.setViewPortOffsets(0, 20, 0, 0); mChart.setBackgroundColor(Color.rgb(104, 241, 175)); // 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(false); mChart.setDrawGridBackground(false); tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); XAxis x = mChart.getXAxis(); x.setEnabled(false); YAxis y = mChart.getAxisLeft(); y.setTypeface(tf); y.setLabelCount(6, false); y.setTextColor(Color.WHITE); y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART); y.setDrawGridLines(false); y.setAxisLineColor(Color.WHITE); mChart.getAxisRight().setEnabled(false); // add data setData(45, 100); mChart.getLegend().setEnabled(false); mChart.animateXY(2000, 2000); // dont forget to refresh the drawing mChart.invalidate(); }
Example 12
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 13
Source File: ChartFragment.java From Liapp with Apache License 2.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { view = inflater.inflate(R.layout.fragment_lastscanchart, container, false); LineChart cv_LastScan = (LineChart) view.findViewById(R.id.cv_LastScan); cv_LastScan.setOnChartGestureListener(new myChartGestureListener(cv_LastScan)); XAxis xAxis = cv_LastScan.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setTextSize(10f); xAxis.setTextColor(getResources().getColor(R.color.colorGlucoseNow)); xAxis.enableGridDashedLine(5f, 5f, 0f); xAxis.setDrawLimitLinesBehindData(true); YAxis yAxisLeft = cv_LastScan.getAxisLeft(); YAxis yAxisRight = cv_LastScan.getAxisRight(); yAxisRight.setEnabled(false); yAxisLeft.setTextSize(18f); // set the textsize yAxisLeft.setTextColor(getResources().getColor(R.color.colorGlucoseNow)); yAxisLeft.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART); yAxisLeft.setStartAtZero(true); yAxisLeft.setYOffset(-6f); yAxisLeft.setAxisMinValue(0.0f); Legend legend = cv_LastScan.getLegend(); legend.setEnabled(false); // no description text cv_LastScan.setDescription(""); cv_LastScan.setNoDataText(getResources().getString(R.string.no_data)); cv_LastScan.setNoDataTextDescription(""); // enable touch gestures cv_LastScan.setTouchEnabled(true); // enable scaling and dragging cv_LastScan.setDragEnabled(true); cv_LastScan.setScaleEnabled(true); cv_LastScan.setDrawGridBackground(false); // if disabled, scaling can be done on x- and y-axis separately cv_LastScan.setPinchZoom(true); MyMarkerView mv = new MyMarkerView(view.getContext(), R.layout.custom_marker_view); // set the marker to the chart cv_LastScan.setMarkerView(mv); try { int sdk = android.os.Build.VERSION.SDK_INT; if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) { cv_LastScan.setHardwareAccelerationEnabled(false); } else { cv_LastScan.setHardwareAccelerationEnabled(true); } } catch (Exception e) { } refresh(); return (view); }
Example 14
Source File: FragmentPrice.java From Lunary-Ethereum-Wallet with GNU General Public License v3.0 | 4 votes |
private void setupChart(LineChart chart, LineData data, int color) { ((LineDataSet) data.getDataSetByIndex(0)).setCircleColorHole(color); chart.getDescription().setEnabled(false); chart.setDrawGridBackground(false); chart.setTouchEnabled(false); chart.setDragEnabled(false); chart.setScaleEnabled(true); chart.setPinchZoom(false); chart.setBackgroundColor(color); chart.setViewPortOffsets(0, 23, 0, 0); chart.setData(data); Legend l = chart.getLegend(); l.setEnabled(false); chart.getAxisLeft().setEnabled(true); chart.getAxisLeft().setDrawGridLines(false); chart.getAxisLeft().setDrawAxisLine(false); chart.getAxisLeft().setSpaceTop(10); chart.getAxisLeft().setSpaceBottom(30); chart.getAxisLeft().setAxisLineColor(0xFFFFFF); chart.getAxisLeft().setTextColor(0xFFFFFF); chart.getAxisLeft().setDrawTopYLabelEntry(true); chart.getAxisLeft().setLabelCount(10); chart.getXAxis().setEnabled(true); chart.getXAxis().setDrawGridLines(false); chart.getXAxis().setDrawAxisLine(false); chart.getXAxis().setAxisLineColor(0xFFFFFF); chart.getXAxis().setTextColor(0xFFFFFF); Typeface tf = Typeface.DEFAULT; // X Axis XAxis xAxis = chart.getXAxis(); xAxis.setTypeface(tf); xAxis.removeAllLimitLines(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE); xAxis.setTextColor(Color.argb(150, 255, 255, 255)); if (displayType == 1 || displayType == 2) // Week and Month xAxis.setValueFormatter(new WeekXFormatter()); else if (displayType == 0) // Day xAxis.setValueFormatter(new HourXFormatter()); else xAxis.setValueFormatter(new YearXFormatter()); // Year // Y Axis YAxis leftAxis = chart.getAxisLeft(); leftAxis.removeAllLimitLines(); leftAxis.setTypeface(tf); leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART); leftAxis.setTextColor(Color.argb(150, 255, 255, 255)); leftAxis.setValueFormatter(new DontShowNegativeFormatter(displayInUsd)); chart.getAxisRight().setEnabled(false); // Deactivates horizontal lines chart.animateX(1300); chart.notifyDataSetChanged(); }
Example 15
Source File: BaseView.java From android-kline with Apache License 2.0 | 4 votes |
protected void initBottomChart(AppCombinedChart chart) { chart.setScaleEnabled(true); chart.setDrawBorders(false); chart.setBorderWidth(1); chart.setDragEnabled(true); chart.setScaleYEnabled(false); chart.setAutoScaleMinMaxEnabled(true); chart.setDragDecelerationEnabled(false); chart.setHighlightPerDragEnabled(false); Legend lineChartLegend = chart.getLegend(); lineChartLegend.setEnabled(false); XAxis xAxisVolume = chart.getXAxis(); xAxisVolume.setDrawLabels(true); xAxisVolume.setDrawAxisLine(false); xAxisVolume.setDrawGridLines(false); xAxisVolume.setTextColor(mAxisColor); xAxisVolume.setPosition(XAxis.XAxisPosition.BOTTOM); xAxisVolume.setLabelCount(3, true); xAxisVolume.setAvoidFirstLastClipping(true); xAxisVolume.setAxisMinimum(-0.5f); xAxisVolume.setValueFormatter(new IAxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { if (mData.isEmpty()) { return ""; } if (value < 0) { value = 0; } if (value < mData.size()) { return DateUtils.formatDate(mData.get((int) value).getDate(), mDateFormat); } return ""; } }); YAxis axisLeftVolume = chart.getAxisLeft(); axisLeftVolume.setDrawLabels(true); axisLeftVolume.setDrawGridLines(false); axisLeftVolume.setLabelCount(3, true); axisLeftVolume.setDrawAxisLine(false); axisLeftVolume.setTextColor(mAxisColor); axisLeftVolume.setSpaceTop(10); axisLeftVolume.setSpaceBottom(0); axisLeftVolume.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART); /*axisLeftVolume.setValueFormatter(new IAxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { String s; if (value > 10000) { s = (int) (value / 10000) + "w"; } else if (value > 1000) { s = (int) (value / 1000) + "k"; } else { s = (int) value + ""; } return String.format(Locale.getDefault(), "%1$5s", s); } }); */ Transformer leftYTransformer = chart.getRendererLeftYAxis().getTransformer(); ColorContentYAxisRenderer leftColorContentYAxisRenderer = new ColorContentYAxisRenderer(chart.getViewPortHandler(), chart.getAxisLeft(), leftYTransformer); leftColorContentYAxisRenderer.setLabelInContent(true); leftColorContentYAxisRenderer.setUseDefaultLabelXOffset(false); chart.setRendererLeftYAxis(leftColorContentYAxisRenderer); //右边y YAxis axisRightVolume = chart.getAxisRight(); axisRightVolume.setDrawLabels(false); axisRightVolume.setDrawGridLines(false); axisRightVolume.setDrawAxisLine(false); }
Example 16
Source File: CubicLineChartActivity.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("CubicLineChartActivity"); tvX = findViewById(R.id.tvXMax); tvY = findViewById(R.id.tvYMax); seekBarX = findViewById(R.id.seekBar1); seekBarY = findViewById(R.id.seekBar2); chart = findViewById(R.id.chart1); chart.setViewPortOffsets(0, 0, 0, 0); chart.setBackgroundColor(Color.rgb(104, 241, 175)); // 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(false); chart.setDrawGridBackground(false); chart.setMaxHighlightDistance(300); XAxis x = chart.getXAxis(); x.setEnabled(false); YAxis y = chart.getAxisLeft(); y.setTypeface(tfLight); y.setLabelCount(6, false); y.setTextColor(Color.WHITE); y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART); y.setDrawGridLines(false); y.setAxisLineColor(Color.WHITE); chart.getAxisRight().setEnabled(false); // add data seekBarY.setOnSeekBarChangeListener(this); seekBarX.setOnSeekBarChangeListener(this); // lower max, as cubic runs significantly slower than linear seekBarX.setMax(700); seekBarX.setProgress(45); seekBarY.setProgress(100); chart.getLegend().setEnabled(false); chart.animateXY(2000, 2000); // don't forget to refresh the drawing chart.invalidate(); }
Example 17
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 18
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); }