com.github.mikephil.charting.charts.LineChart Java Examples

The following examples show how to use com.github.mikephil.charting.charts.LineChart. 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: LineChartExtensions.java    From exchange-rates-mvvm with Apache License 2.0 6 votes vote down vote up
@BindingAdapter({"bind:items"})
public static void populateDiagram(LineChart view, List<SingleValue> items) {

    if (null == items || items.size() == 0) {
        return;
    }
    List<Entry> entries = new ArrayList<>();
    for (int i = 0; i < items.size(); i++) {
        final SingleValue item = items.get(i);
        final Entry entry = new Entry(i, (float) item.getValue(), item);
        entries.add(entry);
    }
    LineDataSet dataSet = new LineDataSet(entries, view.getContext().getString(R.string.currency_value));
    LineData lineData = new LineData(dataSet);

    formatXAxisLabels(view, items);
    view.setData(lineData);
    view.invalidate();
}
 
Example #3
Source File: TrainedModelViewBinder.java    From Synapse with Apache License 2.0 6 votes vote down vote up
private LineDataSet prepareInitData(@NonNull LineChart chart, @NonNull List<Entry> entries) {
    final LineDataSet set = new LineDataSet(entries, "Accuracy");

    set.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    set.setAxisDependency(YAxis.AxisDependency.LEFT);
    set.setLineWidth(2F);
    set.setDrawCircleHole(false);
    set.setDrawCircles(false);
    set.setHighlightEnabled(false);
    set.setDrawFilled(true);

    final LineData group = new LineData(set);
    group.setDrawValues(false);

    chart.setData(group);

    return set;
}
 
Example #4
Source File: RecordingsAdapter.java    From go-bees with GNU General Public License v3.0 6 votes vote down vote up
RecordingViewHolder(View itemView) {
    super(itemView);

    // Get views
    viewHolder = itemView;
    card = (CardView) itemView.findViewById(R.id.card);
    recordingDate = (TextView) itemView.findViewById(R.id.recording_date);
    chart = (LineChart) itemView.findViewById(R.id.chart);
    moreIcon = (ImageView) itemView.findViewById(R.id.more_icon);

    // Set listeners
    viewHolder.setOnClickListener(this);
    viewHolder.setOnCreateContextMenuListener(this);
    moreIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Open Menu
            listener.onOpenMenuClick(viewHolder);
        }
    });

    background = card.getBackground();
    formatter = new SimpleDateFormat(
            context.getString(R.string.hive_recordings_date_format), Locale.getDefault());
}
 
Example #5
Source File: RideDetailActivity.java    From android-ponewheel with MIT License 6 votes vote down vote up
private void addDragListenerMarkerMaker(LineChart speedChart) {
    speedChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
        @Override
        public void onValueSelected(Entry entry, Highlight h) {
            Long entryX = (long) entry.getX();
            if (timeLocationMap.containsKey(entryX)) {
                clearAllMarkersFromMap();
                LatLng latLng = timeLocationMap.get(entryX);
                mapMarkers.add(googleMap.addMarker(new MarkerOptions().position(latLng)));
            }
        }

        @Override
        public void onNothingSelected() {
            clearAllMarkersFromMap();
        }
    });
}
 
Example #6
Source File: LineChartActivityColored.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_colored_lines);

    mCharts[0] = (LineChart) findViewById(R.id.chart1);
    mCharts[1] = (LineChart) findViewById(R.id.chart2);
    mCharts[2] = (LineChart) findViewById(R.id.chart3);
    mCharts[3] = (LineChart) findViewById(R.id.chart4);

    mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Bold.ttf");

    LineData data = getData(36, 100);
    data.setValueTypeface(mTf);

    for (int i = 0; i < mCharts.length; i++)
        // add some transparency to the color with "& 0x90FFFFFF"
        setupChart(mCharts[i], data, mColors[i % mColors.length]);
}
 
