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

The following examples show how to use com.github.mikephil.charting.charts.LineChart#setData() . 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: 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 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: 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 4
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 5
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 6
Source File: ChartsActivity.java    From CameraV with GNU General Public License v3.0 4 votes vote down vote up
private LineChart addChart (String label, LineData data)
{
	LineChart chart = new LineChart(this);
       //chart.setOnChartGestureListener(this);
       //chart.setOnChartValueSelectedListener(this);

	chart.getAxisLeft().setStartAtZero(false);
	
       // no description text
       chart.setDescription("");
       chart.setNoDataTextDescription("");

       // enable value highlighting
       chart.setHighlightEnabled(true);

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

       // enable scaling and dragging
       chart.setDragEnabled(true);
       chart.setScaleEnabled(true);
       // chart.setScaleXEnabled(true);
       // chart.setScaleYEnabled(true);

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

       // set data
       chart.setData(data);        
      
       TextView tv = new TextView (this);
       tv.setText(label);        
       LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
               LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);     
       
       viewChartGroup.addView(tv,params);
       
       int dpHeight = 300;
      
       int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpHeight, getResources().getDisplayMetrics());

       params = new LinearLayout.LayoutParams(
               LayoutParams.MATCH_PARENT, height);     
       
       int dpMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, getResources().getDisplayMetrics());
       params.setMargins(dpMargin,dpMargin,dpMargin,dpMargin);
       
       chart.setLayoutParams(params);              
       
       viewChartGroup.addView(chart,params);
       
       return chart;
}
 
Example 7
Source File: CalibrationLinearityActivity.java    From NoiseCapture with GNU General Public License v3.0 4 votes vote down vote up
private void updateLineChart() {
    LineChart lineChart = getLineChart();
    if(lineChart == null) {
        return;
    }
    if(freqLeqStats.isEmpty()) {
        return;
    }
    float YMin = Float.MAX_VALUE;
    float YMax = Float.MIN_VALUE;

    ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>();

    // Read all white noise values for indexing before usage
    int idStep = 0;
    double referenceLevel = freqLeqStats.get(0).whiteNoiseLevel.getGlobaldBaValue();
    for(LinearCalibrationResult result : freqLeqStats) {
        ArrayList<Entry> yMeasure = new ArrayList<Entry>();
        int idfreq = 0;
        for (LeqStats leqStat : result.measure) {
            float dbLevel = (float)leqStat.getLeqMean();
            YMax = Math.max(YMax, dbLevel);
            YMin = Math.min(YMin, dbLevel);
            yMeasure.add(new Entry(dbLevel, idfreq++));
        }
        LineDataSet freqSet = new LineDataSet(yMeasure, String.format(Locale.getDefault(),"%d dB",
                (int)(result.whiteNoiseLevel.getGlobaldBaValue() - referenceLevel)));
        freqSet.setColor(ColorTemplate.COLORFUL_COLORS[idStep % ColorTemplate.COLORFUL_COLORS.length]);
        freqSet.setFillColor(ColorTemplate.COLORFUL_COLORS[idStep % ColorTemplate.COLORFUL_COLORS.length]);
        freqSet.setValueTextColor(Color.WHITE);
        freqSet.setCircleColorHole(ColorTemplate.COLORFUL_COLORS[idStep % ColorTemplate.COLORFUL_COLORS.length]);
        freqSet.setDrawValues(false);
        freqSet.setDrawFilled(true);
        freqSet.setFillAlpha(255);
        freqSet.setDrawCircles(true);
        freqSet.setMode(LineDataSet.Mode.LINEAR);
        dataSets.add(freqSet);
        idStep++;
    }


    ArrayList<String> xVals = new ArrayList<String>();
    double[] freqs = FFTSignalProcessing.computeFFTCenterFrequency(AudioProcess.REALTIME_SAMPLE_RATE_LIMITATION);
    for (double freqValue : freqs) {
        xVals.add(Spectrogram.formatFrequency((int)freqValue));
    }

    // create a data object with the datasets
    LineData data = new LineData(xVals, dataSets);
    lineChart.setData(data);
    YAxis yl = lineChart.getAxisLeft();
    yl.setAxisMinValue(YMin - 3);
    yl.setAxisMaxValue(YMax + 3);
    lineChart.invalidate();
}
 
