我实时有一张图表......
我的代码是
public class Chart_Broadcaster
{
public class LineChart
{
[JsonProperty("lineChartData")]
private int[] lineChartData;
[JsonProperty("colorString")]
private string colorString;
[JsonProperty("hora")]
private string[] hora = new string[60];
public void SetLineChartData()
{
//Suppose we have a list of 60 items.
using (ZigBeeContext db = new ZigBeeContext())
{
var lista = (from p in db.Medidas
orderby p.FechaHora descending
select p
).ToList();
lineChartData = db.Medidas.Select(p => p.Temperatura).Cast<int>().ToArray();
hora = db.Medidas.Select(p => p.FechaHora).Cast<string>().ToArray();
}
}
}
public class TemperatureUpdate
{
[JsonProperty("DashboardTemperatureResult")]
private List<DashboardTemperatureResult> temp;
public void TakeLastTemp()
{
using (ZigBeeContext db = new ZigBeeContext())
{
var result = db.Empresas.Include("Dispositivos.Medidas").ToList();
List<DashboardTemperatureResult> lis = new List<DashboardTemperatureResult>();
foreach (var item in result.SelectMany(x => x.Dispositivos))
{
if (item.Medidas.OrderBy(y => y.FechaHora).Any())
lis.Add(new DashboardTemperatureResult
{
DispositivoId = item.Medidas.OrderBy(y => y.FechaHora).LastOrDefault().DispositivoID,
Empresa = item.Medidas.OrderBy(y => y.FechaHora).LastOrDefault().Dispositivo.Empresa.Nombre,
Temperature = item.Medidas.OrderBy(y => y.FechaHora).LastOrDefault().Temperatura
});
}
temp = lis;
}
}
}
var lineChartData = {
datasets: [
{
fill: false,
lineTension: 0.1,
//backgroundColor: "#000000",
borderColor: "rgba(125,0,0,0)",
borderCapStyle: 'butt',
borderDash: [],
borderDashOffset: 0.0,
borderJoinStyle: 'miter',
pointBorderColor: "rgba(75,192,192,1)",
pointBackgroundColor: "#7FFF00",
pointBorderWidth: 1,
pointHoverRadius: 5,
pointHoverBackgroundColor: "rgba(75,192,192,1)",
pointHoverBorderColor: "rgba(220,220,220,1)",
pointHoverBorderWidth: 2,
pointRadius: 1,
pointHitRadius: 10,
data: [0]
}
]
}
function UpdateLineChart(data) {
lineChartData.labels = data.hora;
var canvasForLineChart = document.getElementById("canvasForLineChart");
var context2DLine = canvasForLineChart.getContext("2d");
new Chart(context2DLine).Line(lineChartData);
}
我的图表如下:
我的图表上有很多数据,不是很干净,包含我数据库中的所有记录,
正如我每次清理x时间一样。