|
| 1 | +package ir.maryamsh.financialmanagement; |
| 2 | + |
| 3 | +import android.content.Context; |
| 4 | +import android.content.SharedPreferences; |
| 5 | +import android.graphics.Color; |
| 6 | +import android.graphics.Typeface; |
| 7 | +import android.os.Bundle; |
| 8 | +import android.view.LayoutInflater; |
| 9 | +import android.view.View; |
| 10 | +import android.view.ViewGroup; |
| 11 | + |
| 12 | +import androidx.annotation.NonNull; |
| 13 | +import androidx.annotation.Nullable; |
| 14 | +import androidx.fragment.app.Fragment; |
| 15 | + |
| 16 | +import com.github.mikephil.charting.charts.BarChart; |
| 17 | +import com.github.mikephil.charting.charts.PieChart; |
| 18 | +import com.github.mikephil.charting.components.XAxis; |
| 19 | +import com.github.mikephil.charting.data.BarData; |
| 20 | +import com.github.mikephil.charting.data.BarDataSet; |
| 21 | +import com.github.mikephil.charting.data.BarEntry; |
| 22 | +import com.github.mikephil.charting.data.PieData; |
| 23 | +import com.github.mikephil.charting.data.PieDataSet; |
| 24 | +import com.github.mikephil.charting.data.PieEntry; |
| 25 | +import com.github.mikephil.charting.utils.ColorTemplate; |
| 26 | +import com.google.android.material.transition.MaterialSharedAxis; |
| 27 | + |
| 28 | +import java.util.ArrayList; |
| 29 | + |
| 30 | +public class report_fragement extends Fragment { |
| 31 | + View view; |
| 32 | + Context context; |
| 33 | + SharedPreferences shPrefs; |
| 34 | + PieChart pieChart; |
| 35 | + public report_fragement(Context context){ |
| 36 | + this.context=context; |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public void onCreate( Bundle savedInstanceState) { |
| 41 | + super.onCreate(savedInstanceState); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public View onCreateView( LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { |
| 46 | + view =inflater.inflate(R.layout.report_fragment,container,false); |
| 47 | + SharedPreferences shPref = context.getSharedPreferences("shPref", context.MODE_PRIVATE); |
| 48 | + String co=shPref.getString("co", "12"); |
| 49 | + String earn=shPref.getString("earn", "12"); |
| 50 | + pieChart=view.findViewById(R.id.piechart); |
| 51 | + ArrayList<PieEntry> pieEntries=new ArrayList<>(); |
| 52 | + pieEntries.add(new PieEntry(Integer.parseInt(co),"هزینه")); |
| 53 | + pieEntries.add(new PieEntry(Integer.parseInt(earn),"درآمد")); |
| 54 | + pieEntries.add(new PieEntry(Integer.parseInt(earn) - Integer.parseInt(co),"باقی مانده")); |
| 55 | + |
| 56 | + PieDataSet pieDataSet=new PieDataSet(pieEntries,"عنوان"); |
| 57 | + |
| 58 | + pieDataSet.setColors(ColorTemplate.MATERIAL_COLORS); |
| 59 | + pieDataSet.setValueTextColor(Color.BLACK); |
| 60 | + pieDataSet.setValueTextSize(16f); |
| 61 | + pieDataSet.setValueTypeface(Typeface.createFromAsset(context.getAssets(), "kalameh_regular.ttf")); |
| 62 | + |
| 63 | + |
| 64 | + PieData pieData=new PieData(pieDataSet); |
| 65 | + pieChart.setData(pieData); |
| 66 | + pieChart.getDescription().setEnabled(false); |
| 67 | + pieChart.setCenterText("گزارش مالی"); |
| 68 | + pieChart.setCenterTextTypeface(Typeface.createFromAsset(context.getAssets(), "kalameh_regular.ttf")); |
| 69 | + pieChart.animate(); |
| 70 | + return view; |
| 71 | + } |
| 72 | +} |
0 commit comments