Example 8
Source File: UserProfileActivity.java    From zhizhihu with Apache License 2.0 4 votes vote down vote up
private void initHeaderView(UserDetail detail) {

        View headerView = LayoutInflater.from(this)
                .inflate(R.layout.layout_user_profile_header, mTopAnswerListView, false);
        mUserAvatarImg = ButterKnife.findById(headerView, R.id.user_avatar_img);
        mUserDescriptionTxt = ButterKnife.findById(headerView, R.id.user_description_txt);
        mUserSignatureTxt = ButterKnife.findById(headerView, R.id.user_signature_txt);
        mAgreeCountTxt = ButterKnife.findById(headerView, R.id.agree_count_txt);
        mFollowerCountTxt = ButterKnife.findById(headerView, R.id.follower_count_txt);
        mFavCountTxt = ButterKnife.findById(headerView, R.id.fav_count_txt);
        mAskCountTxt = ButterKnife.findById(headerView, R.id.ask_count_txt);
        mAnswerCountTxt = ButterKnife.findById(headerView, R.id.answer_count_txt);
        mPostCountTxt = ButterKnife.findById(headerView, R.id.post_count_txt);


        List<String> xData = new ArrayList<>();
        List<Entry> answerDatas = new ArrayList<>();
        List<Entry> agreeDatas = new ArrayList<>();
        List<Entry> followerDatas = new ArrayList<>();

        for (int i = 0; i < detail.getTrend().size(); i++) {
            UserDetail.Trend trend = detail.getTrend().get(i);

            xData.add(trend.getDate());
            answerDatas.add(new Entry(Float.parseFloat(trend.getAnswer()), i));
            agreeDatas.add(new Entry(Float.parseFloat(trend.getAgree()), i));
            followerDatas.add(new Entry(Float.parseFloat(trend.getFollower()), i));
        }
        LineDataSet answerDataSet = new LineDataSet(answerDatas, "回答数");
        LineDataSet agreeDataSet = new LineDataSet(agreeDatas, "赞同数");
        LineDataSet followerDataSet = new LineDataSet(followerDatas, "粉丝数");

        LineChart trendsChart = ButterKnife.findById(headerView, R.id.trends_chart);
        LineChart agreeChart = ButterKnife.findById(headerView, R.id.agree_chart);
        LineChart followerChart = ButterKnife.findById(headerView, R.id.follower_chart);

        XAxis xAxis = trendsChart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        LineData data = new LineData(xData, answerDataSet);
        trendsChart.setData(data);
        trendsChart.invalidate();

        XAxis agreeX = agreeChart.getXAxis();
        agreeX.setPosition(XAxis.XAxisPosition.BOTTOM);
        LineData agreeData = new LineData(xData, agreeDataSet);
        agreeChart.setData(agreeData);
        agreeChart.invalidate();

        XAxis followerX = followerChart.getXAxis();
        followerX.setPosition(XAxis.XAxisPosition.BOTTOM);
        LineData followerData = new LineData(xData, followerDataSet);
        followerChart.setData(followerData);
        followerChart.invalidate();


        Glide.with(this)
                .load(detail.getAvatar())
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(mUserAvatarImg);

        mUserDescriptionTxt.setText(detail.getDescription());
        mUserSignatureTxt.setText(detail.getSignature());

        mAgreeCountTxt.setText(detail.getDetail().getAgree());
        mFollowerCountTxt.setText(detail.getDetail().getFollower());
        mFavCountTxt.setText(detail.getDetail().getFav());
        mAskCountTxt.setText(detail.getDetail().getAsk());
        mAnswerCountTxt.setText(detail.getDetail().getAnswer());
        mPostCountTxt.setText(detail.getDetail().getPost());

        mTopAnswerListView.addHeaderView(headerView);

    }
 
