feiyu02
2024-05-31 da431c25dfe5122e4ed70372da36ede3e4eaec4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.flightfeather.uav.common.chart
 
import com.flightfeather.uav.common.utils.DateUtil
import com.flightfeather.uav.domain.entity.BaseRealTimeData
import com.flightfeather.uav.socket.eunm.FactorType
 
/**
 * 走航数据生成图表
 * @date 2024/5/31
 * @author feiyu02
 */
object DataToChartUtil {
 
    fun lineToByteArray(type: FactorType?, data: List<BaseRealTimeData>): ByteArray {
        val title = type?.des ?: "未知监测因子"
        val seriesName = type?.des ?: "未知系列"
        val dataList = data.map { d ->
            ChartUtil.ChartValue(
                DateUtil.instance.dateToString(d.dataTime, DateUtil.DateStyle.HH_MM_SS),
                d.getByFactorType(type) ?: 0f
            )
        }
        val dataset = ChartUtil.newDataset(dataList, seriesName)
        return ChartUtil.lineToByteArray(title, dataset)
    }
}