Example #7
Source File: KcaResoureLogFragment.java    From kcanotify with GNU General Public License v3.0 6 votes vote down vote up
public void setChartDataVisibility(View v, int k) {
    int interval_value = interval[position];
    int y_count = 7;
    LineChart chart = v.findViewById(R.id.reslog_chart);
    if (chart != null && chart.getLineData() != null) {
        ILineDataSet data = chart.getLineData().getDataSetByIndex(k);
        data.setVisible(is_draw_enabled[k]);
        int max_value = 0;
        int min_value = maximum[position];
        for (int i = 0; i < 4; i++) {
            if (is_draw_enabled[i]) {
                max_value = Math.max((int) chart.getLineData().getDataSetByIndex(i).getYMax(), max_value);
                min_value = Math.min((int) chart.getLineData().getDataSetByIndex(i).getYMin(), min_value);
            }
        }
        max_value = (int) (Math.ceil(max_value / (float) interval_value) * interval_value);
        min_value = (int) (Math.floor(min_value / (float) interval_value) * interval_value);
        int range = max_value - min_value;
        while (range % (y_count - 1) != 0) y_count -= 1;
        setChartYRange(chart, max_value, min_value, y_count, interval_value);
        chart.notifyDataSetChanged();
        chart.invalidate();
    }
}
 
Example #8
Source File: RealmWikiExample.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_realm_wiki);

    lineChart = (LineChart) findViewById(R.id.lineChart);
    barChart = (BarChart) findViewById(R.id.barChart);
    setup(lineChart);
    setup(barChart);

    lineChart.setExtraBottomOffset(5f);
    barChart.setExtraBottomOffset(5f);

    lineChart.getAxisLeft().setDrawGridLines(false);
    lineChart.getXAxis().setDrawGridLines(false);
    barChart.getAxisLeft().setDrawGridLines(false);
    barChart.getXAxis().setDrawGridLines(false);
}
 
Example #9
Source File: TrafficFragment.java    From gito-github-client with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void chartStyling(LineChart chart) {
    chart.setTouchEnabled(false);
    chart.setDescription("");
    chart.setAutoScaleMinMaxEnabled(false);
    chart.setNoDataTextColor(SettingsActivity.ThemePreferenceFragment.isLight(getContext()) ? Color.BLACK : Color.WHITE);
    YAxis axisRight = chart.getAxisRight();
    axisRight.setEnabled(false);
    chart.getLegend().setEnabled(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        chart.setNestedScrollingEnabled(false);
    }

    XAxis xAxis = chart.getXAxis();
    chartXAxisStyling(xAxis);
    YAxis yAxis = chart.getAxisLeft();
    chartYAxisStyling(yAxis);
}
 
Example #10
Source File: KcaResoureLogFragment.java    From kcanotify_h5-master with GNU General Public License v3.0 6 votes vote down vote up
public void setChartDataVisibility(View v, int k) {
    int interval_value = interval[position];
    int y_count = 7;
    LineChart chart = v.findViewById(R.id.reslog_chart);
    if (chart != null && chart.getLineData() != null) {
        ILineDataSet data = chart.getLineData().getDataSetByIndex(k);
        data.setVisible(is_draw_enabled[k]);
        int max_value = 0;
        int min_value = maximum[position];
        for (int i = 0; i < 4; i++) {
            if (is_draw_enabled[i]) {
                max_value = Math.max((int) chart.getLineData().getDataSetByIndex(i).getYMax(), max_value);
                min_value = Math.min((int) chart.getLineData().getDataSetByIndex(i).getYMin(), min_value);
            }
        }
        max_value = (int) (Math.ceil(max_value / (float) interval_value) * interval_value);
        min_value = (int) (Math.floor(min_value / (float) interval_value) * interval_value);
        int range = max_value - min_value;
        while (range % (y_count - 1) != 0) y_count -= 1;
        setChartYRange(chart, max_value, min_value, y_count, interval_value);
        chart.notifyDataSetChanged();
        chart.invalidate();
    }
}
 
Example #11
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 #12
Source File: PlayActivity.java    From Synapse with Apache License 2.0 5 votes vote down vote up
private void changeStyle(long id, LineChart chart, LineDataSet set) {
    final int index = (int) (id % FG.length);
    final Context context = chart.getContext();

    final int fg = ContextCompat.getColor(context, FG[index]);
    set.setColor(fg);
    set.setFillColor(fg);
    mLowerBg.setBackgroundColor(fg);

    getWindow().setBackgroundDrawableResource(BG[index]);
}
 
