Java Code Examples for com.github.mikephil.charting.components.XAxis#setDrawGridLines()
The following examples show how to use
com.github.mikephil.charting.components.XAxis#setDrawGridLines() .
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: DailyBarChart.java From AndroidApp with GNU Affero General Public License v3.0 | 6 votes |
private void setFormatting() { barChart.setDrawGridBackground(false); barChart.getLegend().setEnabled(false); barChart.getAxisLeft().setEnabled(false); barChart.getAxisRight().setEnabled(false); barChart.setHardwareAccelerationEnabled(true); barChart.getDescription().setEnabled(false); barChart.setNoDataText(""); barChart.setTouchEnabled(false); barChart.setExtraBottomOffset(2); XAxis xAxis2 = barChart.getXAxis(); xAxis2.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis2.setTextColor(ContextCompat.getColor(context, R.color.lightGrey)); xAxis2.setTextSize(context.getResources().getInteger(R.integer.chartValueTextSize)); xAxis2.setDrawGridLines(false); xAxis2.setDrawAxisLine(false); xAxis2.setValueFormatter(new LabelAxisFormatter(chartLabels)); }
Example 2
Source File: PFAChart.java From privacy-friendly-shopping-list with Apache License 2.0 | 6 votes |
private void setXlabels(List<String> labelList) { int valuesSelectedItemPos = cache.getValuesSpinner().getSelectedItemPosition(); String[] labels = new String[ labelList.size() ]; labelList.toArray(labels); PFAXAxisLabels xFormatter = new PFAXAxisLabels(labels); chart.setMarkerView(new PFAMarkerView(context, xFormatter, valuesSelectedItemPos, cache.getNumberScale())); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setDrawGridLines(false); xAxis.setGranularity(1f); xAxis.setLabelCount(5); xAxis.setValueFormatter(xFormatter); }
Example 3
Source File: TrafficFragment.java From gito-github-client with Apache License 2.0 | 6 votes |
@SuppressWarnings("deprecation") private void chartXAxisStyling(XAxis xAxis) { xAxis.setPosition(XAxis.XAxisPosition.TOP); xAxis.setTextColor(getResources().getColor(R.color.traffic_chart_text_color_light)); xAxis.setDrawAxisLine(true); xAxis.setDrawGridLines(false); xAxis.setCenterAxisLabels(true); xAxis.setValueFormatter(new AxisValueFormatter() { @Override public String getFormattedValue(float value, AxisBase axis) { return Utils.humanReadable((long) value); } @Override public int getDecimalDigits() { return 0; } }); }
Example 4
Source File: ModelDetailActivity.java From Synapse with Apache License 2.0 | 5 votes |
private void setXAxis(int epochs) { final XAxis axis = mChart.getXAxis(); axis.setEnabled(true); axis.setAxisMinimum(1F); axis.setAxisMaximum(epochs); axis.setPosition(XAxis.XAxisPosition.BOTTOM); axis.setDrawAxisLine(true); axis.setDrawGridLines(false); axis.setGranularity(1F); axis.setAvoidFirstLastClipping(true); mChart.getAxisRight().setDrawAxisLine(true); }
Example 5
Source File: LineChartHelper.java From Ticket-Analysis with MIT License | 5 votes |
public LineChart generateLineChartConfig(LineChart lineChart) { //XY轴配置 XAxis xAxis = lineChart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); //定制X轴是在图表上方还是下方。 xAxis.setDrawGridLines(false); xAxis.setGranularity(1); YAxis yAxisRight = lineChart.getAxisRight(); yAxisRight.setEnabled(false); YAxis yAxisLeft = lineChart.getAxisLeft(); yAxisLeft.setAxisMinimum(0); yAxisLeft.setGranularity(1); //背景设置 lineChart.setDrawGridBackground(false);//表格背景绘制 lineChart.setBackgroundColor(AppContext.getContext().getResources().getColor(R.color.white)); //Legend定制 lineChart.getLegend().setPosition(Legend.LegendPosition.ABOVE_CHART_LEFT); lineChart.getLegend().setForm(Legend.LegendForm.CIRCLE);//Legend样式 //图表描述 lineChart.setDescription(null); // 设置无数据文本提示 lineChart.setNoDataText("暂无数据"); //设置单方向和双方向缩放 true x,y方向可以同时控制,false只能控制x方向的缩小放大或者Y方向的缩小放大 lineChart.setPinchZoom(true); return lineChart; }
Example 6
Source File: RecordingsAdapter.java From go-bees with GNU General Public License v3.0 | 5 votes |
/** * Setup chart (axis, grid, etc.). * * @param lineChart chart to setup. * @param data chart with the data. * @param firstTimestamp seconds timestamp of the first record (used as initial reference). */ private void setupChart(LineChart lineChart, LineData data, long firstTimestamp) { // General setup lineChart.setDrawGridBackground(false); lineChart.setDrawBorders(false); lineChart.setViewPortOffsets(50, 0, 50, 50); lineChart.getDescription().setEnabled(false); lineChart.getLegend().setEnabled(false); lineChart.setTouchEnabled(false); lineChart.setNoDataText(context.getString(R.string.no_flight_act_data_available)); // X axis setup IAxisValueFormatter xAxisFormatter = new HourAxisValueFormatter(firstTimestamp); XAxis xAxis = lineChart.getXAxis(); xAxis.setValueFormatter(xAxisFormatter); xAxis.setDrawGridLines(false); xAxis.setDrawAxisLine(false); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setCenterAxisLabels(false); xAxis.setTextColor(ContextCompat.getColor(context, R.color.colorIcons)); // Y axis setup YAxis yAxis = lineChart.getAxisLeft(); yAxis.setAxisMaximum(40); yAxis.setAxisMinimum(0); yAxis.setDrawLabels(false); yAxis.setDrawAxisLine(false); yAxis.setDrawGridLines(true); lineChart.getAxisRight().setEnabled(false); // Add data lineChart.setData(data); }
Example 7
Source File: ScrollViewActivity.java From Stayfit with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_scrollview); mChart = (BarChart) findViewById(R.id.chart1); mChart.setDescription(""); // scaling can now only be done on x- and y-axis separately mChart.setPinchZoom(false); mChart.setDrawBarShadow(false); mChart.setDrawGridBackground(false); XAxis xAxis = mChart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setLabelsToSkip(0); xAxis.setDrawGridLines(false); mChart.getAxisLeft().setDrawGridLines(false); mChart.getLegend().setEnabled(false); setData(10); }
Example 8
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 9
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 10
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 11
Source File: StackedBarActivityNegative.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_age_distribution); setTitle("Age Distribution Austria"); mChart = (HorizontalBarChart) findViewById(R.id.chart1); mChart.setOnChartValueSelectedListener(this); mChart.setDrawGridBackground(false); mChart.setDescription(""); // scaling can now only be done on x- and y-axis separately mChart.setPinchZoom(false); mChart.setDrawBarShadow(false); mChart.setDrawValueAboveBar(true); mChart.getAxisLeft().setEnabled(false); mChart.getAxisRight().setAxisMaxValue(25f); mChart.getAxisRight().setAxisMinValue(-25f); mChart.getAxisRight().setDrawGridLines(false); mChart.getAxisRight().setDrawZeroLine(true); mChart.getAxisRight().setLabelCount(7, false); mChart.getAxisRight().setValueFormatter(new CustomFormatter()); mChart.getAxisRight().setTextSize(9f); XAxis xAxis = mChart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTH_SIDED); xAxis.setDrawGridLines(false); xAxis.setDrawAxisLine(false); xAxis.setTextSize(9f); Legend l = mChart.getLegend(); l.setPosition(LegendPosition.BELOW_CHART_RIGHT); 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> yValues = new ArrayList<BarEntry>(); yValues.add(new BarEntry(new float[]{ -10, 10 }, 0)); yValues.add(new BarEntry(new float[]{ -12, 13 }, 1)); yValues.add(new BarEntry(new float[]{ -15, 15 }, 2)); yValues.add(new BarEntry(new float[]{ -17, 17 }, 3)); yValues.add(new BarEntry(new float[]{ -19, 20 }, 4)); yValues.add(new BarEntry(new float[]{ -19, 19 }, 5)); yValues.add(new BarEntry(new float[]{ -16, 16 }, 6)); yValues.add(new BarEntry(new float[]{ -13, 14 }, 7)); yValues.add(new BarEntry(new float[]{ -10, 11 }, 8)); yValues.add(new BarEntry(new float[]{ -5, 6 }, 9)); yValues.add(new BarEntry(new float[]{ -1, 2 }, 10)); BarDataSet set = new BarDataSet(yValues, "Age Distribution"); set.setValueFormatter(new CustomFormatter()); set.setValueTextSize(7f); set.setAxisDependency(YAxis.AxisDependency.RIGHT); set.setBarSpacePercent(40f); set.setColors(new int[] {Color.rgb(67,67,72), Color.rgb(124,181,236)}); set.setStackLabels(new String[]{ "Men", "Women" }); String []xVals = new String[]{"0-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80", "80-90", "90-100", "100+"}; BarData data = new BarData(xVals, set); mChart.setData(data); mChart.invalidate(); }
Example 12
Source File: CandleStickChartActivity.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_candlechart); setTitle("CandleStickChartActivity"); 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.setBackgroundColor(Color.WHITE); 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); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setDrawGridLines(false); YAxis leftAxis = chart.getAxisLeft(); // leftAxis.setEnabled(false); leftAxis.setLabelCount(7, false); leftAxis.setDrawGridLines(false); leftAxis.setDrawAxisLine(false); YAxis rightAxis = chart.getAxisRight(); rightAxis.setEnabled(false); // rightAxis.setStartAtZero(false); // setting data seekBarX.setProgress(40); seekBarY.setProgress(100); chart.getLegend().setEnabled(false); }
Example 13
Source File: AnotherBarActivity.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("AnotherBarActivity"); 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); // 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.setDrawBarShadow(false); chart.setDrawGridBackground(false); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setDrawGridLines(false); chart.getAxisLeft().setDrawGridLines(false); // setting data seekBarX.setProgress(10); seekBarY.setProgress(100); // add a nice and smooth animation chart.animateY(1500); chart.getLegend().setEnabled(false); }
Example 14
Source File: BarChartPositiveNegative.java From StockChart-MPAndroidChart with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_barchart_noseekbar); setTitle("BarChartPositiveNegative"); chart = findViewById(R.id.chart1); chart.setBackgroundColor(Color.WHITE); chart.setExtraTopOffset(-30f); chart.setExtraBottomOffset(10f); chart.setExtraLeftOffset(70f); chart.setExtraRightOffset(70f); chart.setDrawBarShadow(false); chart.setDrawValueAboveBar(true); chart.getDescription().setEnabled(false); // scaling can now only be done on x- and y-axis separately chart.setPinchZoom(false); chart.setDrawGridBackground(false); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setTypeface(tfRegular); xAxis.setDrawGridLines(false); xAxis.setDrawAxisLine(false); xAxis.setTextColor(Color.LTGRAY); xAxis.setTextSize(13f); xAxis.setLabelCount(5); xAxis.setCenterAxisLabels(true); xAxis.setGranularity(1f); YAxis left = chart.getAxisLeft(); left.setDrawLabels(false); left.setSpaceTop(25f); left.setSpaceBottom(25f); left.setDrawAxisLine(false); left.setDrawGridLines(false); left.setDrawZeroLine(true); // draw a zero line left.setZeroLineColor(Color.GRAY); left.setZeroLineWidth(0.7f); chart.getAxisRight().setEnabled(false); chart.getLegend().setEnabled(false); // THIS IS THE ORIGINAL DATA YOU WANT TO PLOT final List<Data> data = new ArrayList<>(); data.add(new Data(0f, -224.1f, "12-29")); data.add(new Data(1f, 238.5f, "12-30")); data.add(new Data(2f, 1280.1f, "12-31")); data.add(new Data(3f, -442.3f, "01-01")); data.add(new Data(4f, -2280.1f, "01-02")); xAxis.setValueFormatter(new ValueFormatter() { @Override public String getFormattedValue(float value) { return data.get(Math.min(Math.max((int) value, 0), data.size()-1)).xAxisValue; } }); setData(data); }
Example 15
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 16
Source File: LineChartCard.java From ResearchStack with Apache License 2.0 | 4 votes |
private void initializeViews() { titleTextView = (TextView) findViewById(R.id.view_chart_line_title); titleTextView.setText(titleText); titleTextView.setTextColor(titleTextColor); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize); titleTextView.setTypeface(Typeface.create(titleTextTypeface, Typeface.NORMAL)); expand = (ImageView) findViewById(R.id.view_chart_line_expand); if (expandTintColor != 0) { Drawable drawable = expand.getDrawable(); drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, expandTintColor); expand.setImageDrawable(drawable); } chart = (LineChart) findViewById(R.id.view_chart_line); chart.getLegend().setEnabled(false); chart.setDescription(""); chart.setDrawBorders(false); chart.setDrawGridBackground(false); chart.setPinchZoom(false); chart.setTouchEnabled(true); chart.setDragEnabled(true); chart.setExtraLeftOffset(0); chart.setExtraBottomOffset(8); chart.setExtraTopOffset(0); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setDrawAxisLine(false); xAxis.setDrawGridLines(false); xAxis.setLabelsToSkip(0); xAxis.setXOffset(16); xAxis.setTextSize(chartXAxisTextSize); xAxis.setTextColor(chartXAxisTextColor); xAxis.setTypeface(Typeface.create(chartXAxisTextTypeface, Typeface.NORMAL)); YAxis yAxisLeft = chart.getAxisLeft(); yAxisLeft.setDrawAxisLine(false); yAxisLeft.setDrawGridLines(false); yAxisLeft.setDrawZeroLine(false); yAxisLeft.setDrawLabels(true); yAxisLeft.setShowOnlyMinMax(true); yAxisLeft.setXOffset(16); yAxisLeft.setTextSize(chartYAxisTextSize); yAxisLeft.setTextColor(chartYAxisTextColor); yAxisLeft.setTypeface(Typeface.create(chartYAxisTextTypeface, Typeface.NORMAL)); YAxis yAxisRight = chart.getAxisRight(); yAxisRight.setDrawAxisLine(false); yAxisRight.setDrawGridLines(false); yAxisRight.setDrawZeroLine(false); yAxisRight.setDrawLabels(false); yAxisRight.setSpaceTop(0); }
Example 17
Source File: ListViewBarChartActivity.java From StockChart-MPAndroidChart with MIT License | 4 votes |
@SuppressLint("InflateParams") @NonNull @Override public View getView(int position, View convertView, @NonNull ViewGroup parent) { BarData data = getItem(position); ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = LayoutInflater.from(getContext()).inflate( R.layout.list_item_barchart, null); holder.chart = convertView.findViewById(R.id.chart); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // apply styling if (data != null) { data.setValueTypeface(tfLight); data.setValueTextColor(Color.BLACK); } holder.chart.getDescription().setEnabled(false); holder.chart.setDrawGridBackground(false); XAxis xAxis = holder.chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setTypeface(tfLight); xAxis.setDrawGridLines(false); YAxis leftAxis = holder.chart.getAxisLeft(); leftAxis.setTypeface(tfLight); leftAxis.setLabelCount(5, false); leftAxis.setSpaceTop(15f); YAxis rightAxis = holder.chart.getAxisRight(); rightAxis.setTypeface(tfLight); rightAxis.setLabelCount(5, false); rightAxis.setSpaceTop(15f); // set data holder.chart.setData(data); holder.chart.setFitBars(true); // do not forget to refresh the chart // holder.chart.invalidate(); holder.chart.animateY(700); return convertView; }
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); }
Example 19
Source File: MeasurementSpectrumFragment.java From NoiseCapture with GNU General Public License v3.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if(view == null) { // Inflate the layout for this fragment view = inflater.inflate(R.layout.fragment_measurement_spectrum, container, false); BarChart sChart = (BarChart) view.findViewById(R.id.spectrumChart); sChart.setDrawBarShadow(false); sChart.setDescription(""); sChart.getLegend().setEnabled(false); sChart.setTouchEnabled(false); sChart.setPinchZoom(false); sChart.setDrawGridBackground(false); sChart.setMaxVisibleValueCount(0); sChart.setHorizontalScrollBarEnabled(false); sChart.setVerticalScrollBarEnabled(false); sChart.setNoDataTextDescription(getText(R.string.no_data_text_description).toString()); // XAxis parameters: XAxis xls = sChart.getXAxis(); xls.setPosition(XAxis.XAxisPosition.BOTTOM); xls.setDrawAxisLine(true); xls.setDrawGridLines(false); xls.setDrawLabels(true); xls.setTextColor(Color.WHITE); xls.setAvoidFirstLastClipping(false); // YAxis parameters (left): main axis for dB values representation YAxis yls = sChart.getAxisLeft(); yls.setDrawAxisLine(true); yls.setDrawGridLines(true); yls.setAxisMaxValue(100.f); yls.setAxisMinValue(0f); yls.setTextColor(Color.WHITE); yls.setGridColor(Color.WHITE); yls.setSpaceBottom(0); yls.setSpaceTop(0); yls.setValueFormatter(new SPLValueFormatter()); // YAxis parameters (right): no axis, hide all YAxis yrs = sChart.getAxisRight(); yrs.setEnabled(false); } return view; }
Example 20
Source File: LineChartActivity.java From iMoney with Apache License 2.0 | 4 votes |
@Override protected void initData() { ivBack.setVisibility(View.VISIBLE); tvTitle.setText("折线图"); ivSetting.setVisibility(View.GONE); // 加载本地的字体库 mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); // 设置图表的描述 lineChart.setDescription("我的资产的变化情况"); // 是否设置网格背景 lineChart.setDrawGridBackground(false); // 获取图表的x轴 XAxis xAxis = lineChart.getXAxis(); // 设置x轴的显示位置 xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); // 设置x轴的字体 xAxis.setTypeface(mTf); // 是否绘制x轴网格线 xAxis.setDrawGridLines(false); // 是否绘制x轴轴线 xAxis.setDrawAxisLine(true); // 设置Y轴 YAxis leftAxis = lineChart.getAxisLeft(); // 设置Y轴的子体 leftAxis.setTypeface(mTf); // 参数1:设置左边区间的个数,参数2:是否需要均匀分布:false均匀 leftAxis.setLabelCount(5, false); YAxis rightAxis = lineChart.getAxisRight(); rightAxis.setTypeface(mTf); rightAxis.setLabelCount(5, false); rightAxis.setDrawGridLines(false); // 设置右边为不显示状态 rightAxis.setEnabled(false); // set data lineChart.setData(generateDataLine()); // do not forget to refresh the chart // lineChart.invalidate(); lineChart.animateX(750); // 设置x轴方向的动画 }