//app.js app.get(“/history/:countryname”),异步(req,res)=>{
const global = await api.all();
const updated = global.updated;
const updatedFormat = new Date(updated).toLocaleString('en-US', {timeZoneName: "short"});
let countryName = _.lowerCase(req.params.countryName);
countryName = countryName.toString();
const history = await api.historical.countries({country:'China' , days: '10'});
const historyCases = history.timeline.cases;
const historyDeaths = history.timeline.deaths;
const historyRecovered = history.timeline.recovered;
for (var i in historyCases){
caseLabel.push(i);
caseData.push(historyCases[i]);
}
for (var i in historyDeaths){
deathData.push(historyDeaths[i]);
}
for (var i in historyRecovered){
recoveredData.push(historyRecovered[i]);
}
let formattedCountry = countryName.toUpperCase();
res.render("country", {caseData, deathData, recoveredData, caseLabel, updatedFormat, formattedCountry} );
caseData = [];
deathData = [];
recoveredData = [];
caseLabel = [];
})
//country.ejs在此处输入代码'var ctx=document.getelementbyid('mychart').getcontext('2d');var mychart=new chart(ctx,{type:'line',data:{label:labels,dataset:[{label:'cases',data:casedata,backgroundcolor:'rgba(255,255,255,0.2)”,bordercolor:'4c92bb',borderwidth:2},{label:'deaths',data:deathdata backgroundcolor:'rgba(255,255,255,0.2'),bordercolor:'de354c',borderwidth:'2},{label:'recovered',数据:recovereddata,backgroundcolor:'rgba(255,255,255,0.2'),bordercolor:'#deb135',borderwidth:2}]},};
暂无答案!
目前还没有任何答案,快来回答吧!