Example #13
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 #14
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 #15
Source File: LineChartHelper.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
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 #16
Source File: PowerChart.java    From AndroidApp with GNU Affero General Public License v3.0 5 votes vote down vote up
public PowerChart(LineChart powerChart,  Context context) {
    this.powerChart = powerChart;
    this.context = context;

    chartLabels = new ArrayList<>();
    chartValues = new ArrayList<>();
    
    setFormatting();
    powerData = createData();
    
}
 
Example #17
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 #18
Source File: DataUsageActivity.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.data_layout);
    setupActionBar();

    TASK_TAG = getClass().getSimpleName();
    progressLayout = (LinearLayout) findViewById(R.id.data_progressbar_ll);
    dataUsedText = (TextView) findViewById(R.id.dataUsedText);
    percentDataUsedView = (ProgressBar) findViewById(R.id.percentDataUsed);
    errorLayout = findViewById(R.id.data_error);
    errorTextView = (TextView) findViewById(R.id.tv_failure);
    chart = (LineChart) findViewById(R.id.mp_usage_chart);

    if (savedInstanceState != null) {
        labels = savedInstanceState.getStringArrayList("labels");
        downData = savedInstanceState.getParcelableArrayList("downData");
        totalData = savedInstanceState.getParcelableArrayList("totalData");
        percentLoadStatus = (LoadStatus) savedInstanceState
                .getSerializable("percentLoadStatus");
        dataLoadStatus = (LoadStatus) savedInstanceState.getSerializable("dataLoadStatus");
        switch (dataLoadStatus) {
            case NOT_STARTED:
                // defaults should suffice
                break;
            case LOADING:
                prepareToLoad();
                break;
            case SUCCEEDED:
                errorLayout.setVisibility(View.GONE);
                dataLoadSucceeded(new DataLoadSucceededEvent(labels, downData, totalData));
                break;
            case FAILED:
                dataLoadFailed(new DataLoadFailedEvent("", errorTextView.getText()));
                break;
        }
    }
    loadData(DataUsageActivity.getDataUrl(), false);
}
 
Example #19
Source File: LineChartExtensions.java    From exchange-rates-mvvm with Apache License 2.0 5 votes vote down vote up
private static void formatXAxisLabels(final LineChart view, final List<SingleValue> items) {
    final XAxis xAxis = view.getXAxis();
    xAxis.setValueFormatter((value, axis) -> {
        int index = (int) value;
        if (index >= items.size()) {
            return "";
        }
        return mDateFormatter.format(items.get(index).getDate());
    });
}
 
Example #20
Source File: TrainedModelViewBinder.java    From Synapse with Apache License 2.0 5 votes vote down vote up
private void changeStyle(long id, LineChart chart, LineDataSet set) {
    final int index = (int) (id % FG.length);
    final Context context = chart.getContext();

    final int fg = ContextCompat.getColor(context, FG[index]);
    set.setColor(fg);
    set.setFillColor(fg);

    chart.setGridBackgroundColor(ContextCompat.getColor(context, BG[index]));
}
 
Example #21
Source File: AudioFragment.java    From walt with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    logger = SimpleLogger.getInstance(getContext());

    audioTest = new AudioTest(getActivity());
    audioTest.setTestStateListener(this);

    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_audio, container, false);
    textView = (TextView) view.findViewById(R.id.txt_box_audio);
    textView.setMovementMethod(new ScrollingMovementMethod());
    startButton = view.findViewById(R.id.button_start_audio);
    stopButton = view.findViewById(R.id.button_stop_audio);
    chartLayout = view.findViewById(R.id.chart_layout);
    chart = (LineChart) view.findViewById(R.id.chart);
    latencyChart = (HistogramChart) view.findViewById(R.id.latency_chart);

    view.findViewById(R.id.button_close_chart).setOnClickListener(this);
    enableButtons();

    // Configure the audio mode spinner
    modeSpinner = (Spinner) view.findViewById(R.id.spinner_audio_mode);
    ArrayAdapter<CharSequence> modeAdapter = ArrayAdapter.createFromResource(getContext(),
            R.array.audio_mode_array, android.R.layout.simple_spinner_item);
    modeAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    modeSpinner.setAdapter(modeAdapter);

    return view;
}
 
