Java Code Examples for com.github.mikephil.charting.charts.LineChart#setDrawGridBackground()

The following examples show how to use com.github.mikephil.charting.charts.LineChart#setDrawGridBackground() . 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: DynamicalAddingActivity.java    From Stayfit with Apache License 2.0 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_linechart_noseekbar);

        mChart = (LineChart) findViewById(R.id.chart1);
        mChart.setOnChartValueSelectedListener(this);
        mChart.setDrawGridBackground(false);
        mChart.setDescription("");
        
        // add an empty data object
        mChart.setData(new LineData());
//        mChart.getXAxis().setDrawLabels(false);
//        mChart.getXAxis().setDrawGridLines(false);

        mChart.invalidate();
    }
 
Example 2
Source File: CalibrationLinearityActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private void initLine() {
    LineChart lineChart = getLineChart();
    if(lineChart == null) {
        return;
    }
    lineChart.setDescription("");

    lineChart.setDrawGridBackground(false);

    // enable scaling and dragging

    Legend l = lineChart.getLegend();
    l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
    l.setTextColor(Color.WHITE);

    YAxis yl = lineChart.getAxisLeft();
    yl.setTextColor(Color.WHITE);
    yl.setGridColor(Color.WHITE);
    lineChart.getAxisRight().setEnabled(false);

    XAxis xl = lineChart.getXAxis();
    xl.setDrawGridLines(false);
    xl.setTextColor(Color.WHITE);
    xl.setGridColor(Color.WHITE);
    xl.setPosition(XAxis.XAxisPosition.BOTTOM);
    xl.setDrawAxisLine(true);
    xl.setLabelRotationAngle(-90);
    xl.setDrawLabels(true);
    xl.setLabelsToSkip(0);
}
 
Example 3
Source File: PerformanceLineChart.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_performance_linechart);

    mTvCount = (TextView) findViewById(R.id.tvValueCount);
    mSeekBarValues = (SeekBar) findViewById(R.id.seekbarValues);
    mTvCount.setText("500");

    mSeekBarValues.setProgress(500);
    
    mSeekBarValues.setOnSeekBarChangeListener(this);

    mChart = (LineChart) findViewById(R.id.chart1);
    mChart.setDrawGridBackground(false);

    // 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);

    // if disabled, scaling can be done on x- and y-axis separately
    mChart.setPinchZoom(false);
          
    mChart.getAxisLeft().setDrawGridLines(false);
    mChart.getAxisRight().setEnabled(false);
    mChart.getXAxis().setDrawGridLines(true);
    mChart.getXAxis().setDrawAxisLine(false);

    // dont forget to refresh the drawing
    mChart.invalidate();
}
 
Example 4
Source File: RecordingFragment.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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: TrainedModelViewBinder.java    From Synapse with Apache License 2.0 5 votes vote down vote up
private void prepareChart(@NonNull LineChart chart) {
    chart.getDescription().setEnabled(false);
    chart.setTouchEnabled(false);
    chart.setDragEnabled(false);
    chart.setScaleEnabled(false);
    chart.setHighlightPerDragEnabled(false);
    chart.setPinchZoom(false);
    chart.setDrawGridBackground(true);
    chart.getLegend().setEnabled(false);
    chart.getAxisRight().setEnabled(false);
    chart.getAxisLeft().setEnabled(false);
    chart.getXAxis().setEnabled(false);
    chart.setViewPortOffsets(0, 0, 0, 0);
}
 
Example 6
Source File: PlayActivity.java    From Synapse with Apache License 2.0 5 votes vote down vote up
private void initChart(@NonNull LineChart chart) {
    chart.getDescription().setEnabled(false);
    chart.setTouchEnabled(false);
    chart.setDragEnabled(false);
    chart.setScaleEnabled(false);
    chart.setHighlightPerDragEnabled(false);
    chart.setPinchZoom(false);
    chart.setDrawGridBackground(false);
    chart.getLegend().setEnabled(false);
    chart.getAxisRight().setEnabled(false);
    chart.getXAxis().setEnabled(false);
    chart.getAxisLeft().setEnabled(false);
    chart.getXAxis().setEnabled(false);
    chart.setViewPortOffsets(0, 0, 0, 0);
}
 
Example 7
Source File: DrawChartActivity.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_draw_chart);

    mChart = (LineChart) findViewById(R.id.chart1);

    // listener for selecting and drawing
    mChart.setOnChartValueSelectedListener(this);
    mChart.setOnDrawListener(this);

    // if disabled, drawn datasets with the finger will not be automatically
    // finished
    // mChart.setAutoFinish(true);
    mChart.setDrawGridBackground(false);

    // add dummy-data to the chart
    initWithDummyData();

    Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

    XAxis xl = mChart.getXAxis();
    xl.setTypeface(tf);
    xl.setAvoidFirstLastClipping(true);

    YAxis yl = mChart.getAxisLeft();
    yl.setTypeface(tf);

    mChart.getLegend().setEnabled(false);

    // mChart.setYRange(-40f, 40f, true);
    // call this to reset the changed y-range
    // mChart.resetYRange(true);
}
 
