本文整理匯總了Java中com.github.mikephil.charting.charts.BarChart.setData方法的典型用法代碼示例。如果您正苦於以下問題:Java BarChart.setData方法的具體用法?Java BarChart.setData怎麽用?Java BarChart.setData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.github.mikephil.charting.charts.BarChart
的用法示例。
在下文中一共展示了BarChart.setData方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的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: onCreateView
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frag_simple_bar, container, false);
// create a new chart object
mChart = new BarChart(getActivity());
mChart.getDescription().setEnabled(false);
mChart.setOnChartGestureListener(this);
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
mv.setChartView(mChart); // For bounds control
mChart.setMarker(mv);
mChart.setDrawGridBackground(false);
mChart.setDrawBarShadow(false);
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"OpenSans-Light.ttf");
mChart.setData(generateBarData(1, 20000, 12));
Legend l = mChart.getLegend();
l.setTypeface(tf);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(tf);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
mChart.getAxisRight().setEnabled(false);
XAxis xAxis = mChart.getXAxis();
xAxis.setEnabled(false);
// programatically add the chart
FrameLayout parent = (FrameLayout) v.findViewById(R.id.parentLayout);
parent.addView(mChart);
return v;
}
示例3: onCreateView
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_historique_graph, container, false);
// Gestion de l'affichage graphique
rlGraphHistorique = (RelativeLayout) view.findViewById(R.id.rlGraphHistorique);
graphiqueHistorique = new BarChart(getContext());
final RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
rlGraphHistorique.addView(graphiqueHistorique,lp);
List<BarEntry> entries = getEntries(pointMesures);
BarDataSet dataSet = new BarDataSet(entries, "Graphique Historique");
//TODO : ne fonctionne pas avec le fichier de ressource colors
dataSet.setColor(R.color.barColorGraph);
dataSet.setValueTextColor(R.color.textColorGraph);
BarData lineData = new BarData(dataSet);
graphiqueHistorique.setData(lineData);
graphiqueHistorique.getLegend().setEnabled(false);
graphiqueHistorique.getDescription().setEnabled(false);
graphiqueHistorique.invalidate(); // refresh
return view;
}
示例4: setHorizontalBarChart
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的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));
}
示例5: setVerticalBarChart
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的package包/類
/**
* Set the vertical bar pattern
* @param barChart chart
* @param chartData pie chart data
* @param typeface Typeface font
*/
public static void setVerticalBarChart(Context context, BarChart barChart, ChartData<?> chartData,
Typeface typeface) {
// create a custom MarkerView (extend MarkerView) and specify the layout to use for it
ExperienceMarker marker = new ExperienceMarker(context, R.layout.marker_exp_age);
marker.setChartView(barChart); // For bounds control
barChart.setMarker(marker);
//fix crash com.github.mikephil.charting.charts.Chart.drawMarkers(Chart.java:731)
barChart.setDrawMarkers(false);
barChart.getDescription().setEnabled(false);
barChart.setDrawGridBackground(false);
barChart.setDrawBarShadow(false);
XAxis xAxis = barChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
//Sets the number of labels for the x-axis (display all the x-axis values)
// xAxis.setLabelCount(chartData.getEntryCount());
xAxis.setTypeface(typeface);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(true);
YAxis leftAxis = barChart.getAxisLeft();
leftAxis.setTypeface(typeface);
leftAxis.setSpaceTop(20f);
leftAxis.setAxisMinimum(0f);
YAxis rightAxis = barChart.getAxisRight();
rightAxis.setTypeface(typeface);
rightAxis.setSpaceTop(20f);
rightAxis.setAxisMinimum(0f);
chartData.setValueTypeface(typeface);
barChart.setData((BarData) chartData);
barChart.setFitBars(true);
barChart.animateY(DURATION_SHORT);
}
示例6: onCreateView
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_idpt, container, false);
BarChart chart = (BarChart) view.findViewById(R.id.chart);
BarData data = new BarData(getXAxisValues(), getDataSet());
//legend coding
Legend l=chart.getLegend();
l.setFormSize(10f);
l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT);
l.setTextSize(12f);
l.setTextColor(Color.BLACK);
l.setXEntrySpace(5f);
l.setYEntrySpace(5f);
//l.setCustom();
XAxis xaxis=chart.getXAxis();
xaxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xaxis.setTextSize(7f);
xaxis.setTextColor(Color.parseColor("#212121"));
xaxis.setDrawAxisLine(true);
xaxis.setDrawGridLines(false);
chart.setData(data);
chart.setDescription("");
chart.animateXY(2000, 2000);
chart.invalidate();
// chart.zoom(100, 10, 10, 10);
return view;
}
示例7: onCreateView
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frag_simple_bar, container, false);
// create a new chart object
mChart = new BarChart(getActivity());
mChart.setDescription("");
mChart.setOnChartGestureListener(this);
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
mChart.setMarkerView(mv);
mChart.setDrawGridBackground(false);
mChart.setDrawBarShadow(false);
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"OpenSans-Light.ttf");
mChart.setData(generateBarData(1, 20000, 12));
Legend l = mChart.getLegend();
l.setTypeface(tf);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(tf);
leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)
mChart.getAxisRight().setEnabled(false);
XAxis xAxis = mChart.getXAxis();
xAxis.setEnabled(false);
// programatically add the chart
FrameLayout parent = (FrameLayout) v.findViewById(R.id.parentLayout);
parent.addView(mChart);
return v;
}
示例8: onCreate
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chart);
BarChart chart = (BarChart) findViewById(R.id.chart);
//BarData data = new BarData(getXAxisValues(),getDataSet());
BarData data = new BarData();
chart.setData(data);
chart.setDescription("My Chart");
chart.animateXY(2000, 2000);
chart.invalidate();
}
示例9: createBarChart
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的package包/類
/**
* Creates the bar chart showing counters visually.
*/
private void createBarChart(BarChart barChart) {
if (game != null) {
ArrayList<BarEntry> entries = new ArrayList<>();
ArrayList<BarEntry> entries2 = new ArrayList<>();
// create simple bar chart
// fill single rolls, 1..6
int[] counts = sr.getCounts();
for (int i = 0; i < counts.length; i++) {
entries.add(new BarEntry(counts[i], i));
}
// fill double roll sums, 2..12
counts = dr.getSumCount();
for (int i = 0; i < counts.length; i++) {
entries2.add(new BarEntry(counts[i], i + 1));
}
BarDataSet dataset = new BarDataSet(entries, "# of single rolls: " + sr.getTotal());
BarDataSet dataset2 = new BarDataSet(entries2, "# of double rolls: " + dr.getTotal());
ArrayList<String> labels = new ArrayList<>();
// fill label for dice roll sums, 1..12
for (int i = 0; i < 12; i++) {
labels.add(Integer.toString(i + 1));
}
// explicit color resolving with util, see AboutActivity#demoBarChart
List<Integer> colors = ColorTemplate.createColors(getResources(), new int[]{R.color.colorSingleRoll, R.color.colorDoubleRoll});
//dataset.setColors(ColorTemplate.COLORFUL_COLORS);
dataset.setColor(colors.get(0));
dataset2.setColor(colors.get(1));
BarData data = new BarData(labels, dataset);
data.addDataSet(dataset2);
barChart.setData(data);
}
}
示例10: onCreate
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
barChart = (BarChart)findViewById(R.id.chart);
ArrayList<BarEntry> entries = new ArrayList<>();
entries.add(new BarEntry(4f, 0));
entries.add(new BarEntry(8f, 1));
entries.add(new BarEntry(6f, 2));
entries.add(new BarEntry(12f, 3));
entries.add(new BarEntry(18f, 4));
entries.add(new BarEntry(9f, 5));
BarDataSet dataset = new BarDataSet(entries, "# of Calls");
//Add this to set the color
// dataset.setColors(ColorTemplate.COLORFUL_COLORS);
ArrayList<String> labels = new ArrayList<String>();
labels.add("January");
labels.add("February");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
data = new BarData(labels,dataset);
barChart.setData(data);
barChart.setDescription("Bar Chart Desc");
}
示例11: setupTemperatureChart
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的package包/類
protected void setupTemperatureChart(){
EnvStatistic temperature = mHDD.getSessionData().getCurrentStats().getTemperature();
if(temperature!=null && temperature.isValid()){
mTempChart = new BarChart(this);
List<BarEntry> statVals = new ArrayList<>(3);
statVals.add(new BarEntry((float) temperature.getMin(), 0));
statVals.add(new BarEntry((float) temperature.getAvg(), 1));
statVals.add(new BarEntry((float) temperature.getMax(), 2));
BarDataSet summary = new BarDataSet(statVals,"Temperature");
mTempChart.setData(new BarData(new String[]{"Min", "Avg", "Max"}, summary));
mTempChart.setDescription("");
mTempChart.animateY(2000);
mTempChart.getAxisRight().setEnabled(false);
mTempChart.setTouchEnabled(false);
mTempChart.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
mTempChart.setMinimumHeight(STATISTIC_CHART_HEIGHT);
mTempChartContainer.addView(mTempChart);
}
else{
TextView noGraph = new TextView(this);
noGraph.setText("No Temperature Statistics to Show");
noGraph.setGravity(View.TEXT_ALIGNMENT_CENTER);
mTempChartContainer.addView(noGraph);
}
}
示例12: setupPressureChart
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的package包/類
protected void setupPressureChart(){
EnvStatistic pressure = mHDD.getSessionData().getCurrentStats().getPressure();
if(pressure!=null && pressure.isValid()){
mPressureChart = new BarChart(this);
List<BarEntry> statVals = new ArrayList<>(3);
statVals.add(new BarEntry((float) pressure.getMin(),0));
statVals.add(new BarEntry((float) pressure.getAvg(), 1));
statVals.add(new BarEntry((float) pressure.getMax(), 2));
BarDataSet summary = new BarDataSet(statVals,"Pressure");
mPressureChart.setData(new BarData(new String[]{"Min", "Avg", "Max"}, summary));
mPressureChart.setDescription("");
mPressureChart.animateY(2000);
mPressureChart.getAxisRight().setEnabled(false);
mPressureChart.setTouchEnabled(false);
mPressureChart.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
mPressureChart.setMinimumHeight(STATISTIC_CHART_HEIGHT);
mPressureChartContainer.addView(mPressureChart);
}
else{
TextView noGraph = new TextView(this);
noGraph.setText("No Pressure Statistics to Show");
noGraph.setGravity(View.TEXT_ALIGNMENT_CENTER);
mPressureChartContainer.addView(noGraph);
}
}
示例13: setupHumidityChart
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的package包/類
protected void setupHumidityChart(){
EnvStatistic humidity = mHDD.getSessionData().getCurrentStats().getHumidity();
if(humidity!=null && humidity.isValid()){
mHumidityChart = new BarChart(this);
List<BarEntry> statVals = new ArrayList<>(3);
statVals.add(new BarEntry((float) humidity.getMin(), 0));
statVals.add(new BarEntry((float) humidity.getAvg(), 1));
statVals.add(new BarEntry((float) humidity.getMax(), 2));
BarDataSet summary = new BarDataSet(statVals,"Humidity");
mHumidityChart.setData(new BarData(new String[]{"Min", "Avg", "Max"}, summary));
mHumidityChart.setDescription("");
mHumidityChart.animateY(2000);
mHumidityChart.getAxisRight().setEnabled(false);
mHumidityChart.setTouchEnabled(false);
mHumidityChart.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
mHumidityChart.setMinimumHeight(STATISTIC_CHART_HEIGHT);
mHumidityChartContainer.addView(mHumidityChart);
}
else{
TextView noGraph = new TextView(this);
noGraph.setText("No Humidity Statistics to Show");
noGraph.setGravity(View.TEXT_ALIGNMENT_CENTER);
mHumidityChartContainer.addView(noGraph);
}
}
示例14: updateSpectrumGUI
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的package包/類
private void updateSpectrumGUI() {
ArrayList<String> xVals = new ArrayList<String>();
ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();
double[] freqLabels = measurementService.getAudioProcess().getRealtimeCenterFrequency();
float[] freqValues = measurementService.getAudioProcess().getThirdOctaveFrequencySPL();
for(int idfreq =0; idfreq < freqLabels.length; idfreq++) {
xVals.add(Spectrogram.formatFrequency((int)freqLabels[idfreq]));
// Sum values
// Compute frequency range covered by frequency
yVals1.add(new BarEntry(new float[] {freqValues[idfreq]}, idfreq));
}
BarDataSet set1 = new BarDataSet(yVals1, "DataSet");
set1.setColor(Color.rgb(102, 178, 255));
set1.setStackLabels(new String[]{
"SL"
});
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
BarData data = new BarData(xVals, dataSets);
data.setValueTextSize(10f);
BarChart sChart = getSpectrum();
if(sChart != null){
sChart.setData(data);
sChart.setPadding(0, 0, 0, 0);
sChart.setViewPortOffsets(0,0,0,0);
sChart.invalidate(); // refresh
}
}
示例15: populateUserStatsChart
import com.github.mikephil.charting.charts.BarChart; //導入方法依賴的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
}
}