Search in sources :

Example 1 with Legend

use of com.github.mikephil.charting.components.Legend in project MPAndroidChart by PhilJay.

the class RadarChartActivitry method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_radarchart_noseekbar);
    TextView tv = (TextView) findViewById(R.id.textView);
    tv.setTypeface(mTfLight);
    tv.setTextColor(Color.WHITE);
    tv.setBackgroundColor(Color.rgb(60, 65, 82));
    mChart = (RadarChart) findViewById(R.id.chart1);
    mChart.setBackgroundColor(Color.rgb(60, 65, 82));
    mChart.getDescription().setEnabled(false);
    mChart.setWebLineWidth(1f);
    mChart.setWebColor(Color.LTGRAY);
    mChart.setWebLineWidthInner(1f);
    mChart.setWebColorInner(Color.LTGRAY);
    mChart.setWebAlpha(100);
    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    MarkerView mv = new RadarMarkerView(this, R.layout.radar_markerview);
    // For bounds control
    mv.setChartView(mChart);
    // Set the marker to the chart
    mChart.setMarker(mv);
    setData();
    mChart.animateXY(1400, 1400, Easing.EasingOption.EaseInOutQuad, Easing.EasingOption.EaseInOutQuad);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setTypeface(mTfLight);
    xAxis.setTextSize(9f);
    xAxis.setYOffset(0f);
    xAxis.setXOffset(0f);
    xAxis.setValueFormatter(new IAxisValueFormatter() {

        private String[] mActivities = new String[] { "Burger", "Steak", "Salad", "Pasta", "Pizza" };

        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return mActivities[(int) value % mActivities.length];
        }
    });
    xAxis.setTextColor(Color.WHITE);
    YAxis yAxis = mChart.getYAxis();
    yAxis.setTypeface(mTfLight);
    yAxis.setLabelCount(5, false);
    yAxis.setTextSize(9f);
    yAxis.setAxisMinimum(0f);
    yAxis.setAxisMaximum(80f);
    yAxis.setDrawLabels(false);
    Legend l = mChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setTypeface(mTfLight);
    l.setXEntrySpace(7f);
    l.setYEntrySpace(5f);
    l.setTextColor(Color.WHITE);
}
Also used : RadarMarkerView(com.xxmassdeveloper.mpchartexample.custom.RadarMarkerView) MarkerView(com.github.mikephil.charting.components.MarkerView) RadarMarkerView(com.xxmassdeveloper.mpchartexample.custom.RadarMarkerView) Legend(com.github.mikephil.charting.components.Legend) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) TextView(android.widget.TextView) AxisBase(com.github.mikephil.charting.components.AxisBase) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 2 with Legend

use of com.github.mikephil.charting.components.Legend in project HAR-Android by linw7.

the class HistoryActivity method show_pie_chart.

private void show_pie_chart(PieChart pie_chart, PieData pie_data) {
    // 半径
    pie_chart.setHoleRadius(60f);
    // 半透明圈
    pie_chart.setTransparentCircleRadius(64f);
    pie_chart.setDescription("");
    // 饼状图中间可以添加文字
    pie_chart.setDrawCenterText(true);
    pie_chart.setDrawHoleEnabled(true);
    // 初始旋转角度
    pie_chart.setRotationAngle(90);
    // 可以手动旋转
    pie_chart.setRotationEnabled(true);
    // 显示成百分比
    pie_chart.setUsePercentValues(true);
    // 饼状图中间的文字
    pie_chart.setCenterText("Activity Recognition");
    // 设置数据
    pie_chart.setData(pie_data);
    // 设置比例图
    Legend mLegend = pie_chart.getLegend();
    // 最右边显示
    mLegend.setPosition(Legend.LegendPosition.BELOW_CHART_CENTER);
    mLegend.setXEntrySpace(7f);
    mLegend.setYEntrySpace(5f);
    // 设置动画
    pie_chart.animateXY(1000, 1000);
}
Also used : Legend(com.github.mikephil.charting.components.Legend)

Example 3 with Legend

use of com.github.mikephil.charting.components.Legend in project HAR-Android by linw7.

the class PieActivity method show_pie_chart.

private void show_pie_chart(PieChart pie_chart, PieData pie_data) {
    // 半径
    pie_chart.setHoleRadius(60f);
    // 半透明圈
    pie_chart.setTransparentCircleRadius(64f);
    pie_chart.setDescription("");
    // 饼状图中间可以添加文字
    pie_chart.setDrawCenterText(true);
    pie_chart.setDrawHoleEnabled(true);
    // 初始旋转角度
    pie_chart.setRotationAngle(90);
    // 可以手动旋转
    pie_chart.setRotationEnabled(true);
    // 显示成百分比
    pie_chart.setUsePercentValues(true);
    // 饼状图中间的文字
    pie_chart.setCenterText("Activity Recognition");
    // 设置数据
    pie_chart.setData(pie_data);
    // 设置比例图
    Legend mLegend = pie_chart.getLegend();
    // 最右边显示
    mLegend.setPosition(Legend.LegendPosition.BELOW_CHART_CENTER);
    mLegend.setXEntrySpace(7f);
    mLegend.setYEntrySpace(5f);
    // 设置动画
    pie_chart.animateXY(1000, 1000);
}
Also used : Legend(com.github.mikephil.charting.components.Legend)

Example 4 with Legend

use of com.github.mikephil.charting.components.Legend in project Dxditor by kimi2009.