Example 8
Source File: RecordingsAdapter.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 9
Source File: Utils.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
public static void setupChart(@NonNull LineChart chart, boolean small, @ColorRes @Nullable Integer fgColorRes) {
    chart.clear();

    int fgColor;
    Context context = chart.getContext();
    if (fgColorRes == null)
        fgColor = CommonUtils.resolveAttrAsColor(context, R.attr.colorOnSurface);
    else
        fgColor = ContextCompat.getColor(context, fgColorRes);

    chart.setDescription(null);
    chart.setDrawGridBackground(false);
    chart.setBackgroundColor(Color.alpha(0));
    chart.setTouchEnabled(false);

    Legend legend = chart.getLegend();
    legend.setTextColor(fgColor);
    legend.setEnabled(true);

    LineData data = new LineData();
    data.setValueTextColor(fgColor);
    chart.setData(data);

    YAxis ya = chart.getAxisLeft();
    ya.setAxisLineColor(fgColor);
    ya.setTextColor(fgColor);
    ya.setTextSize(small ? 8 : 9);
    ya.setAxisMinimum(0);
    ya.setDrawAxisLine(false);
    ya.setLabelCount(small ? 4 : 8, true);
    ya.setEnabled(true);
    ya.setDrawGridLines(true);
    ya.setGridColor(fgColor);
    ya.setValueFormatter(new CustomYAxisValueFormatter());

    chart.getAxisRight().setEnabled(false);
    chart.getXAxis().setEnabled(false);

    data.addDataSet(initUploadSet(context));
    data.addDataSet(initDownloadSet(context));

    chart.invalidate();
}
 
Example 10
Source File: LineChartCard.java    From ResearchStack with Apache License 2.0 4 votes vote down vote up
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 11
Source File: MultiLineChartActivity.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@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);
    mSeekBarX.setOnSeekBarChangeListener(this);

    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
    mSeekBarY.setOnSeekBarChangeListener(this);

    mChart = (LineChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    
    mChart.setDrawGridBackground(false);
    mChart.setDescription("");
    mChart.setDrawBorders(false);

    mChart.getAxisLeft().setDrawAxisLine(false);
    mChart.getAxisLeft().setDrawGridLines(false);
    mChart.getAxisRight().setDrawAxisLine(false);
    mChart.getAxisRight().setDrawGridLines(false);
    mChart.getXAxis().setDrawAxisLine(false);
    mChart.getXAxis().setDrawGridLines(false);

    // 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);

    mSeekBarX.setProgress(20);
    mSeekBarY.setProgress(100);

    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.RIGHT_OF_CHART);
}
 
Example 12
Source File: InvertedLineChartActivity.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_linechart);

    tvX = (TextView) findViewById(R.id.tvXMax);
    tvY = (TextView) findViewById(R.id.tvYMax);

    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);

    mSeekBarX.setProgress(45);
    mSeekBarY.setProgress(100);

    mSeekBarY.setOnSeekBarChangeListener(this);
    mSeekBarX.setOnSeekBarChangeListener(this);

    mChart = (LineChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawGridBackground(false);
    
    // no description text
    mChart.setDescription("");

    // enable touch gestures
    mChart.setTouchEnabled(true);

    // enable scaling and dragging
    mChart.setDragEnabled(true);
    mChart.setScaleEnabled(true);

    // if disabled, scaling can be done on x- and y-axis separately
    mChart.setPinchZoom(true);

    // set an alternative background color
    // mChart.setBackgroundColor(Color.GRAY);

    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);

    // set the marker to the chart
    mChart.setMarkerView(mv);
    
    XAxis xl = mChart.getXAxis();
    xl.setAvoidFirstLastClipping(true);
    
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setInverted(true);
    leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)
    
    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setEnabled(false);

    // add data
    setData(25, 50);

    // // restrain the maximum scale-out factor
    // mChart.setScaleMinima(3f, 3f);
    //
    // // center the view to a specific position inside the chart
    // mChart.centerViewPort(10, 50);

    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();

    // modify the legend ...
    // l.setPosition(LegendPosition.LEFT_OF_CHART);
    l.setForm(LegendForm.LINE);

    // dont forget to refresh the drawing
    mChart.invalidate();
}
 
