Java Code Examples for com.github.mikephil.charting.components.XAxis#setPosition()
The following examples show how to use
com.github.mikephil.charting.components.XAxis#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: 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 2
Source File: BarChartHelper.java From Ticket-Analysis with MIT License | 5 votes |
public BarChart generateBarChartConfig(BarChart barChart) { XAxis xAxis = barChart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); //定制X轴是在图表上方还是下方。 xAxis.setDrawAxisLine(true); xAxis.setDrawGridLines(false); xAxis.setGranularity(1f);//放大的时候X值不增多 YAxis yAxisRight = barChart.getAxisRight(); yAxisRight.setEnabled(false); YAxis yAxisLeft = barChart.getAxisLeft(); yAxisLeft.setAxisMinimum(0); barChart.setDrawBarShadow(false); barChart.setPinchZoom(true); barChart.setFitBars(true); // if more than 60 entries are displayed in the chart, no values will be // drawn barChart.setMaxVisibleValueCount(60); barChart.setDrawValueAboveBar(true); barChart.getDescription().setEnabled(false); barChart.setNoDataText("无数据"); Legend l = barChart.getLegend(); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER); l.setOrientation(Legend.LegendOrientation.HORIZONTAL); //设置单方向和双方向缩放 true x,y方向可以同时控制,false只能控制x方向的缩小放大或者Y方向的缩小放大 l.setDrawInside(false); l.setFormSize(8f); l.setXEntrySpace(4f); return barChart; }
Example 3
Source File: Results.java From NoiseCapture with GNU General Public License v3.0 | 5 votes |
public void initSpectrumChart(){ sChart.setPinchZoom(false); sChart.setDoubleTapToZoomEnabled(false); sChart.setDrawBarShadow(false); sChart.setDescription(""); sChart.setPinchZoom(false); sChart.setDrawGridBackground(false); sChart.setHighlightPerTapEnabled(true); sChart.setHighlightPerDragEnabled(false); sChart.setDrawHighlightArrow(true); sChart.setDrawValueAboveBar(true); // XAxis parameters: hide all XAxis xls = sChart.getXAxis(); xls.setPosition(XAxisPosition.BOTTOM); xls.setDrawAxisLine(true); xls.setDrawGridLines(false); xls.setLabelRotationAngle(-90); xls.setDrawLabels(true); xls.setTextColor(Color.WHITE); xls.setLabelsToSkip(0); // YAxis parameters (left): main axis for dB values representation YAxis yls = sChart.getAxisLeft(); yls.setDrawAxisLine(true); yls.setDrawGridLines(true); yls.setAxisMaxValue(110.f); yls.setStartAtZero(true); yls.setTextColor(Color.WHITE); yls.setGridColor(Color.WHITE); // YAxis parameters (right): no axis, hide all YAxis yrs = sChart.getAxisRight(); yrs.setEnabled(false); //return true; }
Example 4
Source File: MeasurementActivity.java From NoiseCapture with GNU General Public License v3.0 | 5 votes |
public void initVueMeter(){ mChart.setDrawBarShadow(false); mChart.setDescription(""); mChart.setPinchZoom(false); mChart.setDrawGridBackground(false); mChart.setMaxVisibleValueCount(0); mChart.setScaleXEnabled(false); // Disable scaling on the X-axis // XAxis parameters: hide all XAxis xlv = mChart.getXAxis(); xlv.setPosition(XAxisPosition.BOTTOM); xlv.setDrawAxisLine(false); xlv.setDrawGridLines(false); xlv.setDrawLabels(false); // YAxis parameters (left): main axis for dB values representation YAxis ylv = mChart.getAxisLeft(); ylv.setDrawAxisLine(false); ylv.setDrawGridLines(true); ylv.setAxisMaxValue(110.f); ylv.setStartAtZero(true); ylv.setTextColor(Color.WHITE); ylv.setGridColor(Color.WHITE); ylv.setValueFormatter(new dBValueFormatter()); // YAxis parameters (right): no axis, hide all YAxis yrv = mChart.getAxisRight(); yrv.setEnabled(false); //return true; }
Example 5
Source File: ScrollViewActivity.java From StockChart-MPAndroidChart with MIT License | 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); setTitle("ScrollViewActivity"); chart = findViewById(R.id.chart1); chart.getDescription().setEnabled(false); // 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); chart.getLegend().setEnabled(false); setData(10); chart.setFitBars(true); }
Example 6
Source File: ScatterChartFrag.java From Stayfit with Apache License 2.0 | 5 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.frag_simple_scatter, container, false); mChart = (ScatterChart) v.findViewById(R.id.scatterChart1); mChart.setDescription(""); Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"OpenSans-Light.ttf"); MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view); mChart.setMarkerView(mv); mChart.setDrawGridBackground(false); mChart.setData(generateScatterData(6, 10000, 200)); XAxis xAxis = mChart.getXAxis(); xAxis.setEnabled(true); xAxis.setPosition(XAxisPosition.BOTTOM); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setTypeface(tf); YAxis rightAxis = mChart.getAxisRight(); rightAxis.setTypeface(tf); rightAxis.setDrawGridLines(false); Legend l = mChart.getLegend(); l.setWordWrapEnabled(true); l.setTypeface(tf); l.setFormSize(14f); l.setTextSize(9f); // increase the space between legend & bottom and legend & content l.setYOffset(13f); mChart.setExtraBottomOffset(16f); return v; }
Example 7
Source File: FragmentBarChart.java From fingen with Apache License 2.0 | 5 votes |
private void setupBarChart() { mBarChart.setDrawBarShadow(false); mBarChart.setDrawValueAboveBar(true); mBarChart.setDescription(""); mBarChart.setMaxVisibleValueCount(Integer.MAX_VALUE); mBarChart.setPinchZoom(false); mBarChart.setDrawGridBackground(false); mBarChart.setOnChartValueSelectedListener(this); mBarChart.setHighlightPerDragEnabled(false); int textColor = ColorUtils.getTextColor(getActivity()); XAxis xl = mBarChart.getXAxis(); xl.setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE); xl.setDrawAxisLine(true); xl.setDrawGridLines(true); xl.setGridLineWidth(0.3f); xl.setTextColor(textColor); YAxis yl = mBarChart.getAxisLeft(); yl.setDrawAxisLine(true); yl.setDrawGridLines(true); yl.setGridLineWidth(0.3f); yl.setAxisMinValue(0f); yl.setTextColor(textColor); YAxis yr = mBarChart.getAxisRight(); yr.setDrawAxisLine(true); yr.setDrawGridLines(false); yr.setAxisMinValue(0f); yr.setTextColor(textColor); mBarChart.setXAxisRenderer(new FgHorizontalBarChartRenderer(getActivity(), mBarChart.getViewPortHandler(), mBarChart.getXAxis(), mBarChart.getTransformer(YAxis.AxisDependency.LEFT), mBarChart)); mBarChart.getLegend().setEnabled(false); }
Example 8
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 9
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 10
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 11
Source File: LineChartItem.java From Stayfit with Apache License 2.0 | 4 votes |
@Override public View getView(int position, View convertView, Context c) { ViewHolder holder = null; if (convertView == null) { holder = new ViewHolder(); convertView = LayoutInflater.from(c).inflate( R.layout.list_item_linechart, null); holder.chart = (LineChart) convertView.findViewById(R.id.chart); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // apply styling // holder.chart.setValueTypeface(mTf); holder.chart.setDescription(""); holder.chart.setDrawGridBackground(false); XAxis xAxis = holder.chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setTypeface(mTf); xAxis.setDrawGridLines(false); xAxis.setDrawAxisLine(true); YAxis leftAxis = holder.chart.getAxisLeft(); leftAxis.setTypeface(mTf); leftAxis.setLabelCount(5, false); leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true) YAxis rightAxis = holder.chart.getAxisRight(); rightAxis.setTypeface(mTf); rightAxis.setLabelCount(5, false); rightAxis.setDrawGridLines(false); rightAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true) // set data holder.chart.setData((LineData) mChartData); // do not forget to refresh the chart // holder.chart.invalidate(); holder.chart.animateX(750); return convertView; }
Example 12
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 13
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 14
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 15
Source File: ListViewBarChartActivity.java From Stayfit with Apache License 2.0 | 4 votes |
@Override public View getView(int position, View convertView, ViewGroup parent) { BarData data = getItem(position); ViewHolder holder = null; if (convertView == null) { holder = new ViewHolder(); convertView = LayoutInflater.from(getContext()).inflate( R.layout.list_item_barchart, null); holder.chart = (BarChart) convertView.findViewById(R.id.chart); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } // apply styling data.setValueTypeface(mTf); data.setValueTextColor(Color.BLACK); holder.chart.setDescription(""); holder.chart.setDrawGridBackground(false); XAxis xAxis = holder.chart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setTypeface(mTf); xAxis.setDrawGridLines(false); YAxis leftAxis = holder.chart.getAxisLeft(); leftAxis.setTypeface(mTf); leftAxis.setLabelCount(5, false); leftAxis.setSpaceTop(15f); YAxis rightAxis = holder.chart.getAxisRight(); rightAxis.setTypeface(mTf); rightAxis.setLabelCount(5, false); rightAxis.setSpaceTop(15f); // set data holder.chart.setData(data); // do not forget to refresh the chart // holder.chart.invalidate(); holder.chart.animateY(700, Easing.EasingOption.EaseInCubic); return convertView; }
Example 16
Source File: BarChartCard.java From ResearchStack with Apache License 2.0 | 4 votes |
private void initializeViews() { titleTextView = (TextView) findViewById(R.id.view_chart_bar_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 = (BarChart) findViewById(R.id.view_chart_bar); chart.getLegend().setEnabled(false); chart.setDescription(""); chart.setDrawBorders(false); chart.setDrawValueAboveBar(false); chart.setDrawGridBackground(false); chart.setDrawBarShadow(false); chart.setDrawHighlightArrow(false); chart.setPinchZoom(false); chart.setExtraLeftOffset(0); chart.setExtraRightOffset(0); chart.setExtraBottomOffset(8); chart.setExtraTopOffset(0); chart.setTouchEnabled(true); chart.setDragEnabled(true); XAxis xAxis = chart.getXAxis(); xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); xAxis.setDrawAxisLine(false); xAxis.setYOffset(16); xAxis.setDrawGridLines(false); xAxis.setLabelsToSkip(0); 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(false); YAxis yAxisRight = chart.getAxisRight(); yAxisRight.setDrawAxisLine(false); yAxisRight.setDrawGridLines(false); yAxisRight.setDrawZeroLine(false); yAxisRight.setDrawLabels(false); }
Example 17
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 18
Source File: CandleStickChartActivity.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_candlechart); tvX = (TextView) findViewById(R.id.tvXMax); tvY = (TextView) findViewById(R.id.tvYMax); mSeekBarX = (SeekBar) findViewById(R.id.seekBar1); mSeekBarX.setOnSeekBarChangeListener(this); mSeekBarY = (SeekBar) findViewById(R.id.seekBar2); mSeekBarY.setOnSeekBarChangeListener(this); mChart = (CandleStickChart) findViewById(R.id.chart1); mChart.setBackgroundColor(Color.WHITE); 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); XAxis xAxis = mChart.getXAxis(); xAxis.setPosition(XAxisPosition.BOTTOM); xAxis.setSpaceBetweenLabels(2); xAxis.setDrawGridLines(false); YAxis leftAxis = mChart.getAxisLeft(); // leftAxis.setEnabled(false); leftAxis.setLabelCount(7, false); leftAxis.setDrawGridLines(false); leftAxis.setDrawAxisLine(false); YAxis rightAxis = mChart.getAxisRight(); rightAxis.setEnabled(false); // rightAxis.setStartAtZero(false); // setting data mSeekBarX.setProgress(40); mSeekBarY.setProgress(100); mChart.getLegend().setEnabled(false); // Legend l = mChart.getLegend(); // l.setPosition(LegendPosition.BELOW_CHART_CENTER); // l.setFormSize(8f); // l.setFormToTextSpace(4f); // l.setXEntrySpace(6f); // mChart.setDrawLegend(false); }
Example 19
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 20
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); }