the class MainActivity method initGjxxView.

private void initGjxxView() {
    gjpiechart.setUsePercentValues(true);
    gjpiechart.getDescription().setEnabled(false);
    gjpiechart.setExtraOffsets(5, 10, 5, 5);
    gjpiechart.setDragDecelerationFrictionCoef(0.95f);
    gjpiechart.setCenterText("告警信息");
    gjpiechart.setExtraOffsets(20.f, 0.f, 20.f, 0.f);
    gjpiechart.setDrawHoleEnabled(true);
    gjpiechart.setHoleColor(Color.WHITE);
    gjpiechart.setTransparentCircleColor(Color.WHITE);
    gjpiechart.setTransparentCircleAlpha(110);
    gjpiechart.setHoleRadius(58f);
    gjpiechart.setTransparentCircleRadius(61f);
    gjpiechart.setDrawCenterText(true);
    gjpiechart.setRotationAngle(0);
    // enable rotation of the chart by touch
    gjpiechart.setRotationEnabled(true);
    gjpiechart.setHighlightPerTapEnabled(true);
    // gjpiechart.setUnit(" €");
    // gjpiechart.setDrawUnitsInChart(true);
    // add a selection listener点击事件
    // gjpiechart.setOnChartValueSelectedListener(this);
    gjpiechart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
    Legend l = gjpiechart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    l.setXEntrySpace(7f);
    l.setYEntrySpace(0f);
    l.setYOffset(0f);
    // entry label styling
    gjpiechart.setEntryLabelColor(Color.BLUE);
    gjpiechart.setEntryLabelTextSize(12f);
}
Also used : Legend(com.github.mikephil.charting.components.Legend)

Example 5 with Legend

use of com.github.mikephil.charting.components.Legend in project Osmand by osmandapp.

the class GpxUiHelper method setupGPXChart.

public static void setupGPXChart(OsmandApplication ctx, LineChart mChart, int yLabelsCount) {
    OsmandSettings settings = ctx.getSettings();
    boolean light = settings.isLightContent();
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        mChart.setHardwareAccelerationEnabled(false);
    } else {
        mChart.setHardwareAccelerationEnabled(true);
    }
    mChart.setTouchEnabled(true);
    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);
    mChart.setPinchZoom(true);
    mChart.setScaleYEnabled(false);
    mChart.setAutoScaleMinMaxEnabled(true);
    mChart.setDrawBorders(false);
    mChart.getDescription().setEnabled(false);
    mChart.setMaxVisibleValueCount(10);
    mChart.setMinOffset(0f);
    mChart.setDragDecelerationEnabled(false);
    mChart.setExtraTopOffset(24f);
    mChart.setExtraBottomOffset(16f);
    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    GPXMarkerView mv = new GPXMarkerView(mChart.getContext());
    // For bounds control
    mv.setChartView(mChart);
    // Set the marker to the chart
    mChart.setMarker(mv);
    mChart.setDrawMarkers(true);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setDrawAxisLine(false);
    xAxis.setDrawGridLines(true);
    xAxis.setGridLineWidth(1.5f);
    xAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_black_grid));
    xAxis.enableGridDashedLine(25f, Float.MAX_VALUE, 0f);
    xAxis.setPosition(BOTTOM);
    xAxis.setTextColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
    YAxis yAxis = mChart.getAxisLeft();
    yAxis.enableGridDashedLine(10f, 5f, 0f);
    yAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.divider_color));
    yAxis.setDrawAxisLine(false);
    yAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    yAxis.setXOffset(16f);
    yAxis.setYOffset(-6f);
    yAxis.setLabelCount(yLabelsCount);
    yAxis.setTextColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
    yAxis = mChart.getAxisRight();
    yAxis.enableGridDashedLine(10f, 5f, 0f);
    yAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.divider_color));
    yAxis.setDrawAxisLine(false);
    yAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    yAxis.setXOffset(16f);
    yAxis.setYOffset(-6f);
    yAxis.setLabelCount(yLabelsCount);
    yAxis.setTextColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));
    yAxis.setEnabled(false);
    Legend legend = mChart.getLegend();
    legend.setEnabled(false);
}
Also used : Legend(com.github.mikephil.charting.components.Legend) OsmandSettings(net.osmand.plus.OsmandSettings) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Aggregations

Legend (com.github.mikephil.charting.components.Legend)40 XAxis (com.github.mikephil.charting.components.XAxis)24 YAxis (com.github.mikephil.charting.components.YAxis)22 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)7 Typeface (android.graphics.Typeface)6 AxisBase (com.github.mikephil.charting.components.AxisBase)6 View (android.view.View)5 MyMarkerView (com.xxmassdeveloper.mpchartexample.custom.MyMarkerView)5 ArrayList (java.util.ArrayList)4 Paint (android.graphics.Paint)3 LineData (com.github.mikephil.charting.data.LineData)3 LineDataSet (com.github.mikephil.charting.data.LineDataSet)3 MarkerView (com.github.mikephil.charting.components.MarkerView)2 Entry (com.github.mikephil.charting.data.Entry)2 MyAxisValueFormatter (com.xxmassdeveloper.mpchartexample.custom.MyAxisValueFormatter)2 RadarMarkerView (com.xxmassdeveloper.mpchartexample.custom.RadarMarkerView)2 DecimalFormat (java.text.DecimalFormat)2 ValueAnimator (android.animation.ValueAnimator)1 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)1 SuppressLint (android.annotation.SuppressLint)1