Example 9
Source File: GraphActivity.java    From Simple-Accounting with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_graph);

	ActionBar actionBar = getSupportActionBar();
	if (actionBar != null) {
		// Show the Up button in the action bar.
		actionBar.setDisplayHomeAsUpEnabled(true);
	}

	// programmatically create a LineChart
	LineChart chart = findViewById(R.id.chart);

	Session session = getIntent().getParcelableExtra(GRAPH_SESSION);
	int[] updateDate = {getIntent().getIntExtra(GRAPH_UPDATE_MONTH, -1),
			getIntent().getIntExtra(GRAPH_UPDATE_YEAR, -1)};

	((TextView) findViewById(R.id.title)).setText(Utils.INSTANCE.getTitle(this, session, updateDate));

	loadMonthAsyncTask = new LoadMonthAsyncTask(session, null,
			new TableGeneral(this), (result) -> {
		if(result.getDbRows().length > 0) {
			List<Entry> entries = new ArrayList<>();
			BigDecimal bigDecimal = BigDecimal.ZERO;

			for (String[] s : result.getDbRows()) {
				if(s[0] != null) {
					int day = parseInt(s[0]);

					float credit = s[2] != null ? Float.parseFloat(s[2]) : 0,
							debit = s[3] != null ? Float.parseFloat(s[3]) : 0;

					bigDecimal = bigDecimal.add(new BigDecimal(credit));
					bigDecimal = bigDecimal.subtract(new BigDecimal(debit));
					entries.add(new Entry(day, bigDecimal.floatValue()));
				}
			}

			if(entries.size() > 0) {
				for(int i = 0; i < entries.size(); i++) {
					int entriesInDay = 0, day = (int) entries.get(i).getX();
					for(int j = i; j < entries.size() && day == entries.get(j).getX(); j++) {
						entriesInDay++;
					}

					for(int j = i, k = 0; j < entries.size() && day == entries.get(j).getX(); j++, k++) {
						float separationWidth =  1 / (entriesInDay + 1f);//the amount of space between points in the same day (X axis)
						entries.get(j).setX(day + (k+1) * separationWidth);
					}

					while(day == entries.get(i).getX()) i++;
				}

				LineDataSet dataSet = new LineDataSet(entries, null);
				dataSet.setValueFormatter(new MoneyFormatter());

				chart.setData(new LineData(dataSet));
			} else {
				chart.setNoDataText(getString(R.string.nothing_to_graph));
				Snackbar.make(chart, R.string.without_day_data_is_not_charted, Snackbar.LENGTH_LONG).show();
			}
		} else {
			chart.setNoDataText(getString(R.string.nothing_to_graph));
		}

		chart.notifyDataSetChanged();
		chart.invalidate();
	});

	loadMonthAsyncTask.execute();

	chart.getAxisRight().setEnabled(false);
	chart.getXAxis().setValueFormatter(new DeleteNonWholeFormatter());
	chart.getXAxis().setAxisMinimum(0);
	chart.getXAxis().setAxisMaximum(32);
	chart.getXAxis().setDrawGridLines(false);
	chart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
	chart.getLegend().setEnabled(false);
	chart.setDescription(null);
	chart.setNoDataText(getString(R.string.loading));
}
 
Example 10
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 11
Source File: LineChartActivityColored.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
private void setupChart(LineChart chart, LineData data, int color) {

        // no description text
        chart.setDescription("");
        chart.setNoDataTextDescription("You need to provide data for the chart.");
        
        // mChart.setDrawHorizontalGrid(false);
        //
        // enable / disable grid background
        chart.setDrawGridBackground(false);
//        chart.getRenderer().getGridPaint().setGridColor(Color.WHITE & 0x70FFFFFF);

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

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

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

        chart.setBackgroundColor(color);
        
        // set custom chart offsets (automatic offset calculation is hereby disabled)
        chart.setViewPortOffsets(10, 0, 10, 0);

        // add data
        chart.setData(data);

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

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

        chart.getXAxis().setEnabled(false);

        // animate calls invalidate()...
        chart.animateX(2500);
    }
 
