ASP.NET网页(Razor)的饼图百分比

时间:2022-12-03 16:55:41

I am new in ASP.NET Web Pages (Razor). I follow this Tutorial for creating a Pie Chart. so I use this code

我是ASP.NET网页(Razor)的新手。我按照本教程创建饼图。所以我使用这段代码

@{   var myChart = new Chart(width: 500, height: 400, theme: ChartTheme.Green)
    .AddTitle("Pourcentage des réservations par catégorie")
    .AddSeries(
           name: "Ressources réservées",
           chartType: "Pie",
           xValue: new[] { "Hebergement", "Repas", "Espace", "Service", "Produit" },
           yValues: new[] { temp2, temp3, temp4, temp5, temp6 })
    .Write();
}

My Pie chart is created, but I don't know how to show percentages and values.

我的饼图已创建,但我不知道如何显示百分比和值。

1 个解决方案

#1


0  

I dont know much about creating chart in Razor View page but this could help you where I create chart in controller's action method

我不太了解在Razor View页面中创建图表,但这可以帮助您在控制器的操作方法中创建图表

  public ActionResult GetPieChart()
    {
        Chart chart = new Chart();
        chart.ChartAreas.Add(new ChartArea());

        chart.Series.Add(new Series("Data"));
        chart.Series["Data"].ChartType = SeriesChartType.Pie;            
        double[] yValues = { 71.15, 23.19, 5.66 };
        string[] xValues = { "LABLE1", "LABLE2", "LABLE3" };

        chart.Series["Data"].Points.DataBindXY(xValues,yValues);
        chart.Series[0].Label = "#VALX #PERCENT{P0}"; // THIS IS TO GET THE PERCENTAGE
        //Other chart formatting and data source omitted.

        MemoryStream ms = new MemoryStream();
        chart.SaveImage(ms, ChartImageFormat.Png);
        return File(ms.ToArray(), "image/png");
    }

#1


0  

I dont know much about creating chart in Razor View page but this could help you where I create chart in controller's action method

我不太了解在Razor View页面中创建图表,但这可以帮助您在控制器的操作方法中创建图表

  public ActionResult GetPieChart()
    {
        Chart chart = new Chart();
        chart.ChartAreas.Add(new ChartArea());

        chart.Series.Add(new Series("Data"));
        chart.Series["Data"].ChartType = SeriesChartType.Pie;            
        double[] yValues = { 71.15, 23.19, 5.66 };
        string[] xValues = { "LABLE1", "LABLE2", "LABLE3" };

        chart.Series["Data"].Points.DataBindXY(xValues,yValues);
        chart.Series[0].Label = "#VALX #PERCENT{P0}"; // THIS IS TO GET THE PERCENTAGE
        //Other chart formatting and data source omitted.

        MemoryStream ms = new MemoryStream();
        chart.SaveImage(ms, ChartImageFormat.Png);
        return File(ms.ToArray(), "image/png");
    }