| | |
| | | import android.graphics.Color |
| | | import android.widget.GridLayout |
| | | import android.widget.Toast |
| | | import androidx.cardview.widget.CardView |
| | | import androidx.lifecycle.lifecycleScope |
| | | import com.example.firstapp.database.response.UserInfo |
| | | import com.example.firstapp.database.service.RetrofitClient |
| | |
| | | private var currentDateType = DateType.DAY |
| | | private lateinit var barChart: BarChart |
| | | private lateinit var pieChart: PieChart |
| | | private lateinit var chartCourierDistriBution:CardView |
| | | private lateinit var heatmapView: View |
| | | private var currentUserInfo: UserInfo? = null // 确保使用你的实际数据类 |
| | | |
| | | private var startDateCur:String = "" |
| | | private var endDateCur:String = "" |
| | | private lateinit var bar_title:TextView |
| | | private lateinit var pie_title:TextView |
| | | |
| | | |
| | | enum class DateType { |
| | |
| | | |
| | | private fun setupTabLayout() { |
| | | val weekStatsView = binding.layoutWeekStats.root |
| | | val bar_title:TextView = weekStatsView.findViewById(R.id.bar_title) |
| | | val pie_title:TextView = weekStatsView.findViewById(R.id.pie_title) |
| | | bar_title = weekStatsView.findViewById(R.id.bar_title) |
| | | pie_title = weekStatsView.findViewById(R.id.pie_title) |
| | | |
| | | binding.tabDateRange.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
| | | override fun onTabSelected(tab: TabLayout.Tab?) { |
| | |
| | | |
| | | val weekStatsView = binding.layoutWeekStats.root |
| | | barChart = weekStatsView.findViewById(R.id.chart_daily_packages) |
| | | chartCourierDistriBution=weekStatsView.findViewById(R.id.chart_courier_card_view) |
| | | pieChart = weekStatsView.findViewById(R.id.chart_courier_distribution) |
| | | heatmapView = weekStatsView.findViewById(R.id.heatmap_yearly) |
| | | |
| | |
| | | PieEntry(stat.count.toFloat(), "${stat.courierName}(${stat.count})") |
| | | } |
| | | |
| | | val dataSet = PieDataSet(entries, "快递公司分布") |
| | | dataSet.colors = listOf( |
| | | resources.getColor(R.color.purple_500), |
| | | resources.getColor(R.color.teal_200), |
| | | resources.getColor(R.color.purple_200), |
| | | resources.getColor(R.color.teal_700) |
| | | ) |
| | | dataSet.valueTextSize = 14f // 增大数值文字大小 |
| | | if (entries.isNotEmpty()) { |
| | | val dataSet = PieDataSet(entries, "快递公司分布") |
| | | dataSet.colors = listOf( |
| | | resources.getColor(R.color.light_blue_600_1), |
| | | resources.getColor(R.color.sunflower), |
| | | resources.getColor(R.color.light_blue), |
| | | resources.getColor(R.color.vermillion), |
| | | resources.getColor(R.color.fish_belly_white), |
| | | resources.getColor(R.color.light_green), |
| | | resources.getColor(R.color.crimson), |
| | | resources.getColor(R.color.sky_blue), |
| | | resources.getColor(R.color.gold), |
| | | resources.getColor(R.color.light_purple), |
| | | resources.getColor(R.color.yellow), |
| | | resources.getColor(R.color.canary_yellow), |
| | | resources.getColor(R.color.red_purple), |
| | | resources.getColor(R.color.light_cyan), |
| | | resources.getColor(R.color.orange), |
| | | resources.getColor(R.color.magenta), |
| | | resources.getColor(R.color.light_purple_2), |
| | | resources.getColor(R.color.bright_yellow), |
| | | resources.getColor(R.color.emerald_green), |
| | | resources.getColor(R.color.turmeric), |
| | | resources.getColor(R.color.red_gold), |
| | | resources.getColor(R.color.off_white), |
| | | resources.getColor(R.color.tangerine), |
| | | resources.getColor(R.color.aqua_blue), |
| | | resources.getColor(R.color.frost), |
| | | resources.getColor(R.color.wisteria), |
| | | resources.getColor(R.color.cyan) |
| | | ) |
| | | dataSet.valueTextSize = 14f // 增大数值文字大小 |
| | | |
| | | val pieData = PieData(dataSet) |
| | | pieData.setValueFormatter(object : ValueFormatter() { |
| | | override fun getFormattedValue(value: Float): String { |
| | | return value.toInt().toString() |
| | | } |
| | | }) |
| | | val pieData = PieData(dataSet) |
| | | pieData.setValueFormatter(object : ValueFormatter() { |
| | | override fun getFormattedValue(value: Float): String { |
| | | return value.toInt().toString() |
| | | } |
| | | }) |
| | | |
| | | pieChart.data = pieData |
| | | pieChart.invalidate() |
| | | pieChart.data = pieData |
| | | pieChart.invalidate() |
| | | |
| | | pieChart.visibility = View.VISIBLE // 例如:隐藏 PieChart |
| | | |
| | | pie_title.visibility = View.VISIBLE |
| | | |
| | | chartCourierDistriBution.visibility =View.VISIBLE |
| | | |
| | | } else { |
| | | // 如果 entries 为空,可以选择隐藏图表或设置一个默认显示 |
| | | pieChart.visibility = View.GONE // 例如:隐藏 PieChart |
| | | |
| | | pie_title.visibility = View.GONE |
| | | |
| | | chartCourierDistriBution.visibility =View.GONE |
| | | |
| | | } |
| | | |
| | | |
| | | // val dataSet = PieDataSet(entries, "快递公司分布") |
| | | // dataSet.colors = listOf( |
| | | // resources.getColor(R.color.purple_500), |
| | | // resources.getColor(R.color.teal_200), |
| | | // resources.getColor(R.color.purple_200), |
| | | // resources.getColor(R.color.teal_700) |
| | | // ) |
| | | // dataSet.valueTextSize = 14f // 增大数值文字大小 |
| | | // |
| | | // val pieData = PieData(dataSet) |
| | | // pieData.setValueFormatter(object : ValueFormatter() { |
| | | // override fun getFormattedValue(value: Float): String { |
| | | // return value.toInt().toString() |
| | | // } |
| | | // }) |
| | | // |
| | | // pieChart.data = pieData |
| | | // pieChart.invalidate() |
| | | } |
| | | } |
| | | private fun getDayLabels(): Array<String> { |