我在//loop through each year to build our objects needed for the chart
$.each(jsonData.results, function(i, row) {
data = row.dt;
CumulativeDayTotal = 0
yAxis = [];
$.each(data, function(i, row) {
CumulativeDayTotal = parseInt(row[yValueKey]) + parseInt(CumulativeDayTotal);
formattedDate = new Date(row["DATE_F"]);
formattedDate = (formattedDate.getMonth() + 1) + '/' + formattedDate.getDate() + '/' + formattedDate.getFullYear();
yAxis.push("{ y: " + CumulativeDayTotal + ", x: '" + formattedDate + "'}");
});
//create color for each new line/year
lineColor = dynamicColors();
chartPlaceHolders += '{label:"' + row.year + '", data:[' + yAxis + '],' +
'fill: false,' +
'lineTension: 0.1,' +
'backgroundColor: "' + lineColor + '",' +
'borderColor: "' + lineColor + '",' +
'borderCapStyle: "butt",' +
'borderDash: [],' +
'borderDashOffset: 0.0,' +
'borderJoinStyle: "miter",' +
'pointBorderColor: "rgba(75,192,192,1)",' +
'pointBackgroundColor: "#fff",' +
'pointBorderWidth: .2,' +
'pointHoverRadius: 5,' +
'pointHoverBackgroundColor: "rgba(75,192,192,1)",' +
'pointHoverBorderColor: "rgba(220,220,220,1)",' +
'pointHoverBorderWidth: 0,' +
'pointRadius: .5,' +
'pointHitRadius: 1' +
'},';
});
}
//remove last comma from string
chartPlaceHolders = chartPlaceHolders.replace(/,\s*$/, "");
chartPlaceHolders = "[" + chartPlaceHolders + "]";
var initFields = eval("(" + chartPlaceHolders + ")");
//call newly created elements into a variable to pass along to the other functions
var ctx = $("#primaryChart")[0].getContext("2d");
var myChart = new Chart(ctx, {
type: 'line',
data: {
datasets: initFields
},
options: {
scales: {
yAxes: [{
scaleLabel: {
display: true,
labelString: yAxisLabel
}
}],
xAxes: [{
type: 'time',
time: {
unit: 'month',
displayFormats: {
max: 'December',
min: 'January',
//max: moment().startOf('year'),
//min: moment().endOf('year'),
'millisecond': 'MMMM',
'second': 'MMMM',
'minute': 'MMMM',
'hour': 'MMMM',
'day': 'MMMM',
'week': 'MMMM',
'month': 'MMMM',
'quarter': 'MMMM',
'year': 'MMMM',
}
},
scaleLabel: {
display: true,
labelString: xAxisLabel
}
}]
}
}
});
编写了一个简单的程序来添加数字。
scala
在尝试编译时,我收到警告
object AplusB {
def main(args: Array[String]): Unit = {
val rawInput = Console.readLine()
val nums = rawInput.split(" ")
println(args(0).toInt + args(1).toInt)
}
}
我该怎么做才能解决这个问题?尝试从控制台读取数据时有哪些最佳做法?
答案 0 :(得分:1)
首先,请允许我建议一个未弃用的替代解决方案。
import scala.io.StdIn
object AplusB {
def main(args: Array[String]): Unit = {
val rawInput = StdIn.readLine()
val nums = rawInput.split(" ")
println(args(0).toInt + args(1).toInt)
}
}
Console.readLine()方法已弃用,我认为 StdIn.readLine()已被引入以替换它。
当弃用某个方法时,这意味着在将来的某个版本中可能会删除此方法。这个未来版本可能是下一个版本,甚至是未来的几个版本。我认为对于少数版本,可能不会删除不推荐使用的方法,以免破坏依赖于此方法的旧代码。
一个方法可能会被弃用,因为它对于一个例子效率低下,或者语言或框架开发人员意识到在这个特定的类或包中并且需要移动它等等没有意义。< / p>