我需要在ChartSampleData()
中传递2个参数,但是我遇到了麻烦,因为它说明了这一点
List<ChartSampleData> _list = [];
_list.add(ChartSampleData.fromMap(
'${formattedDate.toString()}', redeemedToday[index].total));
不能将参数类型'String'分配给参数类型'Map
这是我的课程
我尝试这样做,
代码:
class ChartSampleData {
ChartSampleData(this.xValue, this.yValue);
ChartSampleData.fromMap(
Map<String, dynamic> dataMap0, Map<String, dynamic> dataMap1)
: xValue = dataMap0['x'],
yValue = dataMap1['y'];
final dynamic xValue;
final dynamic yValue;
}
答案 0 :(得分:2)
您使用了错误的构造函数。使用double
代替ChartSampleData
。
ChartSampleData.fromMap
答案 1 :(得分:1)
我认为您需要像这样更改模型类:
library('data.table')
a = data.table(var1 = c(1,2,3,10,123,12,31,4,6,2), bvar = 1:2)
meansd = function(x, sd = TRUE){
if(!sd) return(mean(x))
return(list(mean = mean(x), sd = sd(x)))
}
#Presumable syntax:
a[, .(meansd(var1, T), meansd(var1, T)), by = bvar] #data are long on metric which is not ideal
#> bvar V1 V2
#> 1: 1 32.8 32.8
#> 2: 1 51.8575 51.8575
#> 3: 2 6 6
#> 4: 2 4.690416 4.690416
#What I was hoping the output would be (dcast call results):
ideal = a[, .(meansd(var1, T), meansd(var1, T)), by = bvar]
ideal[, metric := rep(c('mean', 'sd'),2)]
#ideally the output would look something like this, without the need for the dcast:
dcast(ideal,bvar~metric, value.var = c('V1','V2')) #names are nice, but unimportant
#> bvar V1_mean V1_sd V2_mean V2_sd
#> 1: 1 32.8 51.8575 32.8 51.8575
#> 2: 2 6 4.690416 6 4.690416
您可以使用此website将JSON转换为Dart模型。