Example #22
Source File: ScreenResponseFragment.java    From walt with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    timesToBlink = getIntPreference(getContext(), R.string.preference_screen_blinks, 20);
    shouldShowLatencyChart = getBooleanPreference(getContext(), R.string.preference_show_blink_histogram, true);
    enableFullScreen = getBooleanPreference(getContext(), R.string.preference_screen_fullscreen, true);
    if (getBooleanPreference(getContext(), R.string.preference_systrace, true)) {
        traceLogger = TraceLogger.getInstance();
    }
    waltDevice = WaltDevice.getInstance(getContext());
    logger = SimpleLogger.getInstance(getContext());

    // Inflate the layout for this fragment
    final View view = inflater.inflate(R.layout.fragment_screen_response, container, false);
    stopButton = view.findViewById(R.id.button_stop_screen_response);
    startButton = view.findViewById(R.id.button_start_screen_response);
    blackBox = (TextView) view.findViewById(R.id.txt_black_box_screen);
    fastSurfaceView = (FastPathSurfaceView) view.findViewById(R.id.fast_path_surface);
    spinner = (Spinner) view.findViewById(R.id.spinner_screen_response);
    buttonBarView = view.findViewById(R.id.button_bar);
    ArrayAdapter<CharSequence> modeAdapter = ArrayAdapter.createFromResource(getContext(),
            R.array.screen_response_mode_array, android.R.layout.simple_spinner_item);
    modeAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    spinner.setAdapter(modeAdapter);
    stopButton.setEnabled(false);
    blackBox.setMovementMethod(new ScrollingMovementMethod());
    brightnessChartLayout = view.findViewById(R.id.brightness_chart_layout);
    view.findViewById(R.id.button_close_chart).setOnClickListener(this);
    brightnessChart = (LineChart) view.findViewById(R.id.chart);
    latencyChart = (HistogramChart) view.findViewById(R.id.latency_chart);

    if (getBooleanPreference(getContext(), R.string.preference_auto_increase_brightness, true)) {
        increaseScreenBrightness();
    }
    return view;
}
 
Example #23
Source File: ReportAdapter.java    From privacy-friendly-pedometer with GNU General Public License v3.0 5 votes vote down vote up
public ChartViewHolder(View itemView) {
    super(itemView);
    mChart = (LineChart) itemView.findViewById(R.id.chart);
    mChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
    mChart.getAxisRight().setEnabled(false);
    mChart.setTouchEnabled(false);
    mChart.setDoubleTapToZoomEnabled(false);
    mChart.setPinchZoom(false);
    mChart.setDescription("");
}
 
Example #24
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 #25
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 #26
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 #27
Source File: KcaResoureLogFragment.java    From kcanotify with GNU General Public License v3.0 5 votes vote down vote up
public void setChartYRange(LineChart chart, int max_value, int min_value, int y_count, int interval) {
    int margin = interval;
    if (max_value + margin < maximum[position]) max_value  += margin;
    if (min_value - margin > 0) min_value -= margin;
    chart.getAxisLeft().setAxisMaximum(max_value);
    chart.getAxisLeft().setAxisMinimum(min_value);
    chart.getAxisLeft().setLabelCount(y_count, false);
    chart.getAxisRight().setAxisMaximum(max_value);
    chart.getAxisRight().setAxisMinimum(min_value);
    chart.getAxisRight().setLabelCount(y_count, false);
}
 
Example #28
Source File: RealmDatabaseActivityLine.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_linechart_noseekbar);

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

    mChart.getAxisLeft().setAxisMaxValue(150f);
    mChart.getAxisLeft().setAxisMinValue(0f);
    mChart.getAxisLeft().setDrawGridLines(false);
    mChart.getXAxis().setDrawGridLines(false);
}
 
Example #29
Source File: KcaResoureLogFragment.java    From kcanotify_h5-master with GNU General Public License v3.0 5 votes vote down vote up
public void setChartYRange(LineChart chart, int max_value, int min_value, int y_count, int interval) {
    int margin = interval;
    if (max_value + margin < maximum[position]) max_value  += margin;
    if (min_value - margin > 0) min_value -= margin;
    chart.getAxisLeft().setAxisMaximum(max_value);
    chart.getAxisLeft().setAxisMinimum(min_value);
    chart.getAxisLeft().setLabelCount(y_count, false);
    chart.getAxisRight().setAxisMaximum(max_value);
    chart.getAxisRight().setAxisMinimum(min_value);
    chart.getAxisRight().setLabelCount(y_count, false);
}
 
Example #30
Source File: MiniDateGraph.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public LineChart getChart() {
    return mChart;
}