Ejemplo n.º 1
0
        public ActionResult DrawChart(int zoneid)
        {
            List <Audit> temp = ServiceAudit.getalllatestAuditsforZone(zoneid);

            List <String> lastauditdates      = new List <String>(temp.Count);
            List <String> lastlevels          = new List <String>(temp.Count);
            DateTime      workaroungtogetdate = new DateTime();

            foreach (var item in temp)
            {
                lastlevels.Insert(0, item.FiveStarsLevel.ToString());
                workaroungtogetdate = (DateTime)item.DateOfCompletion;
                lastauditdates.Insert(0, workaroungtogetdate.ToString("dd/MM/yyyy"));
            }
            var   myTheme = @"
<Chart BackColor=""#CECECE"" BackGradientStyle=""TopBottom"" BackSecondaryColor=""White"" BorderColor=""26, 59, 105"" BorderlineDashStyle=""Solid"" BorderWidth=""2"" Palette=""BrightPastel"">
   <Series>
      <series _Template_=""All"" BorderColor=""180, 26, 59, 105"" BorderWidth=""5"" CustomProperties=""LabelStyle=Outside"" IsValueShownAsLabel=""False"" />
   </Series>
   <ChartAreas>
      <ChartArea Name=""Default"" _Template_=""All"" BackColor=""64, 165, 191, 228"" BackGradientStyle=""TopBottom"" BackSecondaryColor=""White"" BorderColor=""64, 64, 64, 64"" BorderDashStyle=""Solid"" ShadowColor=""Transparent"">
         <AxisY>
            <LabelStyle Format=""{#} ★"" />
         </AxisY>
      </ChartArea>
   </ChartAreas>
   <Legends>
      <Legend _Template_=""All"" BackColor=""Transparent"" Font=""Trebuchet MS, 8.25pt, style=Bold"" IsTextAutoFit=""False"" />
   </Legends>
   <BorderSkin SkinStyle=""None"" />
</Chart>";
            Chart chart;

            if (lastlevels.Count == 1)
            {
                chart = new Chart(width: 800, height: 200, theme: myTheme)
                        .AddTitle("la courbe de tendance depuis le 1er audit 5 stars ")
                        .AddSeries(
                    chartType: "Bar",
                    //x  & yValues must be of the same type to sync properly
                    xValue: lastauditdates,
                    yValues: lastlevels)
                        .SetYAxis(max: 5);
            }
            else
            {
                chart = new Chart(width: 800, height: 200, theme: myTheme)
                        .AddTitle("la courbe de tendance depuis le 1er audit 5 stars ")
                        .AddSeries(
                    chartType: "Line",
                    //x  & yValues must be of the same type to sync properly
                    xValue: lastauditdates,
                    yValues: lastlevels)
                        .SetYAxis(max: 5);
            }



            return(File(chart.GetBytes("png"), "image/png"));
        }