Skip to content

Commit 34724ea

Browse files
committed
7days Graph set
1 parent ae98357 commit 34724ea

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/other.xml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/example/spendwise/Home.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,19 @@ class Home : Fragment() {
8787
val creditEntries = ArrayList<BarEntry>()
8888
val debitEntries = ArrayList<BarEntry>()
8989
val labels = ArrayList<String>()
90+
// here change the label : eg 22-01-2025 to 22'Wed
91+
92+
val inputDateFormat = SimpleDateFormat("dd-MM-yyyy", Locale.getDefault())
93+
val outputDateFormat = SimpleDateFormat("dd''EEE", Locale.getDefault()) // Format to `22'Wed`
9094

9195
weeklySummary.forEachIndexed { index, summary ->
9296
creditEntries.add(BarEntry(index.toFloat(), summary.totalCredit))
9397
debitEntries.add(BarEntry(index.toFloat(), summary.totalDebit))
94-
labels.add(summary.date)
98+
99+
// Convert date format
100+
val date = inputDateFormat.parse(summary.date)
101+
val formattedDate = outputDateFormat.format(date!!)
102+
labels.add(formattedDate)
95103
}
96104

97105
val creditDataSet = BarDataSet(creditEntries, "Credits").apply {
@@ -101,24 +109,29 @@ class Home : Fragment() {
101109
color = resources.getColor(R.color.debitColor, null)
102110
}
103111

104-
val barData = BarData(creditDataSet, debitDataSet).apply {
112+
// for double bar.
113+
val barData = BarData(creditDataSet,debitDataSet).apply {
105114
barWidth = 0.3f // Width of each bar
106115
}
107116

108117
barChart.apply {
109118
data = barData
110-
groupBars(0f, 0.4f, 0.05f) // Group the bars
111119
xAxis.apply {
112120
valueFormatter = IndexAxisValueFormatter(labels)
113121
position = XAxis.XAxisPosition.BOTTOM
114122
granularity = 1f
115123
isGranularityEnabled = true
116124
setDrawGridLines(false)
125+
//axisMinimum = 0f
126+
//axisMaximum = weeklySummary.size.toFloat() - 0.5f
127+
117128
}
129+
groupBars(-0.5f, 0.3f, 0.05f)
130+
setVisibleXRangeMaximum(7f)
118131
axisRight.isEnabled = false
119132
description.isEnabled = false
120133
animateY(1000)
121-
invalidate() // Refresh chart
134+
invalidate()
122135
}
123136
}
124137

app/src/main/res/layout/fragment_home.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
android:id="@+id/barChart"
3030
android:layout_width="380dp"
3131
android:layout_height="350dp"
32-
android:layout_margin="16dp"
33-
android:padding="5dp"
32+
android:layout_margin="5dp"
33+
android:padding="0dp"
3434
app:layout_constraintEnd_toEndOf="parent"
3535
app:layout_constraintStart_toStartOf="parent"
3636
app:layout_constraintTop_toBottomOf="@id/expensesHeadingTextView" />

0 commit comments

Comments
 (0)