I have no idea why my yearly shows nothing in the graph while the log successfully shows…
- User
I have no idea why my yearly shows nothing in the graph while the log successfully shows the number (Document: 2023, Total: 1650000.0, Date: Sun Jan 01 00:00:00 GMT+08:00 2023), also I want to make a persistentMarker which is a parameter in the columnChart, like this
persistentMarkers: Map<Float, Marker>? = null
how to fix the code?
- Assistant
To help you fix the code, I need to see the code you're referring to. However, I can give some general guidance on how to address the issues mentioned.
-
Yearly graph shows nothing: If the yearly graph isn't showing any data, you'll want to check the data source or data manipulation that is being used to populate the graph. Make sure the data being passed to the graph is in the correct format and that it covers the yearly timeframe.
-
Adding a persistentMarker: To create a persistent marker as a parameter in a column chart, you'll want to follow this general approach:
Define a data class for the
Markerand create an instance for thepersistentMarkersMap:data class Marker(val value: Float, val label: String) val persistentMarkers: Map<Float, Marker> = mapOf(0f to Marker(0f, "markerLabel"))Next, use the
persistentMarkersMap in your ColumnChart: -
- User
- Assistant
To add the
persistentMarkersfeature to yourExpensesScreen, you can follow the steps mentioned in the previous answer:- Define a data class for the
Marker:
data class Marker(val value: Float, val label: String)- Create the
markersMap inside theExpensesScreenfunction:
val markers = remember { mutableStateOf<Map<Float, Marker>>(emptyMap()) }- Update the
fetchExpensesDatafunction to add the markers as needed. As an example, I'm setting a marker on the first entry of the chart:
- Define a data class for the
- User
I think the yearly chart has no data because of this line of code
expenses.retainAll { it.second >= startCalendar.time && it.second <= endCalendar.time }
- Assistant
Yes, you're correct! The
retainAllmethod could be the cause of the issue for the "Yearly" chart. Since thestartCalendarandendCalendarvariables are not updated to a specific range inside the "Yearly" case in thewhenstatement, they still have the default values (i.e., both are set to the current date), which results in theretainAllcondition filtering out all the data for the "Yearly" chart.To address this, you need to set the appropriate time range for the start and end in the "Yearly" section of your
whenstatement. For example, you can show data for the last five years as follows:"Yearly" -> { startCalendar.add(Calendar.YEAR, -5) // Assume 5 years range startCalendar.set(Calendar.MONTH, 0) startCalendar.set(Calendar.DAY_OF_MONTH, 1) endCalendar.set(Calendar.MONTH, 11) endCalendar.set( Calendar.DAY_OF_MONTH, endCalendar.getActualMaximum(Calendar.DAY_OF_MONTH) ) dateFormat = SimpleDateFormat("yyyy", Locale.getDefault()) }This will ensure the "Yearly" chart displays the data of the last five years, and the method will work as intended. Feel free to adjust the range based on your requirements.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.