Example 12
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 13
Source File: Proxmark3TuneResultActivity.java    From Walrus with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_proxmark3_tune_results);

    Proxmark3Device.TuneResult tuneResult = Parcels.unwrap(getIntent().getParcelableExtra(
            EXTRA_TUNE_RESULT));

    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    if (tuneResult.lf) {
        setResultInfo(tuneResult.peakV, 2.948f, 14.730f, R.id.lfOk);
        ((TextView) findViewById(R.id.lf125)).setText(
                getResources().getString(R.string.tune_voltage, tuneResult.v125));
        ((TextView) findViewById(R.id.lf134)).setText(
                getResources().getString(R.string.tune_voltage, tuneResult.v134));
        ((TextView) findViewById(R.id.lfOptimal)).setText(
                getResources().getString(R.string.tune_peak_voltage, tuneResult.peakV,
                        (tuneResult.peakF / 1000)));

        LineChart lfChart = findViewById(R.id.lfChart);
        if (tuneResult.lfVoltages != null) {
            List<Entry> entries = new ArrayList<>();
            for (int i = 255; i >= 19; --i) {
                entries.add(new Entry(12e6f / (i + 1) / 1e3f, tuneResult.lfVoltages[i]));
            }

            LineDataSet lineDataSet = new LineDataSet(entries, getString(R.string.lf));
            lineDataSet.setColor(Color.BLACK);
            lineDataSet.setCircleColor(Color.BLUE);

            LineData lineData = new LineData(lineDataSet);

            lfChart.setData(lineData);
            lfChart.setDescription(null);
            lfChart.getLegend().setEnabled(false);
            lfChart.getXAxis().setPosition(XAxis.XAxisPosition.BOTTOM);
            lfChart.getAxisRight().setEnabled(false);
            lfChart.invalidate();
        } else {
            lfChart.setVisibility(View.GONE);
        }
    } else {
        findViewById(R.id.lf).setVisibility(View.GONE);
    }

    if (tuneResult.hf) {
        setResultInfo(tuneResult.hfVoltage, 3.167f, 7.917f, R.id.hfOk);
        ((TextView) findViewById(R.id.hfV)).setText(
                getResources().getString(R.string.tune_voltage, tuneResult.hfVoltage));
    } else {
        findViewById(R.id.hf).setVisibility(View.GONE);
    }
}
 
Example 14
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 15
Source File: LineChartActivityColored.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
private void setupChart(LineChart chart, LineData data, int color) {

        ((LineDataSet) data.getDataSetByIndex(0)).setCircleHoleColor(color);

        // no description text
        chart.getDescription().setEnabled(false);

        // chart.setDrawHorizontalGrid(false);
        //
        // enable / disable grid background
        chart.setDrawGridBackground(false);
//        chart.getRenderer().getGridPaint().setGridColor(Color.WHITE & 0x70FFFFFF);

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

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

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

        chart.setBackgroundColor(color);

        // set custom chart offsets (automatic offset calculation is hereby disabled)
        chart.setViewPortOffsets(10, 0, 10, 0);

        // add data
        chart.setData(data);

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

        chart.getAxisLeft().setEnabled(false);
        chart.getAxisLeft().setSpaceTop(40);
        chart.getAxisLeft().setSpaceBottom(40);
        chart.getAxisRight().setEnabled(false);

        chart.getXAxis().setEnabled(false);

        // animate calls invalidate()...
        chart.animateX(2500);
    }
 
Example 16
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 17
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 18
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;
}