本文整理汇总了Java中lecho.lib.hellocharts.model.SliceValue类的典型用法代码示例。如果您正苦于以下问题:Java SliceValue类的具体用法?Java SliceValue怎么用?Java SliceValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SliceValue类属于lecho.lib.hellocharts.model包,在下文中一共展示了SliceValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawSlices
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
/**
* Draw all slices for this PieChart, if mode == {@link #MODE_HIGHLIGHT} currently selected slices will be redrawn
* and
* highlighted.
*
* @param canvas
*/
private void drawSlices(Canvas canvas) {
final PieChartData data = dataProvider.getPieChartData();
final float sliceScale = 360f / maxSum;
float lastAngle = rotation;
int sliceIndex = 0;
for (SliceValue sliceValue : data.getValues()) {
final float angle = Math.abs(sliceValue.getValue()) * sliceScale;
if (isTouched() && selectedValue.getFirstIndex() == sliceIndex) {
drawSlice(canvas, sliceValue, lastAngle, angle, MODE_HIGHLIGHT);
} else {
drawSlice(canvas, sliceValue, lastAngle, angle, MODE_DRAW);
}
lastAngle += angle;
++sliceIndex;
}
}
示例2: drawLabels
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
public void drawLabels(Canvas canvas) {
final PieChartData data = dataProvider.getPieChartData();
final float sliceScale = 360f / maxSum;
float lastAngle = rotation;
int sliceIndex = 0;
for (SliceValue sliceValue : data.getValues()) {
final float angle = Math.abs(sliceValue.getValue()) * sliceScale;
if (isTouched()) {
if (hasLabels) {
drawLabel(canvas, sliceValue, lastAngle, angle);
} else if (hasLabelsOnlyForSelected && selectedValue.getFirstIndex() == sliceIndex) {
drawLabel(canvas, sliceValue, lastAngle, angle);
}
} else {
if (hasLabels) {
drawLabel(canvas, sliceValue, lastAngle, angle);
}
}
lastAngle += angle;
++sliceIndex;
}
}
示例3: drawSlice
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
/**
* Method draws single slice from lastAngle to lastAngle+angle, if mode = {@link #MODE_HIGHLIGHT} slice will be
* darken
* and will have bigger radius.
*/
private void drawSlice(Canvas canvas, SliceValue sliceValue, float lastAngle, float angle, int mode) {
sliceVector.set((float) (Math.cos(Math.toRadians(lastAngle + angle / 2))),
(float) (Math.sin(Math.toRadians(lastAngle + angle / 2))));
normalizeVector(sliceVector);
drawCircleOval.set(originCircleOval);
if (MODE_HIGHLIGHT == mode) {
// Add additional touch feedback by setting bigger radius for that slice and darken color.
drawCircleOval.inset(-touchAdditional, -touchAdditional);
slicePaint.setColor(sliceValue.getDarkenColor());
canvas.drawArc(drawCircleOval, lastAngle, angle, true, slicePaint);
} else {
slicePaint.setColor(sliceValue.getColor());
canvas.drawArc(drawCircleOval, lastAngle, angle, true, slicePaint);
}
}
示例4: getValueForAngle
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
/**
* Returns SliceValue that is under given angle, selectedValue (if not null) will be hold slice index.
*/
public SliceValue getValueForAngle(int angle, SelectedValue selectedValue) {
final PieChartData data = dataProvider.getPieChartData();
final float touchAngle = (angle - rotation + 360f) % 360f;
final float sliceScale = 360f / maxSum;
float lastAngle = 0f;
int sliceIndex = 0;
for (SliceValue sliceValue : data.getValues()) {
final float tempAngle = Math.abs(sliceValue.getValue()) * sliceScale;
if (touchAngle >= lastAngle) {
if (null != selectedValue) {
selectedValue.set(sliceIndex, sliceIndex, SelectedValueType.NONE);
}
return sliceValue;
}
lastAngle += tempAngle;
++sliceIndex;
}
return null;
}
示例5: drawSeparationLines
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
private void drawSeparationLines(Canvas canvas) {
PieChartData data = this.dataProvider.getPieChartData();
if (data.getValues().size() >= 2) {
int sliceSpacing = ChartUtils.dp2px(this.density, data.getSlicesSpacing());
if (sliceSpacing >= 1) {
float sliceScale = 360.0f / this.maxSum;
float lastAngle = (float) this.rotation;
float circleRadius = this.originCircleOval.width() / 2.0f;
this.separationLinesPaint.setStrokeWidth((float) sliceSpacing);
for (SliceValue sliceValue : data.getValues()) {
float angle = Math.abs(sliceValue.getValue()) * sliceScale;
this.sliceVector.set((float) Math.cos(Math.toRadians((double) lastAngle)), (float) Math.sin(Math.toRadians((double) lastAngle)));
normalizeVector(this.sliceVector);
Canvas canvas2 = canvas;
canvas2.drawLine(this.originCircleOval.centerX(), this.originCircleOval.centerY(), (this.sliceVector.x * (((float) this.touchAdditional) + circleRadius)) + this.originCircleOval.centerX(), (this.sliceVector.y * (((float) this.touchAdditional) + circleRadius)) + this.originCircleOval.centerY(), this.separationLinesPaint);
lastAngle += angle;
}
}
}
}
示例6: getValueForAngle
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
public SliceValue getValueForAngle(int angle, SelectedValue selectedValue) {
float touchAngle = (((float) (angle - this.rotation)) + 360.0f) % 360.0f;
float sliceScale = 360.0f / this.maxSum;
float lastAngle = 0.0f;
int sliceIndex = 0;
for (SliceValue sliceValue : this.dataProvider.getPieChartData().getValues()) {
float tempAngle = Math.abs(sliceValue.getValue()) * sliceScale;
if (touchAngle < lastAngle) {
lastAngle += tempAngle;
sliceIndex++;
} else if (selectedValue == null) {
return sliceValue;
} else {
selectedValue.set(sliceIndex, sliceIndex, SelectedValueType.NONE);
return sliceValue;
}
}
return null;
}
示例7: initMealsPie
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
public static void initMealsPie(PieChartView pieChartView, TodayDiets todayDiets) {
List<SliceValue> values = new ArrayList();
if (todayDiets.breakfast != null && todayDiets.breakfast.percentage > 0.0f) {
values.add(new SliceValue(todayDiets.breakfast.percentage, MEALS_COLORS[0]).setLabel(
((int) (todayDiets.breakfast.percentage * 100.0f)) + "%早餐"));
}
if (todayDiets.lunch != null && todayDiets.lunch.percentage > 0.0f) {
values.add(new SliceValue(todayDiets.lunch.percentage, MEALS_COLORS[1]).setLabel((
(int) (todayDiets.lunch.percentage * 100.0f)) + "%午餐"));
}
if (todayDiets.dinner != null && todayDiets.dinner.percentage > 0.0f) {
values.add(new SliceValue(todayDiets.dinner.percentage, MEALS_COLORS[2]).setLabel((
(int) (todayDiets.dinner.percentage * 100.0f)) + "%晚餐"));
}
PieChartData data = new PieChartData(values);
data.setHasLabels(true);
data.setHasLabelsOnlyForSelected(false);
data.setHasLabelsOutside(false);
data.setHasCenterCircle(false);
data.setSlicesSpacing(3);
data.setValueLabelBackgroundColor(0);
data.setValueLabelBackgroundEnabled(true);
pieChartView.setValueSelectionEnabled(true);
pieChartView.setPieChartData(data);
pieChartView.startDataAnimation();
}
示例8: onCreateView
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
setHasOptionsMenu(true);
View rootView = inflater.inflate(R.layout.fragment_pie_chart, container, false);
chart = (PieChartView) rootView.findViewById(R.id.chart);
chart.setOnValueTouchListener(new PieChartOnValueSelectListener() {
@Override
public void onValueSelected(int arcIndex, SliceValue value) {
Toast.makeText(getActivity(), String.valueOf(value.getLabelAsChars()), Toast.LENGTH_SHORT).show();
}
@Override
public void onValueDeselected() {
}
});
toggleLabelForSelected();
return rootView;
}
示例9: setGraph
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
private void setGraph(PieChartView graph, PieChartData data,int color){
ArrayList<SliceValue> sliceValues = new ArrayList<>();
SliceValue sliceValue2 = new SliceValue(1);
SliceValue sliceValue = new SliceValue(0);
sliceValues.add(sliceValue);
sliceValues.add(sliceValue2);
sliceValue.setColor(color);
sliceValue2.setColor(getResources().getColor(R.color.dark_custom_gray));
data.setHasCenterCircle(true);
data.setCenterCircleColor(Color.BLACK);
data.setValues(sliceValues);
data.setCenterText1FontSize(12);
data.setCenterText1Typeface(Typeface.DEFAULT_BOLD);
data.setCenterText1Color(Color.WHITE);
graph.setPieChartData(data);
graph.setChartRotationEnabled(false);
}
示例10: generateData
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
private void generateData() {
List<SliceValue> values = new ArrayList<SliceValue>();
String s1 = String.format("%.2f", ((double) yes / all) * 100);
SliceValue sliceValue1 = new SliceValue(yes, ChartUtils.pickColor());
sliceValue1.setLabel("已报到" + s1 + "%");
values.add(sliceValue1);
String s2 = String.format("%.2f", ((double) no / all) * 100);
SliceValue sliceValue2 = new SliceValue(no, ChartUtils.pickColor());
sliceValue2.setLabel("未报到" + s2 + "%");
values.add(sliceValue2);
data = new PieChartData(values);
data.setHasLabels(true);
data.setHasLabelsOnlyForSelected(false);
data.setHasLabelsOutside(false);
chart.setValueSelectionEnabled(true);
chart.setCircleFillRatio(1.0f);
chart.setPieChartData(data);
}
示例11: generateData
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
private void generateData() {
List<SliceValue> values = new ArrayList<SliceValue>();
String s1 = String.format("%.2f", ((double) yes / all) * 100);
SliceValue sliceValue1 = new SliceValue(yes, ChartUtils.pickColor());
sliceValue1.setLabel("已报到" + s1 + "%");
values.add(sliceValue1);
String s2 = String.format("%.2f", ((double) no / all) * 100);
SliceValue sliceValue2 = new SliceValue(no, ChartUtils.pickColor());
sliceValue2.setLabel("未报到" + s2 + "%");
values.add(sliceValue2);
data = new PieChartData(values);
data.setHasLabels(true);
data.setHasLabelsOnlyForSelected(false);
data.setHasLabelsOutside(false);
chart.setValueSelectionEnabled(true);
chart.setCircleFillRatio(1.0f);
chart.setPieChartData(data);
}
示例12: generateData
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
private void generateData() {
List<SliceValue> values = new ArrayList<SliceValue>();
String s1 = String.format("%.2f", ((double) yes / all) * 100);
SliceValue sliceValue1 = new SliceValue(yes, ChartUtils.pickColor());
sliceValue1.setLabel("已报到"+s1+"%");
values.add(sliceValue1);
String s2 = String.format("%.2f", ((double) no / all) * 100);
SliceValue sliceValue2 = new SliceValue(no, ChartUtils.pickColor());
sliceValue2.setLabel("未报到"+s2+"%");
values.add(sliceValue2);
data = new PieChartData(values);
data.setHasLabels(true);
data.setHasLabelsOnlyForSelected(false);
data.setHasLabelsOutside(false);
chart.setValueSelectionEnabled(true);
chart.setCircleFillRatio(1.0f);
chart.setPieChartData(data);
}
示例13: onValueSelected
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
@Override
public void onValueSelected(int i, SliceValue arcValue) {
if (lastScaleMeasurement == null) {
return;
}
String date_time = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.SHORT).format(lastScaleMeasurement.getDateTime());
switch (i) {
case 0:
Toast.makeText(getActivity(), getResources().getString(R.string.info_your_fat) + " " + lastScaleMeasurement.getFat() + "% " + getResources().getString(R.string.info_on_date) + " " + date_time, Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(getActivity(), getResources().getString(R.string.info_your_water) + " " + lastScaleMeasurement.getWater() + "% " + getResources().getString(R.string.info_on_date) + " " + date_time, Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(getActivity(), getResources().getString(R.string.info_your_muscle) + " " + lastScaleMeasurement.getMuscle() + "% " + getResources().getString(R.string.info_on_date) + " " + date_time, Toast.LENGTH_SHORT).show();
break;
}
}
示例14: initPieChart
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
private void initPieChart(final PieChartView pieChart) {
initBaseChart(pieChart);
pieChart.setChartRotationEnabled(false);
pieChart.setChartRotation(180, false);
pieChart.setOnValueTouchListener(new PieChartOnValueSelectListener() {
@Override
public void onValueSelected(int arcIndex, SliceValue value) {
SliceValue slice = pieChart.getPieChartData().getValues().get(arcIndex);
if (slice instanceof EctsSliceValue) {
pieChart.getPieChartData().setCenterText1(AppUtils.format(getContext(), "%.2f ECTS", ((EctsSliceValue) slice).getEcts()));
Grade grade = ((EctsSliceValue) slice).getGrade();
if (grade != null) {
pieChart.getPieChartData().setCenterText2(getContext().getString(grade.getStringResID()));
}
}
}
@Override
public void onValueDeselected() {
pieChart.getPieChartData().setCenterText1(null);
pieChart.getPieChartData().setCenterText2(null);
}
});
}
示例15: callTouchListener
import lecho.lib.hellocharts.model.SliceValue; //导入依赖的package包/类
@Override
public void callTouchListener() {
SelectedValue selectedValue = chartRenderer.getSelectedValue();
if (selectedValue.isSet()) {
SliceValue sliceValue = data.getValues().get(selectedValue.getFirstIndex());
onValueTouchListener.onValueSelected(selectedValue.getFirstIndex(), sliceValue);
} else {
onValueTouchListener.onValueDeselected();
}
}