Example 13
Source File: LineChartActivity2.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_linechart);

        tvX = (TextView) findViewById(R.id.tvXMax);
        tvY = (TextView) findViewById(R.id.tvYMax);
        mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
        mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);

        mSeekBarX.setProgress(45);
        mSeekBarY.setProgress(100);

        mSeekBarY.setOnSeekBarChangeListener(this);
        mSeekBarX.setOnSeekBarChangeListener(this);

        mChart = (LineChart) findViewById(R.id.chart1);
        mChart.setOnChartValueSelectedListener(this);
        
        // no description text
        mChart.setDescription("");
        mChart.setNoDataTextDescription("You need to provide data for the chart.");

        // enable touch gestures
        mChart.setTouchEnabled(true);
        
        mChart.setDragDecelerationFrictionCoef(0.9f);

        // enable scaling and dragging
        mChart.setDragEnabled(true);
        mChart.setScaleEnabled(true);
        mChart.setDrawGridBackground(false);
        mChart.setHighlightPerDragEnabled(true);

        // if disabled, scaling can be done on x- and y-axis separately
        mChart.setPinchZoom(true);

        // set an alternative background color
        mChart.setBackgroundColor(Color.LTGRAY);

        // add data
        setData(20, 30);

        mChart.animateX(2500);

        Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");

        // get the legend (only possible after setting data)
        Legend l = mChart.getLegend();

        // modify the legend ...
        // l.setPosition(LegendPosition.LEFT_OF_CHART);
        l.setForm(LegendForm.LINE);
        l.setTypeface(tf);
        l.setTextSize(11f);
        l.setTextColor(Color.WHITE);
        l.setPosition(LegendPosition.BELOW_CHART_LEFT);
//        l.setYOffset(11f);

        XAxis xAxis = mChart.getXAxis();
        xAxis.setTypeface(tf);
        xAxis.setTextSize(12f);
        xAxis.setTextColor(Color.WHITE);
        xAxis.setDrawGridLines(false);
        xAxis.setDrawAxisLine(false);
        xAxis.setSpaceBetweenLabels(1);

        YAxis leftAxis = mChart.getAxisLeft();
        leftAxis.setTypeface(tf);
        leftAxis.setTextColor(ColorTemplate.getHoloBlue());
        leftAxis.setAxisMaxValue(200f);
        leftAxis.setAxisMinValue(0f);
        leftAxis.setDrawGridLines(true);
        
        YAxis rightAxis = mChart.getAxisRight();
        rightAxis.setTypeface(tf);
        rightAxis.setTextColor(Color.RED);
        rightAxis.setAxisMaxValue(900);
        rightAxis.setAxisMinValue(-200);
        rightAxis.setDrawGridLines(false);
        rightAxis.setDrawZeroLine(false);
    }
 
Example 14
Source File: RealtimeLineChartActivity.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@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 15
Source File: ChartFragment.java    From Liapp with Apache License 2.0 4 votes vote down vote up
@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 16
Source File: FragmentPrice.java    From Lunary-Ethereum-Wallet with GNU General Public License v3.0 4 votes vote down vote up
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 17
Source File: ChartUtil.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 显示图表
 *
 * @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 18
Source File: FragmentPrice.java    From bcm-android with GNU General Public License v3.0 4 votes vote down vote up
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 19
Source File: ComplexityFragment.java    From Stayfit with Apache License 2.0 3 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_simple_line, container, false);
    
    mChart = (LineChart) v.findViewById(R.id.lineChart1);
    
    mChart.setDescription("");

    mChart.setDrawGridBackground(false);
    
    mChart.setData(getComplexity());
    mChart.animateX(3000);
    
    Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"OpenSans-Light.ttf");
    
    Legend l = mChart.getLegend();
    l.setTypeface(tf);
    
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(tf);
    leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)
    
    mChart.getAxisRight().setEnabled(false);
    
    XAxis xAxis = mChart.getXAxis();
    xAxis.setEnabled(false);
    
    return v;
}
 
Example 20
Source File: SineCosineFragment.java    From Stayfit with Apache License 2.0 3 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_simple_line, container, false);
    
    mChart = (LineChart) v.findViewById(R.id.lineChart1);
    
    mChart.setDescription("");

    mChart.setDrawGridBackground(false);
    
    mChart.setData(generateLineData());
    mChart.animateX(3000);
    
    Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"OpenSans-Light.ttf");
    
    Legend l = mChart.getLegend();
    l.setTypeface(tf);
    
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(tf);
    leftAxis.setAxisMaxValue(1.2f);
    leftAxis.setAxisMinValue(-1.2f);
    
    mChart.getAxisRight().setEnabled(false);
    
    XAxis xAxis = mChart.getXAxis();
    xAxis.setEnabled(false);
    
    return v;
}