本文整理汇总了Java中com.github.mikephil.charting.components.YAxis.setGranularity方法的典型用法代码示例。如果您正苦于以下问题:Java YAxis.setGranularity方法的具体用法?Java YAxis.setGranularity怎么用?Java YAxis.setGranularity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.mikephil.charting.components.YAxis
的用法示例。
在下文中一共展示了YAxis.setGranularity方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupYAxis
import com.github.mikephil.charting.components.YAxis; //导入方法依赖的package包/类
private void setupYAxis()
{
int valuesSelectedItemPos = cache.getValuesSpinner().getSelectedItemPosition();
YAxis leftAxis = this.chart.getAxisLeft();
leftAxis.setLabelCount(10, false);
leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
leftAxis.setSpaceTop(20f);
leftAxis.setAxisMinValue(0f);
leftAxis.setValueFormatter(new PFAYAxisLabels(context, valuesSelectedItemPos, cache.getNumberScale()));
if ( valuesSelectedItemPos == StatisticsQuery.QUANTITY )
{
leftAxis.setGranularity(1f); // interval 1
}
YAxis rightAxis = this.chart.getAxisRight();
rightAxis.setEnabled(false);
}
示例2: setHorizontalBarChart
import com.github.mikephil.charting.components.YAxis; //导入方法依赖的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));
}
示例3: onCreate
import com.github.mikephil.charting.components.YAxis; //导入方法依赖的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_sinus);
mSinusData = FileUtils.loadBarEntriesFromAssets(getAssets(), "othersine.txt");
tvX = (TextView) findViewById(R.id.tvValueCount);
mSeekBarX = (SeekBar) findViewById(R.id.seekbarValues);
mChart = (BarChart) findViewById(R.id.chart1);
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(true);
mChart.getDescription().setEnabled(false);
// if more than 60 entries are displayed in the chart, no values will be
// drawn
mChart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
// draw shadows for each bar that show the maximum value
// mChart.setDrawBarShadow(true);
// mChart.setDrawXLabels(false);
mChart.setDrawGridBackground(false);
// mChart.setDrawYLabels(false);
XAxis xAxis = mChart.getXAxis();
xAxis.setEnabled(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(mTfLight);
leftAxis.setLabelCount(6, false);
leftAxis.setAxisMinimum(-2.5f);
leftAxis.setAxisMaximum(2.5f);
leftAxis.setGranularityEnabled(true);
leftAxis.setGranularity(0.1f);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setTypeface(mTfLight);
rightAxis.setLabelCount(6, false);
rightAxis.setAxisMinimum(-2.5f);
rightAxis.setAxisMaximum(2.5f);
rightAxis.setGranularity(0.1f);
mSeekBarX.setOnSeekBarChangeListener(this);
mSeekBarX.setProgress(150); // set data
Legend l = mChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setForm(LegendForm.SQUARE);
l.setFormSize(9f);
l.setTextSize(11f);
l.setXEntrySpace(4f);
mChart.animateXY(2000, 2000);
}
示例4: setUpBarChart
import com.github.mikephil.charting.components.YAxis; //导入方法依赖的package包/类
private void setUpBarChart() {
BarData barData = generateBarData(project.getTimeSpent());
XAxis xAxis = barChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setAxisLineColor(Color.WHITE);
xAxis.setTextColor(Color.WHITE);
xAxis.setDrawGridLines(false);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(new FormatUtils().getBarXAxisValueFormatterInstance(referenceTime));
xAxis.setAxisLineWidth(2f);
YAxis leftAxis = barChart.getAxisLeft();
leftAxis.removeAllLimitLines();
leftAxis.setDrawGridLines(false);
leftAxis.setAxisLineColor(Color.WHITE);
leftAxis.setTextColor(Color.WHITE);
leftAxis.setGranularity(60 * 60);
leftAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
int hours = (int) TimeUnit.SECONDS.toHours((long) Math.ceil(value));
return (hours == 0)
? "" : context.getString(R.string.hours, hours);
}
});
leftAxis.setAxisLineWidth(2f);
int maxYData = (int) (Math.ceil(barData.getYMax()) + 3600);
leftAxis.setAxisMaximum(maxYData);
leftAxis.setAxisMinimum(0f);
CustomMarkerView customMarkerView = new CustomMarkerView(context, R.layout.marker_view, referenceTime);
barChart.setMarker(customMarkerView);
barChart.getAxisRight().setEnabled(false);
barChart.getLegend().setEnabled(false);
barChart.getDescription().setEnabled(false);
barChart.setBackground(context.getResources().getDrawable(R.color.colorPrimaryDark));
barChart.setDrawGridBackground(false);
barChart.setDragEnabled(false);
barChart.setScaleEnabled(false);
barChart.setDragDecelerationEnabled(false);
barChart.setPinchZoom(false);
barChart.setDoubleTapToZoomEnabled(false);
barChart.setDrawBorders(false);
barChart.setData(barData);
customMarkerView.setChartView(barChart);
barChart.setVisibility(View.VISIBLE);
barChart.animateY(1500, Easing.EasingOption.Linear);
}
示例5: setUpBarChart
import com.github.mikephil.charting.components.YAxis; //导入方法依赖的package包/类
private void setUpBarChart(int dailyGoal, List<Integer> progressSoFar) {
BarData barData = generateBarData(dailyGoal, progressSoFar);
//Set up a limit line indicating the goal
LimitLine limitLine = new LimitLine(dailyGoal * 60 * 60, context.getString(R.string.goal));
limitLine.setLineWidth(4f);
limitLine.setLineColor(blue400);
limitLine.setTextSize(12f);
limitLine.setTextColor(Color.WHITE);
//Format Xaxis
XAxis xAxis = goalBarChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setAxisLineColor(Color.WHITE);
xAxis.setTextColor(Color.WHITE);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(new FormatUtils().getBarXAxisValueFormatterInstance(referenceTime));
xAxis.setAxisLineWidth(2f);
//Format Yaxis
YAxis leftAxis = goalBarChart.getAxisLeft();
leftAxis.removeAllLimitLines();
leftAxis.addLimitLine(limitLine);
leftAxis.setDrawGridLines(false);
leftAxis.setAxisLineColor(Color.WHITE);
leftAxis.setTextColor(Color.WHITE);
leftAxis.setGranularity(60 * 60);
leftAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
/* Do not display zero value and format the value as time*/
return (value == 0)
? "" : FormatUtils.getFormattedTime(context, (int) value);
}
});
leftAxis.setAxisLineWidth(2f);
//Set a maximum value on purpose so that marker view is visible
int maximum;
int maxYData = (int) TimeUnit.SECONDS.toHours((long) Math.ceil(barData.getYMax()));
maximum = (maxYData > dailyGoal) ? maxYData : dailyGoal;
maximum += 2;
leftAxis.setAxisMaximum(maximum * 60 * 60);
leftAxis.setAxisMinimum(0f);
// Setup a marker view to display details of the selected dataItem
CustomMarkerView customMarkerView = new CustomMarkerView(context, R.layout.marker_view, referenceTime);
goalBarChart.setMarker(customMarkerView);
// Disable interactions
goalBarChart.getAxisRight().setEnabled(false);
goalBarChart.getLegend().setEnabled(false);
goalBarChart.getDescription().setEnabled(false);
goalBarChart.setBackgroundColor(windowColor);
goalBarChart.setDrawGridBackground(false);
goalBarChart.setDragEnabled(false);
goalBarChart.setScaleEnabled(false);
goalBarChart.setDragDecelerationEnabled(false);
goalBarChart.setPinchZoom(false);
goalBarChart.setDoubleTapToZoomEnabled(false);
goalBarChart.setDrawBorders(false);
goalBarChart.setData(barData);
customMarkerView.setChartView(goalBarChart);
goalBarChart.setVisibility(View.VISIBLE);
goalBarChart.animateY(1500, Easing.EasingOption.Linear);
}
示例6: setUpActivityChart
import com.github.mikephil.charting.components.YAxis; //导入方法依赖的package包/类
private void setUpActivityChart() {
Legend l = lineChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setTextColor(Color.WHITE);
l.setTextSize(12);
l.setWordWrapEnabled(true);
l.setXEntrySpace(UiUtils.dpToPx(4));
l.setYEntrySpace(UiUtils.dpToPx(4));
YAxis rightAxis = lineChart.getAxisRight();
rightAxis.setEnabled(false);
YAxis leftAxis = lineChart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setAxisMinimum(0);
leftAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return value == 0 ? "" : String.valueOf(FormatUtils.getFormattedTime(context, (int) value));
}
});
leftAxis.setGranularityEnabled(true);
leftAxis.setGranularity(3600f); // FIXME: 12-04-2017 granularity not respected
leftAxis.setAxisLineWidth(2f);
leftAxis.setTextColor(Color.WHITE);
leftAxis.setAxisLineColor(Color.WHITE);
XAxis xAxis = lineChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setTextColor(Color.WHITE);
xAxis.setSpaceMin(0.5f);
xAxis.setSpaceMax(0.5f);
xAxis.setYOffset(UiUtils.dpToPx(4));
xAxis.setAxisLineWidth(2f);
xAxis.setAxisLineColor(Color.WHITE);
lineChart.getDescription().setEnabled(false);
lineChart.setDrawGridBackground(false);
lineChart.setBackground(context.getResources().getDrawable(R.color.colorPrimaryDark));
lineChart.setDragEnabled(false);
lineChart.setScaleEnabled(false);
lineChart.setDragDecelerationEnabled(false);
lineChart.setPinchZoom(false);
lineChart.setDoubleTapToZoomEnabled(false);
lineChart.setDrawBorders(false);
lineChart.setExtraOffsets(16, 0, 16, 0);
}
示例7: setUpActivityChart
import com.github.mikephil.charting.components.YAxis; //导入方法依赖的package包/类
private void setUpActivityChart() {
Legend l = lineChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setTextColor(Color.WHITE);
l.setTextSize(12);
l.setWordWrapEnabled(true);
l.setXEntrySpace(UiUtils.dpToPx(4));
l.setYEntrySpace(UiUtils.dpToPx(4));
YAxis rightAxis = lineChart.getAxisRight();
rightAxis.setEnabled(false);
YAxis leftAxis = lineChart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setAxisMinimum(0);
leftAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return value == 0 ? "" : String.valueOf(FormatUtils.getFormattedTime(context, (int) value));
}
});
leftAxis.setGranularityEnabled(true);
leftAxis.setGranularity(3600f); // FIXME: 12-04-2017 granularity not respected
leftAxis.setAxisLineWidth(2f);
leftAxis.setTextColor(Color.WHITE);
leftAxis.setAxisLineColor(Color.WHITE);
long referenceTime = new DateTime().plusDays(-7).getMillis();
XAxis xAxis = lineChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setValueFormatter(new FormatUtils().getBarXAxisValueFormatterInstance(referenceTime));
xAxis.setDrawGridLines(false);
xAxis.setTextColor(Color.WHITE);
xAxis.setSpaceMin(0.5f);
xAxis.setSpaceMax(0.5f);
xAxis.setYOffset(UiUtils.dpToPx(4));
xAxis.setAxisLineWidth(2f);
xAxis.setAxisLineColor(Color.WHITE);
CustomMarkerView customMarkerView = new CustomMarkerView(context, R.layout.marker_view, referenceTime);
lineChart.setMarker(customMarkerView);
lineChart.getDescription().setEnabled(false);
lineChart.setDrawGridBackground(false);
lineChart.setBackground(context.getResources().getDrawable(R.color.colorPrimaryDark));
lineChart.setDragEnabled(false);
lineChart.setScaleEnabled(false);
lineChart.setDragDecelerationEnabled(false);
lineChart.setPinchZoom(false);
lineChart.setDoubleTapToZoomEnabled(false);
lineChart.setDrawBorders(false);
lineChart.setExtraOffsets(16, 0, 16, 0);
customMarkerView.setChartView(lineChart);
}
示例8: onCreateView
import com.github.mikephil.charting.components.YAxis; //导入方法依赖的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;
}
示例9: initCharts
import com.github.mikephil.charting.components.YAxis; //导入方法依赖的package包/类
private void initCharts(BarChart mChart) {
mChart.setDrawBarShadow(false);
mChart.setDrawValueAboveBar(true);
mChart.setDescription("");
// if more than 60 entries are displayed in the chart, no values will be
// drawn
mChart.setMaxVisibleValueCount(60);
// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
// draw shadows for each bar that show the maximum value
// mChart.setDrawBarShadow(true);
// mChart.setDrawXLabels(false);
mChart.setDrawGridBackground(false);
// mChart.setDrawYLabels(false);
XAxis xAxis = mChart.getXAxis();
xAxis.setEnabled(false);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(BandApplication.INSTANCE.getTfLight());
leftAxis.setLabelCount(6, false);
// leftAxis.setAxisMinimum(-2.5f);
// leftAxis.setAxisMaximum(2.5f);
leftAxis.setGranularityEnabled(true);
leftAxis.setGranularity(0.1f);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setTypeface(BandApplication.INSTANCE.getTfLight());
rightAxis.setLabelCount(6, false);
// rightAxis.setAxisMinimum(-2.5f);
// rightAxis.setAxisMaximum(2.5f);
rightAxis.setGranularity(0.1f);
Legend l = mChart.getLegend();
l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);
l.setForm(Legend.LegendForm.SQUARE);
l.setFormSize(9f);
l.setTextSize(11f);
l.setXEntrySpace(4f);
mChart.animateXY(2000, 2000);
}
示例10: setYAxisConfig
import com.github.mikephil.charting.components.YAxis; //导入方法依赖的package包/类
protected void setYAxisConfig(YAxis axis, ReadableMap propMap) {
if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMaxValue")) {
axis.setAxisMaxValue((float) propMap.getDouble("axisMaxValue"));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMinValue")) {
axis.setAxisMinValue((float) propMap.getDouble("axisMinValue"));
}
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "inverted")) {
axis.setInverted(propMap.getBoolean("inverted"));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceTop")) {
axis.setSpaceTop((float) propMap.getDouble("spaceTop"));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceBottom")) {
axis.setSpaceBottom((float) propMap.getDouble("spaceBottom"));
}
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "showOnlyMinMax")) {
axis.setShowOnlyMinMax(propMap.getBoolean("showOnlyMinMax"));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "labelCount")) {
boolean labelCountForce = false;
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "labelCountForce")) {
labelCountForce = propMap.getBoolean("labelCountForce");
}
axis.setLabelCount(propMap.getInt("labelCount"), labelCountForce);
}
if (BridgeUtils.validate(propMap, ReadableType.String, "position")) {
axis.setPosition(YAxis.YAxisLabelPosition.valueOf(propMap.getString("position")));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "granularity")) {
axis.setGranularity((float) propMap.getDouble("granularity"));
}
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "granularityEnabled")) {
axis.setGranularityEnabled(propMap.getBoolean("granularityEnabled"));
}
// formatting
if (BridgeUtils.validate(propMap, ReadableType.String, "valueFormatter")) {
String valueFormatter = propMap.getString("valueFormatter");
if ("largeValue".equals(valueFormatter)) {
axis.setValueFormatter(new LargeValueFormatter());
} else if ("percent".equals(valueFormatter)) {
axis.setValueFormatter(new PercentFormatter());
} else {
axis.setValueFormatter(new CustomFormatter(valueFormatter));
}
}
// TODO docs says the remaining config needs to be applied before setting data. Test it
// zero line
if (BridgeUtils.validate(propMap, ReadableType.Map, "zeroLine")) {
ReadableMap zeroLineConfig = propMap.getMap("zeroLine");
if (BridgeUtils.validate(zeroLineConfig, ReadableType.Boolean, "enabled")) {
axis.setDrawZeroLine(zeroLineConfig.getBoolean("enabled"));
}
if (BridgeUtils.validate(zeroLineConfig, ReadableType.Number, "lineWidth")) {
axis.setZeroLineWidth((float) zeroLineConfig.getDouble("lineWidth"));
}
if (BridgeUtils.validate(zeroLineConfig, ReadableType.String, "lineColor")) {
axis.setZeroLineColor(Color.parseColor(zeroLineConfig.getString("lineColor")));
}
}
}