У меня установка размера гистограммыMPAndroidchartlibrary как я могу регулировать высоту Bar Chart в фрагменте
Я имею диаграмму внутри фрагмента, помещенных в деятельности проблема.
Если я использую setContentView (диаграмма), он заполнит весь экран, но я хочу его ограничить.
вот XML, где диаграмма получает Размещенные: (Изменение layout_height не помогло)
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.github.mikephil.charting.charts.BarChart
android:id="@+id/piechart"
android:layout_weight="2"
android:layout_width="fill_parent"
android:layout_height="30dp">
</com.github.mikephil.charting.charts.BarChart>
</ScrollView>
И Heres фрагмент:
package com.example.kim.s236322_mappe3.View;
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import com.example.kim.s236322_mappe3.R;
import com.github.mikephil.charting.charts.BarChart;
import com.github.mikephil.charting.data.BarData;
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.utils.ColorTemplate;
import java.util.ArrayList;
public class StatisticsFragment extends Fragment {
View view;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.statistics_layout,container,false);
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");
ArrayList<String> labels = new ArrayList<String>();
labels.add("January");
labels.add("February");
labels.add("March");
labels.add("April");
labels.add("May");
labels.add("June");
BarChart chart = new BarChart(getActivity().getBaseContext());
BarChart layout = (BarChart) view.findViewById(R.id.piechart);
layout.addView(chart);
BarData data = new BarData(labels, dataset);
chart.setData(data);
chart.setDescription("# of times Alice called Bob");
dataset.setColors(ColorTemplate.COLORFUL_COLORS);
chart.animateY(5000);
return view;
}
}
Почему вы кладете диаграмму внутри диаграммы? Просто используйте диаграмму, которую вы определили в xml, вместо создания нового. – GoneUp