本文整理汇总了Java中com.github.mikephil.charting.components.XAxis.setValueFormatter方法的典型用法代码示例。如果您正苦于以下问题:Java XAxis.setValueFormatter方法的具体用法?Java XAxis.setValueFormatter怎么用?Java XAxis.setValueFormatter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.mikephil.charting.components.XAxis
的用法示例。
在下文中一共展示了XAxis.setValueFormatter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setAxis
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
@Override
public void setAxis(AnalysisXAxisValueFormatter formatter, float yAxisMaxValue) {
XAxis xAxis = mRadarChart.getXAxis();
xAxis.setTextSize(9f);
xAxis.setYOffset(0f);
xAxis.setXOffset(0f);
xAxis.setValueFormatter(formatter);
xAxis.setTextColor(Color.WHITE);
YAxis yAxis = mRadarChart.getYAxis();
yAxis.setLabelCount(5, false);
yAxis.setTextSize(9f);
yAxis.setAxisMinimum(0f);
yAxis.setAxisMaximum(yAxisMaxValue);
yAxis.setDrawLabels(false);
Legend l = mRadarChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setXEntrySpace(7f);
l.setYEntrySpace(5f);
l.setTextColor(Color.WHITE);
}
示例2: setChartOptions
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
private void setChartOptions() {
mChart.getLegend().setEnabled(false);
mChart.setAutoScaleMinMaxEnabled(true);
mChart.setScaleYEnabled(false);
mChart.setDescription(null);
mChart.setDrawGridBackground(false);
mChart.setDrawBorders(false);
mChart.setHighlightPerTapEnabled(false);
mChart.setHighlightPerDragEnabled(false);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setEnabled(false);
IAxisValueFormatter xAxisFormatter = new HourAxisValueFormatter();
XAxis xAxis = mChart.getXAxis();
xAxis.setValueFormatter(xAxisFormatter);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);
}
示例3: chartXAxisStyling
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
private void chartXAxisStyling(XAxis xAxis) {
xAxis.setPosition(XAxis.XAxisPosition.TOP);
xAxis.setTextColor(getResources().getColor(R.color.traffic_chart_text_color_light));
xAxis.setDrawAxisLine(true);
xAxis.setDrawGridLines(false);
xAxis.setCenterAxisLabels(true);
xAxis.setValueFormatter(new AxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return Utils.humanReadable((long) value);
}
@Override
public int getDecimalDigits() {
return 0;
}
});
}
示例4: setXlabels
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
private void setXlabels(List<String> labelList)
{
int valuesSelectedItemPos = cache.getValuesSpinner().getSelectedItemPosition();
String[] labels = new String[ labelList.size() ];
labelList.toArray(labels);
PFAXAxisLabels xFormatter = new PFAXAxisLabels(labels);
chart.setMarkerView(new PFAMarkerView(context, xFormatter, valuesSelectedItemPos, cache.getNumberScale()));
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f);
xAxis.setLabelCount(5);
xAxis.setValueFormatter(xFormatter);
}
示例5: formatXAxisLabels
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
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());
});
}
示例6: setHorizontalBarChart
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
/**
* Set the horizontal bar pattern
* @param barChart chart
* @param chartData horizontal bar chart data
* @param jobs string array of job titles
* @param typeface Typeface font
*/
public static void setHorizontalBarChart(BarChart barChart, final ChartData<?> chartData,
final String[] jobs, Typeface typeface) {
barChart.setDrawGridBackground(false);
XAxis xAxis = barChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
//xAxis.setLabelCount(chartData.getEntryCount());
xAxis.setLabelCount(jobs.length);
xAxis.setTypeface(typeface);
xAxis.setDrawAxisLine(true);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f);
YAxis leftAxis = barChart.getAxisLeft();
leftAxis.setTypeface(typeface);
leftAxis.setSpaceTop(15f);
leftAxis.setAxisMinimum(0f);
leftAxis.setGranularity(1f);
leftAxis.setDrawAxisLine(true);
leftAxis.setDrawGridLines(true);
YAxis axisRight = barChart.getAxisRight();
axisRight.setTypeface(typeface);
axisRight.setDrawAxisLine(true);
axisRight.setDrawGridLines(false);
axisRight.setGranularity(1f);
axisRight.setAxisMinimum(0f);
final Legend legend = barChart.getLegend();
legend.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
legend.setOrientation(Legend.LegendOrientation.HORIZONTAL);
legend.setDrawInside(false);
legend.setFormSize(8f);
legend.setXEntrySpace(4f);
barChart.setData((BarData) chartData);
barChart.setFitBars(true);
barChart.animateY(DURATION_LONG);
xAxis.setValueFormatter(new HorizontalBarValueFormatter(jobs));
}
示例7: setupXAxis
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
private void setupXAxis(BarLineChartBase chart, IAxisValueFormatter formatter) {
XAxis x = chart.getXAxis();
x.setGranularity(1.0f);
x.setDrawGridLines(false);
x.setPosition(XAxis.XAxisPosition.BOTTOM);
x.setDrawAxisLine(false);
x.setCenterAxisLabels(true);
x.setAxisMinimum(2.0f);
x.setAxisMaximum(5.0f);
x.setValueFormatter(formatter);
}
示例8: setupChart
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的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);
}
示例9: getFormattedLineChart
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
/**
* Formats a line chart in a standardized manner
* @param c App context
* @param chart LineChart to format
* @param listener Listener to attach to chart
* @param xLabels Labels to use for the x-axis
* @param valueFormatter True if large value formatter should be used
* @param skip Number of values to skip
* @param legend True if show legend, false if hide legend
* @return Formatted linechart
*/
public static LineChart getFormattedLineChart(Context c, LineChart chart, OnChartValueSelectedListener listener, List<String> xLabels, boolean valueFormatter, int skip, boolean legend) {
Legend cLegend = chart.getLegend();
cLegend.setEnabled(legend);
XAxis xAxis = chart.getXAxis();
xAxis.setGranularity(skip);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setValueFormatter(new XAxisLabelFormatter(xLabels));
YAxis yAxisRight = chart.getAxisRight();
yAxisRight.setEnabled(false);
YAxis yAxisLeft = chart.getAxisLeft();
if (valueFormatter) {
yAxisLeft.setValueFormatter(new LargeNumberAxisFormatter(c));
}
if (SettingsActivity.getTheme(c) == SettingsActivity.THEME_NOIR) {
int textColorNoir = ContextCompat.getColor(c, R.color.colorPrimaryTextNoir);
cLegend.setTextColor(textColorNoir);
xAxis.setTextColor(textColorNoir);
yAxisLeft.setTextColor(textColorNoir);
}
chart.setDoubleTapToZoomEnabled(false);
chart.setDescription(EMPTY_CHART_DESCRIPTION);
chart.setDragEnabled(true);
chart.setScaleYEnabled(false);
chart.setDrawGridBackground(false);
chart.setOnChartValueSelectedListener(listener);
return chart;
}
示例10: createChart
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
private static void createChart(Chart barChart, List<Pair<String, Integer>> chartData, String title, Context context){
int count = chartData.size() > 10 ? 10 : chartData.size();
String[] stateNames = new String[count];
for (int i=0; i<count; ++i) {
Pair<String, Integer> record = chartData.get(i);
stateNames[i] = record.first;
}
StateAxisValueFormatter stateAxisValueFormatter = new StateAxisValueFormatter(stateNames);
barChart.getDescription().setEnabled(false);
barChart.setTouchEnabled(false);
XAxis xl = barChart.getXAxis();
xl.setPosition(XAxis.XAxisPosition.BOTTOM);
xl.setDrawAxisLine(true);
xl.setDrawGridLines(true);
xl.setGridLineWidth(0.3f);
xl.setTextSize(11f);
xl.setTextColor(Color.BLACK);
xl.setLabelCount(count);
xl.setValueFormatter(stateAxisValueFormatter);
// setting data
Legend l = barChart.getLegend();
l.setDirection(Legend.LegendDirection.LEFT_TO_RIGHT);
l.setFormSize(11f);
l.setTextSize(11f);
l.setXEntrySpace(4f);
setData(barChart, chartData, title,context);
}
示例11: initChart
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
private void initChart() {
barChart.setDrawBarShadow(false);
barChart.setDrawValueAboveBar(true);
barChart.getDescription().setEnabled(false);
barChart.setPinchZoom(false);
barChart.setMaxVisibleValueCount(60);
barChart.getLegend().setEnabled(false);
barChart.setDrawGridBackground(false);
barChart.getAxisRight().setEnabled(false);
barChart.setScaleYEnabled(false);
dayAxisValueFormatter = new DayAxisValueFormatter();
XAxis xAxis = barChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setLabelRotationAngle(270);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f);
xAxis.setTextColor(getOutlayTheme().secondaryTextColor);
xAxis.setValueFormatter(dayAxisValueFormatter);
YAxis leftAxis = barChart.getAxisLeft();
leftAxis.setValueFormatter(new AmountValueFormatter());
leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
leftAxis.setTextColor(getOutlayTheme().secondaryTextColor);
leftAxis.setSpaceTop(15f);
leftAxis.setAxisMinimum(0f);
}
示例12: updateGraph
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
public void updateGraph(){
List<Entry> entries = new ArrayList<>();
Last7Days newDays = AxisFormatter.reverseLast7Days(last7Days);
int i = 0;
for(long dataEntry : get7Days(newDays)){
entries.add(new Entry((float)i,(float)dataEntry));
i++;
}
LineDataSet dataSet = new LineDataSet(entries,context.getString(R.string.main_scores));
dataSet.setColor(ContextCompat.getColor(context,R.color.greenDark));
dataSet.setValueTextSize(14f);
dataSet.setValueFormatter(new IValueFormatter() {
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return String.valueOf((int) value);
}
});
dataSet.setCircleColor(ContextCompat.getColor(context,R.color.greenPrimary));
dataSet.setLineWidth(3f);
dataSet.setCircleRadius(10f);
dataSet.setDrawValues(false);
dataSet.setHighlightEnabled(true);
LineData lineData = new LineData(dataSet);
graph.setData(lineData);
Description description = new Description();
description.setEnabled(false);
description.setText("");
graph.setDescription(description);
graph.setNoDataText(context.getString(R.string.main_connecting));
graph.setNoDataTextColor(ContextCompat.getColor(context,R.color.greenDark));
graph.setDrawGridBackground(false);
graph.setDrawBorders(false);
YAxis leftAxis = graph.getAxisLeft();
leftAxis.setEnabled(false);
leftAxis.setAxisMinimum(0);
YAxis rightAxis = graph.getAxisRight();
rightAxis.setEnabled(false);
XAxis xAxis = graph.getXAxis();
Calendar c = Calendar.getInstance();
c.setTimeInMillis(System.currentTimeMillis());
ArrayList<Date> dateArrayList = new ArrayList<>();
for(int count = 0;count<7;count++){
Date date = c.getTime();
dateArrayList.add(date);
c.setTimeInMillis(c.getTimeInMillis() - ((long) 1000 * 60 * 60 * 24 ));
}
Collections.reverse(dateArrayList);
xAxis.setValueFormatter(new AxisFormatter(context,dateArrayList,dateFormatPattern));
xAxis.setTextSize(10f);
graph.setTouchEnabled(false);
graph.setDragEnabled(false);
graph.setScaleEnabled(false);
graph.setScaleXEnabled(false);
graph.setScaleYEnabled(false);
graph.setPinchZoom(false);
graph.setDoubleTapToZoomEnabled(false);
Legend legend = graph.getLegend();
legend.setEnabled(false);
graph.invalidate();
}
示例13: onCreate
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart);
tvX = (TextView) findViewById(R.id.tvXMax);
tvX.setTextSize(10);
tvY = (TextView) findViewById(R.id.tvYMax);
mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
mSeekBarX.setOnSeekBarChangeListener(this);
mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
mSeekBarY.setOnSeekBarChangeListener(this);
mChart = (BarChart) findViewById(R.id.chart1);
mChart.setOnChartValueSelectedListener(this);
mChart.getDescription().setEnabled(false);
// mChart.setDrawBorders(true);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
mChart.setDrawBarShadow(false);
mChart.setDrawGridBackground(false);
// create a custom MarkerView (extend MarkerView) and specify the layout
// to use for it
MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
mv.setChartView(mChart); // For bounds control
mChart.setMarker(mv); // Set the marker to the chart
mSeekBarX.setProgress(10);
mSeekBarY.setProgress(100);
Legend l = mChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(true);
l.setTypeface(mTfLight);
l.setYOffset(0f);
l.setXOffset(10f);
l.setYEntrySpace(0f);
l.setTextSize(8f);
XAxis xAxis = mChart.getXAxis();
xAxis.setTypeface(mTfLight);
xAxis.setGranularity(1f);
xAxis.setCenterAxisLabels(true);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return String.valueOf((int) value);
}
});
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(mTfLight);
leftAxis.setValueFormatter(new LargeValueFormatter());
leftAxis.setDrawGridLines(false);
leftAxis.setSpaceTop(35f);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
mChart.getAxisRight().setEnabled(false);
}
示例14: onCreate
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的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);
}
示例15: onCreate
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_barchart_noseekbar);
mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
mChart = (BarChart) findViewById(R.id.chart1);
mChart.setBackgroundColor(Color.WHITE);
mChart.setExtraTopOffset(-30f);
mChart.setExtraBottomOffset(10f);
mChart.setExtraLeftOffset(70f);
mChart.setExtraRightOffset(70f);
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(true);
mChart.getDescription().setEnabled(false);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
mChart.setDrawGridBackground(false);
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTTOM);
xAxis.setTypeface(mTf);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(false);
xAxis.setTextColor(Color.LTGRAY);
xAxis.setTextSize(13f);
xAxis.setLabelCount(5);
xAxis.setCenterAxisLabels(true);
xAxis.setGranularity(1f);
YAxis left = mChart.getAxisLeft();
left.setDrawLabels(false);
left.setSpaceTop(25f);
left.setSpaceBottom(25f);
left.setDrawAxisLine(false);
left.setDrawGridLines(false);
left.setDrawZeroLine(true); // draw a zero line
left.setZeroLineColor(Color.GRAY);
left.setZeroLineWidth(0.7f);
mChart.getAxisRight().setEnabled(false);
mChart.getLegend().setEnabled(false);
// THIS IS THE ORIGINAL DATA YOU WANT TO PLOT
final List<Data> data = new ArrayList<>();
data.add(new Data(0f, -224.1f, "12-29"));
data.add(new Data(1f, 238.5f, "12-30"));
data.add(new Data(2f, 1280.1f, "12-31"));
data.add(new Data(3f, -442.3f, "01-01"));
data.add(new Data(4f, -2280.1f, "01-02"));
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return data.get(Math.min(Math.max((int) value, 0), data.size()-1)).xAxisValue;
}
});
setData(data);
}