本文整理汇总了Java中com.github.mikephil.charting.components.XAxis.setLabelCount方法的典型用法代码示例。如果您正苦于以下问题:Java XAxis.setLabelCount方法的具体用法?Java XAxis.setLabelCount怎么用?Java XAxis.setLabelCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.mikephil.charting.components.XAxis
的用法示例。
在下文中一共展示了XAxis.setLabelCount方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: setLineChart
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的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);
}
示例3: 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));
}
示例4: 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);
}
示例5: 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);
}
示例6: onCreateView
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.chart_frag, container, false);
// Set up timeline chart
chart = view.findViewById(R.id.timeline);
entries = new ArrayList<>();
// Set up the x-axis
XAxis xAxis = chart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
formatter = DateTimeFormatter.ofPattern("MMM d");
dates = new ArrayList<>();
int numDays = 14;
LocalDate today = LocalDate.now();
minimumDate = today.minusDays(numDays);
LocalDate currentDay = minimumDate;
dateMap = new HashMap<>();
for (int i = 0; i < numDays + 1; i++) {
float index = (float) i;
String dateString = currentDay.format(formatter);
dates.add(dateString);
dateMap.put(dateString, i);
BarEntry barEntry = new BarEntry(index, new float[] { 0, 0, 0, 0 });
entries.add(barEntry);
currentDay = currentDay.plusDays(1);
}
xAxis.setValueFormatter(new MyXAxisValueFormatter(dates));
xAxis.setLabelCount(numDays);
xAxis.setGranularity(1f);
xAxis.setLabelRotationAngle(45f);
UserAccount currentUser = HabitUpApplication.getCurrentUser();
// Get user events
ArrayList<HabitEvent> eventList = currentUser.getEventList().getEvents();
for (HabitEvent event : eventList) {
if (withinDateRange(event.getCompletedate(), minimumDate)) {
addChartEntry(event);
}
}
set = new BarDataSet(entries, "");
int red = Color.parseColor(Attributes.getColour("Physical"));
int purple = Color.parseColor(Attributes.getColour("Mental"));
int green = Color.parseColor(Attributes.getColour("Discipline"));
int blue = Color.parseColor(Attributes.getColour("Social"));
int[] colors = {red, purple, green, blue};
set.setColors(colors);
set.setStackLabels(new String[]{"Physical", "Mental", "Discipline", "Social"});
set.setDrawValues(false);
BarData data = new BarData(set);
data.setBarWidth(0.6f);
YAxis leftAxis = chart.getAxisLeft();
leftAxis.setValueFormatter(new MyYAxisValueFormatter());
leftAxis.setGranularity(1f);
leftAxis.setAxisMinimum(0f);
chart.getAxisRight().setEnabled(false);
chart.setData(data);
chart.setFitBars(true);
chart.getXAxis().setDrawGridLines(false);
chart.getAxisLeft().setDrawGridLines(false);
chart.getDescription().setEnabled(false);
animateChart();
chart.invalidate();
return view;
}
示例7: init
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
private void init(Context context, AttributeSet attrs, int defStyle) {
setDrawBarShadow(false);
setDrawValueAboveBar(true);
getDescription().setEnabled(false);
setMaxVisibleValueCount(60);
setDrawGridBackground(false);
XAxis xAxis = getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f);
xAxis.setLabelCount(7);
xAxis.setTextColor(Color.GRAY);
YAxis leftAxis = getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setLabelCount(8, false);
leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
leftAxis.setSpaceTop(15f);
leftAxis.setAxisMinimum(0f);
leftAxis.setTextColor(Color.GRAY);
YAxis rightAxis = getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setDrawAxisLine(false);
rightAxis.setLabelCount(8, false);
rightAxis.setDrawLabels(false);
rightAxis.setSpaceTop(15f);
rightAxis.setAxisMinimum(0f);
Legend l = getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setForm(Legend.LegendForm.SQUARE);
l.setFormSize(9f);
l.setTextSize(11f);
l.setXEntrySpace(4f);
}
示例8: initChart
import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
/**
* 初始化报表
*
* @param showAnimation 是否显示动画
*/
void initChart(boolean showAnimation) {
int screenWidth = Utils.getScreenWidth(mContext);
combinedChart.getLayoutParams().height = screenWidth * 300 / 640;
//启用缩放和拖动
combinedChart.setDragEnabled(true);//拖动
combinedChart.setScaleEnabled(false);//缩放
combinedChart.setOnChartValueSelectedListener(this);
combinedChart.getDescription().setEnabled(false);
combinedChart.setBackgroundColor(ContextCompat.getColor(mContext, R.color.co10));
combinedChart.setDrawGridBackground(false);
combinedChart.setDrawBarShadow(false);
combinedChart.setHighlightFullBarEnabled(false);
Legend l = combinedChart.getLegend();
l.setForm(Legend.LegendForm.NONE);//底部样式
l.setTextColor(ContextCompat.getColor(mContext, R.color.transparent));
l.setWordWrapEnabled(false);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
YAxis rightAxis = combinedChart.getAxisRight();
rightAxis.setEnabled(false);
YAxis leftAxis = combinedChart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setGranularityEnabled(false);
leftAxis.setDrawAxisLine(false);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
leftAxis.setTextColor(ContextCompat.getColor(mContext, R.color.co4));
updateTitle(items.get(dateSelected));
XAxis xAxis = combinedChart.getXAxis();
xAxis.setTypeface(mTfLight);
xAxis.setEnabled(true);//设置轴启用或禁用 如果禁用以下的设置全部不生效
xAxis.setDrawAxisLine(true);//是否绘制轴线
xAxis.setDrawGridLines(false);//设置x轴上每个点对应的线
xAxis.setDrawLabels(true);//绘制标签 指x轴上的对应数值
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);//设置x轴的显示位置
xAxis.setTextSize(10f); //设置X轴文字大小
xAxis.setGranularityEnabled(true);//是否允许X轴上值重复出现
xAxis.setTextColor(ContextCompat.getColor(this, R.color.co4));//设置X轴文字颜色
// //设置竖线的显示样式为虚线
// //lineLength控制虚线段的长度
// //spaceLength控制线之间的空间
xAxis.enableGridDashedLine(10f, 10f, 0f);
xAxis.setAxisMinimum(0f);//设置x轴的最小值
xAxis.setAxisMaximum(mDatas.length);//设置最大值
xAxis.setAvoidFirstLastClipping(true);//图表将避免第一个和最后一个标签条目被减掉在图表或屏幕的边缘
xAxis.setLabelRotationAngle(0f);//设置x轴标签字体的旋转角度
// 设置x轴显示标签数量 还有一个重载方法第二个参数为布尔值强制设置数量 如果启用会导致绘制点出现偏差
xAxis.setLabelCount(10);
xAxis.setGridLineWidth(10f);//设置竖线大小
// xAxis.setGridColor(Color.RED);//设置竖线颜色
xAxis.setAxisLineColor(Color.GRAY);//设置x轴线颜色
xAxis.setAxisLineWidth(1f);//设置x轴线宽度
CombinedData combinedData = new CombinedData();
combinedData.setData(generateLineData());
combinedData.setData(generateBarData());
combinedData.setValueTypeface(mTfLight);
xAxis.setAxisMaximum(combinedData.getXMax() + 0.25f);
//X轴的数据格式
ValueFormatter xAxisFormatter = new ValueFormatter(combinedChart);
xAxisFormatter.setmValues(xAxisValue);
xAxis.setValueFormatter(xAxisFormatter);//格式化x轴标签显示字符
combinedChart.setData(combinedData);
combinedChart.invalidate();
if (showAnimation) {
combinedChart.animateY(2000);
}
}