本文整理汇总了Java中com.github.mikephil.charting.charts.LineChart.setBackgroundColor方法的典型用法代码示例。如果您正苦于以下问题:Java LineChart.setBackgroundColor方法的具体用法?Java LineChart.setBackgroundColor怎么用?Java LineChart.setBackgroundColor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.mikephil.charting.charts.LineChart
的用法示例。
在下文中一共展示了LineChart.setBackgroundColor方法的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.setBackgroundColor(Color.WHITE);
mChart.setGridBackgroundColor(mFillColor);
mChart.setDrawGridBackground(true);
mChart.setDrawBorders(true);
// no description text
mChart.getDescription().setEnabled(false);
// if disabled, scaling can be done on x- and y-axis separately
mChart.setPinchZoom(false);
Legend l = mChart.getLegend();
l.setEnabled(false);
XAxis xAxis = mChart.getXAxis();
xAxis.setEnabled(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setAxisMaximum(900f);
leftAxis.setAxisMinimum(-250f);
leftAxis.setDrawAxisLine(false);
leftAxis.setDrawZeroLine(false);
leftAxis.setDrawGridLines(false);
mChart.getAxisRight().setEnabled(false);
// add data
setData(100, 60);
mChart.invalidate();
}
示例2: initInValidGoNoGoGameLineChart
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
private void initInValidGoNoGoGameLineChart(Activity activity, View view) {
inValidGoNoGoGamesLineChart = (LineChart) view.findViewById(R.id.line_chart_invalid_gonogogames);
inValidGoNoGoGamesLineChart.setDescription("");
String noData = activity.getResources().getString(R.string.no_failures_to_display);
inValidGoNoGoGamesLineChart.setNoDataText(noData);
inValidGoNoGoGamesLineChart.setTouchEnabled(false);
inValidGoNoGoGamesLineChart.setDragEnabled(true);
inValidGoNoGoGamesLineChart.setScaleEnabled(true);
inValidGoNoGoGamesLineChart.setPinchZoom(true);
inValidGoNoGoGamesLineChart.setBackgroundColor(Color.WHITE);
inValidGoNoGoGamesLineChart.setDrawGridBackground(false);
YAxis leftAxis = inValidGoNoGoGamesLineChart.getAxisLeft();
leftAxis.setAxisMinValue(0);
YAxis righAxis = inValidGoNoGoGamesLineChart.getAxisRight();
if (righAxis != null)
righAxis.setEnabled(false);
}
示例3: initHeartRateChart
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
private void initHeartRateChart(LineChart mChart) {
mChart.setViewPortOffsets(0, 0, 0, 0);
mChart.setBackgroundColor(getResources().getColor(R.color.gold_pressed));
mChart.setDescription("Heart Rate");
mChart.setTouchEnabled(true);
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setPinchZoom(false);
mChart.setDrawGridBackground(false);
mChart.setMaxHighlightDistance(300);
XAxis xAxis = mChart.getXAxis();
xAxis.setTypeface(BandApplication.INSTANCE.getTfLight());
xAxis.setTextSize(11f);
xAxis.setTextColor(Color.WHITE);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(false);
YAxis y = mChart.getAxisLeft();
y.setTypeface(BandApplication.INSTANCE.getTfLight());
y.setLabelCount(6, false);
y.setTextColor(Color.RED);
y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
y.setDrawGridLines(false);
y.setAxisLineColor(Color.WHITE);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setTypeface(BandApplication.INSTANCE.getTfLight());
y.setLabelCount(6, false);
y.setTextColor(Color.RED);
y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
y.setDrawGridLines(false);
y.setAxisLineColor(Color.WHITE);
mChart.getLegend().setEnabled(false);
mChart.animateXY(2000, 2000);
}
示例4: initTemperatureChart
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
private void initTemperatureChart(LineChart mChart) {
// mChart.setOnChartValueSelectedListener(this);
mChart.setDescription("Skin Temperature");
mChart.setNoDataTextDescription("You need to provide data for the chart.");
mChart.setTouchEnabled(true);
mChart.setDragDecelerationFrictionCoef(0.9f);
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setDrawGridBackground(false);
mChart.setHighlightPerDragEnabled(true);
mChart.setPinchZoom(true);
mChart.setBackgroundColor(getResources().getColor(R.color.blue_light_pressed));
mChart.animateX(2500);
Legend l = mChart.getLegend();
l.setForm(Legend.LegendForm.LINE);
l.setTypeface(BandApplication.INSTANCE.getTfLight());
l.setTextSize(11f);
l.setTextColor(Color.WHITE);
l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);
mChart.getXAxis().setEnabled(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(BandApplication.INSTANCE.getTfLight());
leftAxis.setTextColor(Color.RED);
leftAxis.setDrawGridLines(true);
leftAxis.setGranularityEnabled(true);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setTypeface(BandApplication.INSTANCE.getTfLight());
rightAxis.setTextColor(Color.RED);
rightAxis.setDrawGridLines(false);
rightAxis.setDrawZeroLine(false);
rightAxis.setGranularityEnabled(false);
}
示例5: initResistanceChart
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
private void initResistanceChart(LineChart mChart) {
// mChart.setOnChartValueSelectedListener(this);
mChart.setDescription("Skin Resistance");
mChart.setNoDataTextDescription("You need to provide data for the chart.");
mChart.setTouchEnabled(true);
mChart.setDragDecelerationFrictionCoef(0.9f);
mChart.setDragEnabled(true);
mChart.setScaleEnabled(true);
mChart.setDrawGridBackground(false);
mChart.setHighlightPerDragEnabled(true);
mChart.setPinchZoom(true);
mChart.setBackgroundColor(getResources().getColor(R.color.green_pressed));
mChart.animateX(2500);
Legend l = mChart.getLegend();
l.setForm(Legend.LegendForm.LINE);
l.setTypeface(BandApplication.INSTANCE.getTfLight());
l.setTextSize(11f);
l.setTextColor(Color.WHITE);
l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);
mChart.getXAxis().setEnabled(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(BandApplication.INSTANCE.getTfLight());
leftAxis.setTextColor(Color.RED);
leftAxis.setDrawGridLines(true);
leftAxis.setGranularityEnabled(true);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setTypeface(BandApplication.INSTANCE.getTfLight());
rightAxis.setTextColor(Color.RED);
rightAxis.setDrawGridLines(false);
rightAxis.setDrawZeroLine(false);
rightAxis.setGranularityEnabled(false);
}
示例6: 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);
}
示例7: 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);
}
示例8: 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_time);
tvX = (TextView) findViewById(R.id.tvXMax);
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
mSeekBarX.setProgress(100);
tvX.setText("100");
mSeekBarX.setOnSeekBarChangeListener(this);
mChart = (LineChart) findViewById(R.id.chart1);
// no description text
mChart.getDescription().setEnabled(false);
// 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);
// set an alternative background color
mChart.setBackgroundColor(Color.WHITE);
mChart.setViewPortOffsets(0f, 0f, 0f, 0f);
// add data
setData(100, 30);
mChart.invalidate();
// get the legend (only possible after setting data)
Legend l = mChart.getLegend();
l.setEnabled(false);
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.TOP_INSIDE);
xAxis.setTypeface(mTfLight);
xAxis.setTextSize(10f);
xAxis.setTextColor(Color.WHITE);
xAxis.setDrawAxisLine(false);
xAxis.setDrawGridLines(true);
xAxis.setTextColor(Color.rgb(255, 192, 56));
xAxis.setCenterAxisLabels(true);
xAxis.setGranularity(1f); // one hour
xAxis.setValueFormatter(new IAxisValueFormatter() {
private SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm");
@Override
public String getFormattedValue(float value, AxisBase axis) {
long millis = TimeUnit.HOURS.toMillis((long) value);
return mFormat.format(new Date(millis));
}
});
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
leftAxis.setTypeface(mTfLight);
leftAxis.setTextColor(ColorTemplate.getHoloBlue());
leftAxis.setDrawGridLines(true);
leftAxis.setGranularityEnabled(true);
leftAxis.setAxisMinimum(0f);
leftAxis.setAxisMaximum(170f);
leftAxis.setYOffset(-9f);
leftAxis.setTextColor(Color.rgb(255, 192, 56));
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setEnabled(false);
}
示例9: 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);
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.setViewPortOffsets(0, 0, 0, 0);
mChart.setBackgroundColor(Color.rgb(104, 241, 175));
// no description text
mChart.getDescription().setEnabled(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);
mChart.setDrawGridBackground(false);
mChart.setMaxHighlightDistance(300);
XAxis x = mChart.getXAxis();
x.setEnabled(false);
YAxis y = mChart.getAxisLeft();
y.setTypeface(mTfLight);
y.setLabelCount(6, false);
y.setTextColor(Color.WHITE);
y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
y.setDrawGridLines(false);
y.setAxisLineColor(Color.WHITE);
mChart.getAxisRight().setEnabled(false);
// add data
setData(45, 100);
mChart.getLegend().setEnabled(false);
mChart.animateXY(2000, 2000);
// dont forget to refresh the drawing
mChart.invalidate();
}
示例10: 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();
}
示例11: 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_coin_details);
initToolbar("Coin Graph", 0);
mChart = (LineChart) findViewById(R.id.chart);
mChart.setBackgroundColor(Color.TRANSPARENT);
// no description text
mChart.getDescription().setEnabled(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);
mChart.setDrawGridBackground(false);
mChart.setMaxHighlightDistance(300);
XAxis x = mChart.getXAxis();
x.setTextColor(Color.RED);
x.setPosition(XAxis.XAxisPosition.BOTTOM);
x.setAxisLineColor(Color.BLUE);
x.setDrawGridLines(false);
x.setAxisLineWidth(2f);
YAxis y = mChart.getAxisRight();
// y.setTypeface();
y.setLabelCount(6, false);
y.setTextColor(Color.RED);
y.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
y.setDrawGridLines(false);
y.setAxisLineColor(Color.BLUE);
y.setAxisLineWidth(2f);
mChart.getAxisLeft().setEnabled(false);
// add data
setData(45, 100);
mChart.getLegend().setEnabled(false);
mChart.animateX(1000);
// dont forget to refresh the drawing
mChart.invalidate();
// TODO Testing
if (mChart.getData() != null) {
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
mChart.invalidate();
}
}
示例12: onCreateView
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_voice_db_record_db, container, false);
mDBTextView = (TextView) view.findViewById(R.id.record_db_fragment_db_tv);
mDurationTimeView = (TextView) view.findViewById(R.id.record_db_fragment_duration_tv);
mAverageTextView = (TextView) view.findViewById(R.id.record_db_fragment_average_tv);
mMaxTextView = (TextView) view.findViewById(R.id.record_db_fragment_max_tv);
mBtn = (Button) view.findViewById(R.id.record_db_fragment_switch_btn);
mBtn.setOnClickListener(this);
mLineChart = (LineChart) view.findViewById(R.id.record_db_fragment_info_lc);
mLineChart.setOnChartValueSelectedListener(this);
// 设置表描述为不可见
mLineChart.getDescription().setEnabled(false);
// 设置表描述可见,颜色值以及显示的文本
// mLineChart.getDescription().setEnabled(true);
// mLineChart.getDescription().setText(getString(R.string.db));
// mLineChart.getDescription().setTextColor(Color.WHITE);
// enable touch gestures
mLineChart.setTouchEnabled(true);
// enable scaling and dragging
mLineChart.setDragEnabled(true);
mLineChart.setScaleEnabled(true);
mLineChart.setDrawGridBackground(false);
// if disabled, scaling can be done on x- and y-axis separately
mLineChart.setPinchZoom(true);
// set an alternative background color
mLineChart.setBackgroundColor(Color.parseColor("#6A1B9A") );
LineData data = new LineData();
data.setValueTextColor(Color.WHITE);
// add empty data
mLineChart.setData(data);
// get the legend (only possible after setting data)
Legend l = mLineChart.getLegend();
// modify the legend ...
l.setForm(Legend.LegendForm.LINE);
//l.setTypeface(mTfLight);
l.setTextColor(Color.WHITE);
// 获得图表的x轴
XAxis xAxis = mLineChart.getXAxis();
// 设置x轴的文本颜色为白色
xAxis.setTextColor(Color.WHITE);
// 不设置纵向的网格线,即与x轴垂直的线
xAxis.setDrawGridLines(false);
// 避免图表剪辑的边缘是屏幕
xAxis.setAvoidFirstLastClipping(true);
// 设置x轴可见
xAxis.setEnabled(true);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
YAxis leftYAxis = mLineChart.getAxisLeft();
leftYAxis.setTextColor(Color.WHITE);
leftYAxis.setAxisMaximum(100f);
leftYAxis.setAxisMinimum(0f);
leftYAxis.setDrawGridLines(true);
// 获取右y轴并将其设置为可见
YAxis rightYAxis = mLineChart.getAxisRight();
rightYAxis.setEnabled(true);
rightYAxis.setDrawGridLines(false);
// 设置与背景颜色相同使文本不可见
rightYAxis.setTextColor(Color.parseColor("#6A1B9A"));
addEntry(UserInfo.getInt(getContext(),"AverageDb"));
return view;
}
示例13: onCreateView
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_store_db_record, container, false);
mDBTextView = (TextView) view.findViewById(R.id.store_record_db_fragment_db_tv);
mDurationTimeView = (TextView) view.findViewById(R.id.store_record_db_fragment_duration_tv);
mAverageTextView = (TextView) view.findViewById(R.id.store_record_db_fragment_average_tv);
mMaxTextView = (TextView) view.findViewById(R.id.store_record_db_fragment_max_tv);
mBtn = (Button) view.findViewById(R.id.store_record_db_fragment_switch_btn);
mBtn.setOnClickListener(this);
mLineChart = (LineChart) view.findViewById(R.id.store_record_db_fragment_info_lc);
mLineChart.setOnChartValueSelectedListener(this);
// 设置表描述为不可见
mLineChart.getDescription().setEnabled(false);
// 设置表描述可见,颜色值以及显示的文本
// mLineChart.getDescription().setEnabled(true);
// mLineChart.getDescription().setText(getString(R.string.db));
// mLineChart.getDescription().setTextColor(Color.WHITE);
// enable touch gestures
mLineChart.setTouchEnabled(true);
// enable scaling and dragging
mLineChart.setDragEnabled(true);
mLineChart.setScaleEnabled(true);
mLineChart.setDrawGridBackground(false);
// if disabled, scaling can be done on x- and y-axis separately
mLineChart.setPinchZoom(true);
// set an alternative background color
mLineChart.setBackgroundColor(Color.parseColor("#6A1B9A"));
LineData data = new LineData();
data.setValueTextColor(Color.WHITE);
// add empty data
mLineChart.setData(data);
// get the legend (only possible after setting data)
Legend l = mLineChart.getLegend();
// modify the legend ...
l.setForm(Legend.LegendForm.LINE);
//l.setTypeface(mTfLight);
l.setTextColor(Color.WHITE);
// 获得图表的x轴
XAxis xAxis = mLineChart.getXAxis();
// 设置x轴的文本颜色为白色
xAxis.setTextColor(Color.WHITE);
// 不设置纵向的网格线,即与x轴垂直的线
xAxis.setDrawGridLines(false);
// 避免图表剪辑的边缘是屏幕
xAxis.setAvoidFirstLastClipping(true);
// 设置x轴可见
xAxis.setEnabled(true);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
YAxis leftYAxis = mLineChart.getAxisLeft();
leftYAxis.setTextColor(Color.WHITE);
leftYAxis.setAxisMaximum(100f);
leftYAxis.setAxisMinimum(0f);
leftYAxis.setDrawGridLines(true);
// 获取右y轴并将其设置为可见
YAxis rightYAxis = mLineChart.getAxisRight();
rightYAxis.setEnabled(true);
rightYAxis.setDrawGridLines(false);
// 设置与背景颜色相同使文本不可见
rightYAxis.setTextColor(Color.parseColor("#6A1B9A"));
addEntry(UserInfo.getInt(getContext(), "AverageDb"));
return view;
}
示例14: updateLastScanChart
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
public void updateLastScanChart() {
SharedPreferences sharedPrefs = PreferenceManager
.getDefaultSharedPreferences(this.getApplicationContext());
ImageView iv_unit;
iv_unit = (ImageView)findViewById(R.id.iv_unit);
if(sharedPrefs.getString("pref_unit", "mg/dl").equals("mg/dl")) {
iv_unit.setImageResource(R.drawable.unit_mgdl);
}else{
iv_unit.setImageResource(R.drawable.unit_mmoll);
}
LineChart cv_LastScan = (LineChart) findViewById(R.id.cv_LastScan);
if(sharedPrefs.getBoolean("pref_nightmode", false)) {
cv_LastScan.setBackgroundColor(getResources().getColor(R.color.colorBackgroundDark));
}else{
cv_LastScan.setBackgroundColor(getResources().getColor(R.color.colorBackgroundLight));
}
LineData getData = cv_LastScan.getData();
if(getData != null) {
YAxis yAxisLeft = cv_LastScan.getAxisLeft();
yAxisLeft.removeAllLimitLines();
yAxisLeft.setDrawLimitLinesBehindData(true);
yAxisLeft.resetAxisMaxValue();
if (cv_LastScan.getData() != null && !sharedPrefs.getString("pref_default_range", "0.0").equals("")) {
if (cv_LastScan.getData().getDataSets().get(0).getYMax() < Float.valueOf(sharedPrefs.getString("pref_default_range", "0.0"))) { //Todo: platz für highlight
yAxisLeft.setAxisMaxValue(Float.valueOf(sharedPrefs.getString("pref_default_range", "0.0")));
}
}
LimitLine ll_max = new LimitLine(Float.valueOf(sharedPrefs.getString("pref_zb_max", "-100.0")), getResources().getString(R.string.pref_zb_max));
ll_max.setLineWidth(4f);
ll_max.setTextSize(12f);
LimitLine ll_min = new LimitLine(Float.valueOf(sharedPrefs.getString("pref_zb_min", "-100.0")), getResources().getString(R.string.pref_zb_min));
ll_min.setLineWidth(4f);
ll_min.setTextSize(12f);
ll_min.setLabelPosition(LimitLine.LimitLabelPosition.RIGHT_BOTTOM);
Legend legend = cv_LastScan.getLegend();
legend.setEnabled(false);
// set an alternative background color
if (sharedPrefs.getBoolean("pref_nightmode", false)) {
ll_max.setLineColor(getResources().getColor(R.color.colorZielbereichDark));
ll_max.setTextColor(getResources().getColor(R.color.colorZielbereichDark));
ll_min.setLineColor(getResources().getColor(R.color.colorZielbereichDark));
ll_min.setTextColor(getResources().getColor(R.color.colorZielbereichDark));
} else {
ll_max.setLineColor(getResources().getColor(R.color.colorZielbereichLight));
ll_max.setTextColor(getResources().getColor(R.color.colorZielbereichLight));
ll_min.setLineColor(getResources().getColor(R.color.colorZielbereichLight));
ll_min.setTextColor(getResources().getColor(R.color.colorZielbereichLight));
}
yAxisLeft.addLimitLine(ll_max);
yAxisLeft.addLimitLine(ll_min);
cv_LastScan.notifyDataSetChanged();
cv_LastScan.invalidate();
}
}
示例15: refresh
import com.github.mikephil.charting.charts.LineChart; //导入方法依赖的package包/类
public void refresh() {
SharedPreferences sharedPrefs = PreferenceManager
.getDefaultSharedPreferences(view.getContext().getApplicationContext());
ImageView iv_unit;
iv_unit = (ImageView)view.findViewById(R.id.iv_unit);
if(sharedPrefs.getString("pref_unit", "mg/dl").equals("mg/dl")) {
iv_unit.setImageResource(R.drawable.unit_mgdl);
}else{
iv_unit.setImageResource(R.drawable.unit_mmoll);
}
LineChart cv_LastScan = (LineChart) view.findViewById(R.id.cv_LastScan);
YAxis yAxisLeft = cv_LastScan.getAxisLeft();
yAxisLeft.removeAllLimitLines();
LimitLine ll_max = new LimitLine(Float.valueOf(sharedPrefs.getString("pref_zb_max", "-100.0")), getResources().getString(R.string.pref_zb_max));
ll_max.setLineWidth(4f);
ll_max.setTextSize(12f);
LimitLine ll_min = new LimitLine(Float.valueOf(sharedPrefs.getString("pref_zb_min", "-100.0")), getResources().getString(R.string.pref_zb_min));
ll_min.setLineWidth(4f);
ll_min.setTextSize(12f);
ll_min.setLabelPosition(LimitLine.LimitLabelPosition.RIGHT_BOTTOM);
Legend legend = cv_LastScan.getLegend();
legend.setEnabled(false);
// set an alternative background color
if(sharedPrefs.getBoolean("pref_nightmode", false)) {
cv_LastScan.setBackgroundColor(getResources().getColor(R.color.colorBackgroundDark));
ll_max.setLineColor(getResources().getColor(R.color.colorZielbereichDark));
ll_max.setTextColor(getResources().getColor(R.color.colorZielbereichDark));
ll_min.setLineColor(getResources().getColor(R.color.colorZielbereichDark));
ll_min.setTextColor(getResources().getColor(R.color.colorZielbereichDark));
}else{
cv_LastScan.setBackgroundColor(getResources().getColor(R.color.colorBackgroundLight));
ll_max.setLineColor(getResources().getColor(R.color.colorZielbereichLight));
ll_max.setTextColor(getResources().getColor(R.color.colorZielbereichLight));
ll_min.setLineColor(getResources().getColor(R.color.colorZielbereichLight));
ll_min.setTextColor(getResources().getColor(R.color.colorZielbereichLight));
}
yAxisLeft.addLimitLine(ll_max);
yAxisLeft.addLimitLine(ll_min);
/* if(cv_LastScan.getData() != null) {
if( cv_LastScan.getData().getDataSets().get(0).getYMax() < Float.valueOf(sharedPrefs.getString("pref_default_range", "0.0"))) {
yAxisLeft.setAxisMaxValue(Float.valueOf(sharedPrefs.getString("pref_default_range", "0.0")));
}
}*/
ArrayList<Entry> yVals = new ArrayList<Entry>();
yVals.add(new Entry(Float.valueOf(sharedPrefs.getString("pref_zb_max", "-100.0")), 0));
yVals.add(new Entry(Float.valueOf(sharedPrefs.getString("pref_zb_max", "-100.0")), cv_LastScan.getXAxis().getValues().size() - 1));
LineDataSet setarea = new LineDataSet(yVals, "area");
setarea.setLineWidth(4f);
setarea.setDrawCircleHole(false);
setarea.setDrawCircles(false);
setarea.setDrawValues(false);
setarea.setDrawCubic(false);
setarea.setDrawHighlightIndicators(false);
ArrayList<LineDataSet> areaSets = new ArrayList<LineDataSet>();
areaSets.add(setarea); // add the datasets
// create a data object with the datasets
if(cv_LastScan.getXAxis().getValues().size() > 2) {
LineData ld_area = new LineData(cv_LastScan.getXAxis().getValues(), areaSets);
cv_LastScan.setData(ld_area);
}
}