本文整理汇总了Java中com.github.mikephil.charting.charts.LineChart.setData方法的典型用法代码示例。如果您正苦于以下问题:Java LineChart.setData方法的具体用法?Java LineChart.setData怎么用?Java LineChart.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.mikephil.charting.charts.LineChart
的用法示例。
在下文中一共展示了LineChart.setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
@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.getDescription().setEnabled(false);
// add an empty data object
mChart.setData(new LineData());
// mChart.getXAxis().setDrawLabels(false);
// mChart.getXAxis().setDrawGridLines(false);
mChart.invalidate();
}
示例2: prepareInitData
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
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;
}
示例3: populateDiagram
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
@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();
}
示例4: onCreate
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
@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();
}
示例5: setLineChart
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
/**
* Set the line chart pattern
* @param lineChart chart
* @param chartData pie chart data
* @param month data
* @param typeface Typeface font
*/
public static void setLineChart(Context context, LineChart lineChart, ChartData<?> chartData,
final String[] month, Typeface typeface) {
// apply styling
lineChart.getDescription().setEnabled(false);
lineChart.setDrawGridBackground(false);
// create a custom MarkerView (extend MarkerView) and specify the layout to use for it
SalaryMarker marker = new SalaryMarker(context, R.layout.marker_salary_detail);
marker.setChartView(lineChart); // For bounds control
lineChart.setMarker(marker);
//fix crash com.github.mikephil.charting.charts.Chart.drawMarkers(Chart.java:731)
lineChart.setDrawMarkers(false);
XAxis xAxis = lineChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTypeface(typeface);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(true);
xAxis.setValueFormatter(new LineChartValueFormatter(month));
xAxis.setLabelCount(month.length / 2, true);//xAxis label count
YAxis leftAxis = lineChart.getAxisLeft();
leftAxis.setTypeface(typeface);
leftAxis.setLabelCount(9, false);
leftAxis.setAxisMinimum(0f);
YAxis rightAxis = lineChart.getAxisRight();
rightAxis.setTypeface(typeface);
rightAxis.setDrawGridLines(false);
rightAxis.setAxisMinimum(0f);
Legend l = lineChart.getLegend();
l.setWordWrapEnabled(true);
l.setTypeface(typeface);
l.setFormSize(14f);
l.setTextSize(9f);
lineChart.setData((LineData) chartData);
lineChart.animateX(DURATION_SHORT);
}
示例6: setupChart
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
/**
* 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);
}
示例7: enter
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
@Override
public void enter(int view) {
super.enter(view);
lchScope = (LineChart) findViewById(R.id.scope_chart);
lchScope.setDrawGridBackground(false);
//lchScope.setNoDataTextDescription("Select a Value in the ObjectBrowser to start the Scope");
mData = new LineData();
mData.setValueTextColor(Color.GREEN);
// add empty data
if (mObject1 != null) lchScope.setData(mData);
txtScopeLastValue = (TextView) findViewById(R.id.txtScopeLastValue);
txtScopeObjectName = (TextView) findViewById(R.id.txtScopeObjectName);
mObject1 = ScopeHelper.object1;
mField1 = ScopeHelper.field1;
mElement1 = ScopeHelper.element1;
mObject2 = ScopeHelper.object2;
mField2 = ScopeHelper.field2;
mElement2 = ScopeHelper.element2;
if (mObject1 != null) {
setScopeMetric(mObject1, mField1, mElement1);
//lchScope.setDescription(mObject1 + "/" + mField1 + "/" + mElement1);
}
if (mObject2 != null) {
setScopeMetric(mObject2, mField2, mElement2);
//lchScope.setDescription(mObject1 + "/" + mField1 + "/" + mElement1);
}
txtScopeObjectName.setText(mObject1);
relTime = System.currentTimeMillis();
}
示例8: setupGraphic
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
private void setupGraphic(LineChart chart, List<Entry> entries, float axisMinimum, IAxisValueFormatter formatter) {
LineDataSet dataSet = new LineDataSet(entries, Constants.EMPTY_STRING);
dataSet.setDrawCircles(false);
dataSet.setDrawCircleHole(false);
dataSet.setLineWidth(ResourcesHelper.getDimensionPixelSize(this, R.dimen.half_dp));
dataSet.setFillColor(getResources().getColor(R.color.colorPrimary));
dataSet.setDrawFilled(true);
dataSet.setFillAlpha(Constants.Chart.ALPHA_FILL);
dataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
dataSet.setColor(getResources().getColor(R.color.colorPrimary));
dataSet.setDrawValues(false);
LineData lineData = new LineData(dataSet);
chart.getDescription().setEnabled(false);
chart.setTouchEnabled(false);
chart.getLegend().setEnabled(false);
chart.getAxisRight().setEnabled(false);
chart.getXAxis().setDrawLabels(false);
chart.getXAxis().setDrawGridLines(false);
chart.getAxisLeft().removeAllLimitLines();
chart.getAxisLeft().setTextColor(getResources().getColor(R.color.gray));
chart.getAxisLeft().setAxisMinimum(axisMinimum);
chart.getAxisLeft().setTextSize(Constants.Chart.LABEL_SIZE);
chart.getAxisLeft().setValueFormatter(formatter);
chart.animateX(Constants.Chart.ANIMATION_DURATION, Easing.EasingOption.EaseInSine);
chart.setData(lineData);
chart.invalidate();
}
示例9: setupAltitudeChart
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
protected void setupAltitudeChart(){
TextView textAltitude = new TextView(this);
textAltitude.setText("Altitude:");
textAltitude.setTextColor(getResources().getColor(R.color.hike_blue_grey));
mAltitudeChartContainer.addView(textAltitude);
if(mCoordinatesList!=null) {
int listSize = mCoordinatesList.size();
if (listSize > 0) {
mAltitudeChart = new LineChart(this);
List<Entry> entries = new ArrayList<>(listSize);
for (int i = 0; i < listSize; i++) {
entries.add(new Entry((float) mCoordinatesList.get(i).getAltitude(), i));
}
LineDataSet altitudePoints = new LineDataSet(entries, "Altitude during Hike");
mAltitudeChart.setData(new LineData(Collections.nCopies(listSize, ""), altitudePoints));
mAltitudeChart.setDescription("");
mAltitudeChart.animateX(3500);
mAltitudeChart.getAxisLeft().setEnabled(false);
mAltitudeChart.setTouchEnabled(false);
mAltitudeChart.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
mAltitudeChart.setMinimumHeight(ALTITUDE_CHART_HEIGHT);
mAltitudeChartContainer.addView(mAltitudeChart);
mAltitudeChartContainer.setMinimumHeight(ALTITUDE_CHART_HEIGHT);
return;
}
}
//Else...
TextView noAltitude = new TextView(this);
noAltitude.setText("No Altitude Height to Show");
mAltitudeChartContainer.addView(noAltitude);
}
示例10: setupInstPaceChart
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
protected void setupInstPaceChart(){
TextView textInstPace = new TextView(this);
textInstPace.setText("Pace:");
textInstPace.setTextColor(getResources().getColor(R.color.hike_blue_grey));
mInstPaceChartContainer.addView(textInstPace);
if(mCoordinatesList!=null) {
int listSize = mCoordinatesList.size();
if (listSize > 0) {
mInstPaceChart = new LineChart(this);
List<Entry> entries = new ArrayList<>(listSize);
for (int i = 0; i < listSize; i++) {
//TODO change logic to get the instant pace instead of altidude
entries.add(new Entry((float) mCoordinatesList.get(i).getAltitude(), i));
}
LineDataSet altitudePoints = new LineDataSet(entries, "Pace during Hike");
mInstPaceChart.setData(new LineData(Collections.nCopies(listSize, ""), altitudePoints));
mInstPaceChart.setDescription("");
mInstPaceChart.animateX(3500);
mInstPaceChart.getAxisLeft().setEnabled(false);
mInstPaceChart.setTouchEnabled(false);
mInstPaceChart.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
mInstPaceChart.setMinimumHeight(INST_PACE_CHART_HEIGHT);
mInstPaceChartContainer.addView(mInstPaceChart);
mInstPaceChartContainer.setMinimumHeight(INST_PACE_CHART_HEIGHT);
return;
}
//Else...
TextView noInstaPace = new TextView(this);
noInstaPace.setText("No Pace to Show");
mAltitudeChartContainer.addView(noInstaPace);
}
}
示例11: setupGraph
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
public void setupGraph(String courseID,int index,View v) {
LineChart l = (LineChart) v.findViewById(R.id.linechart);
l.setStartAtZero(false);
l.setDescription("");
l.setDrawYValues(false);
ArrayList<DataPoint> grades = new DataManager(getActivity()).getCourseDatapoints(courseID);
if (grades != null && grades.size() > 0 ) {
LineData dataSet = constructDataSet(grades, Constants.COLORS[index % Constants.COLORS.length]);
l.setData(dataSet);
}
}
示例12: setupChart
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
private void setupChart(LineChart chart, LineData data, int color) {
((LineDataSet) data.getDataSetByIndex(0)).setCircleColorHole(color);
// no description text
chart.getDescription().setEnabled(false);
// 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.getAxisLeft().setSpaceTop(40);
chart.getAxisLeft().setSpaceBottom(40);
chart.getAxisRight().setEnabled(false);
chart.getXAxis().setEnabled(false);
// animate calls invalidate()...
chart.animateX(2500);
}
示例13: onCreate
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
@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);
// enable description text
mChart.getDescription().setEnabled(true);
// 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);
// get the legend (only possible after setting data)
Legend l = mChart.getLegend();
// modify the legend ...
l.setForm(LegendForm.LINE);
l.setTypeface(mTfLight);
l.setTextColor(Color.WHITE);
XAxis xl = mChart.getXAxis();
xl.setTypeface(mTfLight);
xl.setTextColor(Color.WHITE);
xl.setDrawGridLines(false);
xl.setAvoidFirstLastClipping(true);
xl.setEnabled(true);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(mTfLight);
leftAxis.setTextColor(Color.WHITE);
leftAxis.setAxisMaximum(100f);
leftAxis.setAxisMinimum(0f);
leftAxis.setDrawGridLines(true);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setEnabled(false);
}
示例14: setupChart
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
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();
}
示例15: setChart1Value
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
/**
* Used to display the value from the measure list into the chart
* @param measures The list of the measure we want to display
* @param labelName The label we want to display for each value under the graph
*/
private void setChart1Value(List<Measure> measures, String labelName,String dateFormat, CustomRules rule) {
chart=(LineChart) view.findViewById(R.id.chart_measure);
if (measures.size()==0)
return;
//data for the entry
List<Entry> dataEntries=new ArrayList<>();
//get the data based on measure
for (int k=0;k<measures.size();k++)
{ //add the entry
dataEntries.add(new Entry(k,measures.get(k).getValue1().floatValue()));
//enter the fix value related to the rule
}
//add label instead of number in the axis
chart.notifyDataSetChanged();
//sort otherwise we will trigger an error
Collections.sort(dataEntries, new EntryXComparator());
//add the entry to a data set (data that belong together), it's a line
LineDataSet dataSet=new LineDataSet(dataEntries,labelName);
dataSet.setColor(Color.BLUE);
dataSet.setValueTextColor(Color.BLACK);
//create a data set for each line
LineData lineData=new LineData(dataSet);
chart.setData(lineData);
//refresh view
IAxisValueFormatter formatter =new XaxValueFormater(measures,dateFormat);
//set the gape between value in x axis
XAxis xAxis = chart.getXAxis();
xAxis.setGranularity(1f); // minimum axis-step (interval) is 1
//set the label instead of numner
xAxis.setValueFormatter(formatter);
dataSet.setMode(LineDataSet.Mode.CUBIC_BEZIER);
dataSet.setDrawFilled(true);
dataSet.setFillColor(Color.BLUE);
//draw the limite of the allowed value
setLimites(rule);
chart.getDescription().setEnabled(false);
chart.invalidate();
}