本文整理汇总了Java中com.github.mikephil.charting.data.BarData.setBarWidth方法的典型用法代码示例。如果您正苦于以下问题:Java BarData.setBarWidth方法的具体用法?Java BarData.setBarWidth怎么用?Java BarData.setBarWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.mikephil.charting.data.BarData
的用法示例。
在下文中一共展示了BarData.setBarWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreate
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.timevis_layout);
barchart = (BarChart) findViewById(R.id.barchart);
Intent intent = getIntent();
String ot = intent.getExtras().getString("ot");
String pt = intent.getExtras().getString("pt");
String lt = intent.getExtras().getString("lt");
String pert = intent.getExtras().getString("pert");
Float otf = Float.valueOf(ot);
Float ptf = Float.valueOf(pt);
Float ltf = Float.valueOf(lt);
Float pertf = Float.valueOf(pert);
List<BarEntry> entries = new ArrayList<>();
entries.add(new BarEntry(0f, otf.floatValue()));
entries.add(new BarEntry(1f, ptf.floatValue()));
entries.add(new BarEntry(2f, ltf.floatValue()));
entries.add(new BarEntry(3f, pertf.floatValue()));
BarDataSet set = new BarDataSet(entries, "Time Visualization");
BarData data = new BarData(set);
data.setBarWidth(0.9f); // set custom bar width
barchart.setData(data);
barchart.setFitBars(true); // make the x-axis fit exactly all bars
barchart.invalidate();
}
示例2: generateData
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
/**
* generates a random ChartData object with just one DataSet
*
* @return
*/
private BarData generateData(int cnt) {
ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
for (int i = 0; i < 12; i++) {
entries.add(new BarEntry(i, (float) (Math.random() * 70) + 30));
}
BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
d.setColors(ColorTemplate.VORDIPLOM_COLORS);
d.setBarShadowColor(Color.rgb(203, 203, 203));
ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>();
sets.add(d);
BarData cd = new BarData(sets);
cd.setBarWidth(0.9f);
return cd;
}
示例3: generateDataBar
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
/**
* generates a random ChartData object with just one DataSet
*
* @return
*/
private BarData generateDataBar(int cnt) {
ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
for (int i = 0; i < 12; i++) {
entries.add(new BarEntry(i, (int) (Math.random() * 70) + 30));
}
BarDataSet d = new BarDataSet(entries, "New DataSet " + cnt);
d.setColors(ColorTemplate.VORDIPLOM_COLORS);
d.setHighLightAlpha(255);
BarData cd = new BarData(d);
cd.setBarWidth(0.9f);
return cd;
}
示例4: generateBarData
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
private BarData generateBarData(List<Integer> progressSoFar) {
ArrayList<BarEntry> barEntries = new ArrayList<>(progressSoFar.size());
DateTime dateTime = new DateTime();
referenceTime = dateTime.minusDays(7).getMillis();
int totalSeconds = 0;
for (int i = 0; i < progressSoFar.size(); i++) {
int progress = progressSoFar.get(i);
barEntries.add(new BarEntry(i, progress));
totalSeconds += progress;
}
activityTotal.setText(context.getString(R.string.total_project_time,
FormatUtils.getFormattedTime(context, totalSeconds)));
BarDataSet barDataSet = new BarDataSet(barEntries, "");
barDataSet.setColors(blue400);
BarData barData = new BarData(barDataSet);
barData.setBarWidth(0.85f);
barData.setDrawValues(false);
return barData;
}
示例5: generateBarData
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
private BarData generateBarData(int dailyGoal, List<Integer> progressSoFar) {
ArrayList<BarEntry> barEntries = new ArrayList<>(progressSoFar.size());
DateTime dateTime = new DateTime();
referenceTime = dateTime.minusDays(7).getMillis();
for (int i = 0; i < progressSoFar.size(); i++) {
barEntries.add(new BarEntry(i, progressSoFar.get(i)));
}
BarDataSet barDataSet = new BarDataSet(barEntries, "");
int colors[] = new int[progressSoFar.size()];
for (int i = 0; i < progressSoFar.size(); i++) {
colors[i] = (progressSoFar.get(i) >= dailyGoal * 60 * 60) ? green400 : red400;
}
barDataSet.setColors(colors);
BarData barData = new BarData(barDataSet);
barData.setBarWidth(0.85f);
barData.setDrawValues(false);
return barData;
}
示例6: generateBarData
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
/**
* 柱形图数据
*/
private BarData generateBarData() {
BarData barData = new BarData();
ArrayList<BarEntry> entries1 = new ArrayList<>();
for (int index = 0; index < items.size(); index++) {
entries1.add(new BarEntry(index + 1f, (float) items.get(index).main_data.getData()));
}
BarDataSet barDataSet = new BarDataSet(entries1, "当前数据");
barDataSet.setValues(entries1);
barDataSet.setDrawValues(false);//是否在线上显示值
barDataSet.setColor(Color.rgb(230, 230, 230));
barDataSet.setHighLightColor(Color.parseColor(items.get(dateSelected).state.getColor()));
barDataSet.setValueTextColor(Color.rgb(60, 220, 78));
barDataSet.setValueTextSize(10f);
barDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
float barWidth = 0.45f;
barData.addDataSet(barDataSet);
barData.setBarWidth(barWidth);
return barData;
}
示例7: getBarData
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
public BarData getBarData() {
ArrayList<BarEntry> entries = new ArrayList<>();
float overall_people = 100f;
Log.d(TAG + "barData", barRatingCount[3] + "");
entries.add(new BarEntry(4, barRatingCount[4]));
entries.add(new BarEntry(3, barRatingCount[3]));
entries.add(new BarEntry(2, barRatingCount[2]));
entries.add(new BarEntry(1, barRatingCount[1]));
entries.add(new BarEntry(0, barRatingCount[0]));
BarDataSet dataset = new BarDataSet(entries, "");
dataset.setColors(CUSTOM_COLOR);
dataset.setDrawValues(false);
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(dataset);
BarData data = new BarData(dataSets);
// data.setValueTextSize(10f);
// data.setValueTypeface(fontType);
data.setBarWidth(1f);
return data;
}
示例8: generateBarData
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
private BarData generateBarData() {
ArrayList<BarEntry> entries1 = new ArrayList<BarEntry>();
ArrayList<BarEntry> entries2 = new ArrayList<BarEntry>();
for (int index = 0; index < itemcount; index++) {
entries1.add(new BarEntry(0, getRandom(25, 25)));
// stacked
entries2.add(new BarEntry(0, new float[]{getRandom(13, 12), getRandom(13, 12)}));
}
BarDataSet set1 = new BarDataSet(entries1, "Bar 1");
set1.setColor(Color.rgb(60, 220, 78));
set1.setValueTextColor(Color.rgb(60, 220, 78));
set1.setValueTextSize(10f);
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
BarDataSet set2 = new BarDataSet(entries2, "");
set2.setStackLabels(new String[]{"Stack 1", "Stack 2"});
set2.setColors(new int[]{Color.rgb(61, 165, 255), Color.rgb(23, 197, 255)});
set2.setValueTextColor(Color.rgb(61, 165, 255));
set2.setValueTextSize(10f);
set2.setAxisDependency(YAxis.AxisDependency.LEFT);
float groupSpace = 0.06f;
float barSpace = 0.02f; // x2 dataset
float barWidth = 0.45f; // x2 dataset
// (0.45 + 0.02) * 2 + 0.06 = 1.00 -> interval per "group"
BarData d = new BarData(set1, set2);
d.setBarWidth(barWidth);
// make this BarData object grouped
d.groupBars(0, groupSpace, barSpace); // start at x = 0
return d;
}
示例9: showBarChart
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
/**
* 展示柱状图(多条)
*
* @param xAxisValues
* @param yAxisValues
* @param labels
* @param colours
*/
public void showBarChart(List<Float> xAxisValues, List<List<Float>> yAxisValues, List<String> labels, List<Integer> colours) {
initLineChart();
BarData data = new BarData();
for (int i = 0; i < yAxisValues.size(); i++) {
ArrayList<BarEntry> entries = new ArrayList<>();
for (int j = 0; j < yAxisValues.get(i).size(); j++) {
entries.add(new BarEntry(xAxisValues.get(j), yAxisValues.get(i).get(j)));
}
BarDataSet barDataSet = new BarDataSet(entries, labels.get(i));
barDataSet.setColor(colours.get(i));
barDataSet.setValueTextColor(colours.get(i));
barDataSet.setValueTextSize(10f);
barDataSet.setAxisDependency(YAxis.AxisDependency.LEFT);
data.addDataSet(barDataSet);
}
int amount = yAxisValues.size();
float groupSpace = 0.12f; //柱状图组之间的间距
float barSpace = (float) ((1 - 0.12) / amount / 10); // x4 DataSet
float barWidth = (float) ((1 - 0.12) / amount / 10 * 9); // x4 DataSet
// (0.2 + 0.02) * 4 + 0.08 = 1.00 -> interval per "group"
xAxis.setLabelCount(xAxisValues.size() - 1, false);
data.setBarWidth(barWidth);
data.groupBars(0, groupSpace, barSpace);
mBarChart.setData(data);
}
示例10: generateBarData
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
private BarData generateBarData(float index, float dis) {
ArrayList<BarEntry> entries = new ArrayList<>();
for (int i = 0; i < count; i++) {
float a = new Random().nextInt(40) / 100f + 0.1f;
float b = new Random().nextInt(40) / 100f + 0.1f;
entries.add(new BarEntry(index, new float[]{a, b, 1 - a - b}));
index += dis;
}
BarDataSet set = new BarDataSet(entries, "hello");
set.setStackLabels(new String[]{"1", "2"});
set.setColors(new int[]{Color.rgb(154, 209, 253), Color.rgb(254, 206, 121), Color.rgb(253, 136, 95)});
set.setValueTextColor(Color.rgb(61, 165, 255));
set.setValueTextSize(10f);
set.setAxisDependency(YAxis.AxisDependency.LEFT);
ArrayList<IBarDataSet> threebardata = new ArrayList<>();
BarData d = new BarData(threebardata);
d.setBarWidth(0.4f);
d.setDrawValues(true);
d.addDataSet(set);
d.setValueFormatter(new IValueFormatter() {
@Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
return toPercentDecimalStr(value);
}
});
return d;
}
示例11: setUp
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
@Before
public void setUp() {
mockStatic(android.graphics.Color.class);
when(android.graphics.Color.rgb(anyInt(), anyInt(), anyInt())).thenReturn(0);
barData = new BarData();
barData.setBarWidth((1f - HistogramChart.GROUP_SPACE)/1);
barData.addDataSet(new BarDataSet(new ArrayList<BarEntry>(), "SomeLabel"));
data = new HistogramChart.HistogramData(1, 5f);
data.addEntry(barData, 0, 12);
data.addEntry(barData, 0, 14);
data.addEntry(barData, 0, 16);
data.addEntry(barData, 0, 21);
}
示例12: showAnalysis
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
@Override
public void showAnalysis(Report report) {
List<BarEntry> barEntries = new ArrayList<>();
List<Expense> expenses = report.getExpenses();
for (int i = 0; i < expenses.size(); i++) {
Expense expense = expenses.get(i);
barEntries.add(new BarEntry(
i,
expense.getAmount().floatValue())
);
}
BarDataSet barSet = new BarDataSet(barEntries, "");
barSet.setColor(selectedCategory.getColor());
List<IBarDataSet> dataSets = new ArrayList<>();
dataSets.add(barSet);
BarData data = new BarData(dataSets);
data.setValueTextSize(10f);
data.setValueTextColor(getOutlayTheme().secondaryTextColor);
data.setBarWidth(0.9f);
dayAxisValueFormatter.setExpenses(expenses);
barChart.setData(data);
barChart.invalidate();
barChart.animateY(500);
}
示例13: testGroupBars
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
@Test
public void testGroupBars() {
float groupSpace = 5f;
float barSpace = 1f;
List<BarEntry> values1 = new ArrayList<>();
List<BarEntry> values2 = new ArrayList<>();
for(int i = 0; i < 5; i++) {
values1.add(new BarEntry(i, 50));
values2.add(new BarEntry(i, 60));
}
BarDataSet barDataSet1 = new BarDataSet(values1, "Set1");
BarDataSet barDataSet2 = new BarDataSet(values2, "Set2");
BarData data = new BarData(barDataSet1, barDataSet2);
data.setBarWidth(10f);
float groupWidth = data.getGroupWidth(groupSpace, barSpace);
assertEquals(27f, groupWidth, 0.01f);
assertEquals(0f, values1.get(0).getX(), 0.01f);
assertEquals(1f, values1.get(1).getX(), 0.01f);
data.groupBars(1000, groupSpace, barSpace);
// 1000 + 2.5 + 0.5 + 5
assertEquals(1008f, values1.get(0).getX(), 0.01f);
assertEquals(1019f, values2.get(0).getX(), 0.01f);
assertEquals(1035f, values1.get(1).getX(), 0.01f);
assertEquals(1046f, values2.get(1).getX(), 0.01f);
data.groupBars(-1000, groupSpace, barSpace);
assertEquals(-992f, values1.get(0).getX(), 0.01f);
assertEquals(-981f, values2.get(0).getX(), 0.01f);
assertEquals(-965f, values1.get(1).getX(), 0.01f);
assertEquals(-954f, values2.get(1).getX(), 0.01f);
data.setBarWidth(20f);
groupWidth = data.getGroupWidth(groupSpace, barSpace);
assertEquals(47f, groupWidth, 0.01f);
data.setBarWidth(10f);
data.groupBars(-20, groupSpace, barSpace);
assertEquals(-12f, values1.get(0).getX(), 0.01f);
assertEquals(-1f, values2.get(0).getX(), 0.01f);
assertEquals(15f, values1.get(1).getX(), 0.01f);
assertEquals(26f, values2.get(1).getX(), 0.01f);
}
示例14: populateUserStatsChart
import com.github.mikephil.charting.data.BarData; //导入方法依赖的package包/类
/**
* Show user stats graph
*/
private void populateUserStatsChart() {
final String[] userStatsChartXAxisLabel = getActivity().getResources().getStringArray(R.array.user_stats_x_axis_labels);
final BarChart chart = getActivity().findViewById(R.id.user_stats_chart);
chart.setTouchEnabled(false);
XAxis xAxis = chart.getXAxis();
xAxis.setGranularity(1);
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setValueFormatter(new IAxisValueFormatter() {
/**
* Format the value
* @param value - value to fit to the axis
* @param axis - the axis to fit to
* @return Returns the formatted value
*/
@Override
public String getFormattedValue(float value, AxisBase axis) {
int v = (int) value;
return userStatsChartXAxisLabel[v];
}
});
xAxis.setDrawGridLines(false);
xAxis.setTextSize(11f);
YAxis rightAxis = chart.getAxisRight();
rightAxis.setEnabled(false);
chart.getAxisLeft().setGranularity(1);
chart.getDescription().setEnabled(false);
if (mUser != null) {
int[] colors = getActivity().getResources().getIntArray(R.array.user_stats_chart_colors);
List<BarEntry> entries = new ArrayList<>();
entries.add(new BarEntry(0f, mUser.getPlantsAdded()));
entries.add(new BarEntry(1f, mUser.getPlantsDeleted()));
entries.add(new BarEntry(2f, mUser.getWaterCount()));
entries.add(new BarEntry(3f, mUser.getMeasureCount()));
entries.add(new BarEntry(4f, mUser.getPhotoCount()));
BarDataSet barDataSet = new BarDataSet(entries, "Plant Operations");
barDataSet.setColors(ColorTemplate.createColors(colors));
barDataSet.setValueTextSize(11f);
BarData data = new BarData(barDataSet);
data.setBarWidth(0.9f); // set custom bar width
chart.setData(data);
chart.invalidate(); // refresh
}
}
示例15: onCreateView
import com.github.mikephil.charting.data.BarData; //导入方法依赖的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;
}