public async Task <string> GetDiagnosesBySymptom(int idSymptom) { Random rand = new Random(); DataChart dc = new DataChart(); DataChart.Dataset dataset1 = new DataChart.Dataset(); List <SymptomWeight> diagnosesWeights = await db.SymptomsWeights.Where(sw => sw.IdSymptom == idSymptom).ToListAsync(); foreach (var diagnosisWeight in diagnosesWeights) { dc.labels.Add(diagnosisWeight.Diagnosis.Name); dataset1.data.Add(Math.Round(diagnosisWeight.Weight, 2)); dataset1.backgroundColor.Add($"rgba({rand.Next(0, 255)},{rand.Next(0, 255)},{rand.Next(0, 255)},1)"); dataset1.borderColor.Add($"rgba({rand.Next(0, 255)},{rand.Next(0, 255)},{rand.Next(0, 255)},0.4)"); } if (diagnosesWeights.Count != 0) { dataset1.label = diagnosesWeights[0].Symptom.Name; dc.datasets.Add(dataset1); } else { dc = null; } return(JsonConvert.SerializeObject(dc)); }
public ActionResult About() { //DataChart.Dataset dataset1 = new DataChart.Dataset(); //dataset1.label = "Choice a number"; //DataChart dc = new DataChart(); //dc.datasets = new List<DataChart.Dataset>() { dataset1 }; //ViewBag.dataChart = JsonConvert.SerializeObject(dc); //return View(); DataChart.Dataset dataset1 = new DataChart.Dataset(); dataset1.label = "# of Votes"; dataset1.data = new List <double>() { 12, 19, 3, 5, 2, 3 }; dataset1.backgroundColor = new List <string>() { "rgba(255, 99, 132, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(255, 206, 86, 0.2)", "rgba(75, 192, 192, 0.2)", "rgba(153, 102, 255, 0.2)", "rgba(255, 159, 64, 0.2)" }; dataset1.borderColor = new List <string>() { "rgba(255,99,132,1)", "rgba(54, 162, 235, 1)", "rgba(255, 206, 86, 1)", "rgba(75, 192, 192, 1)", "rgba(153, 102, 255, 1)", "rgba(255, 159, 64, 1)" }; dataset1.borderWidth = 1; DataChart dc = new DataChart(); dc.datasets = new List <DataChart.Dataset>() { dataset1 }; dc.labels = new List <string>() { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" }; ViewBag.dataChart = JsonConvert.SerializeObject(dc); return(View()); }
public ActionResult DiagnosesBySymptom() { DataChart.Dataset dataset1 = new DataChart.Dataset(); dataset1.label = ""; DataChart dc = new DataChart(); dc.datasets = new List <DataChart.Dataset>() { dataset1 }; ViewBag.dataChart = JsonConvert.SerializeObject(dc); return(View()); }
public string GetDataForChart(int x) { DataChart dc = new DataChart(); DataChart.Dataset dataset1 = new DataChart.Dataset(); dataset1.backgroundColor = new List <string>() { "rgba(255, 99, 132, 0.2)", "rgba(54, 162, 235, 0.2)", "rgba(255, 206, 86, 0.2)", "rgba(75, 192, 192, 0.2)", "rgba(153, 102, 255, 0.2)", "rgba(255, 159, 64, 0.2)" }; dataset1.borderColor = new List <string>() { "rgba(255,99,132,1)", "rgba(54, 162, 235, 1)", "rgba(255, 206, 86, 1)", "rgba(75, 192, 192, 1)", "rgba(153, 102, 255, 1)", "rgba(255, 159, 64, 1)" }; dataset1.borderWidth = 1; if (x == 1) { dataset1.label = "test1"; dataset1.data = new List <double>() { 12, 19, 3, 5, 2, 3 }; dc.labels = new List <string>() { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" }; } else { dataset1.label = "# of Votes"; dataset1.data = new List <double>() { 5, 9, 13, 1, 8, 7 }; dc.labels = new List <string>() { "Test", "Blue", "Yellow", "Green", "Purple", "Orange" }; } dc.datasets = new List <DataChart.Dataset>() { dataset1 }; return(JsonConvert.SerializeObject(dc)); }