これはあなたを助けるかもしれません**コントローラー***
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApp.Models;
using System.Web.Helpers;
namespace MvcApp.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
public ActionResult About()
{
return View();
}
public ActionResult ChartDispaly()
{
ChartImage();
return View();
}
public void ChartImage() {
IEnumerable<Product> productList = new List<Product> {
new Product {Name = "Kayak", Category = "Watersports", Price = 275m},
new Product {Name = "Lifejacket", Category = "Watersports", Price = 48.95m},
new Product {Name = "Soccer ball", Category = "Football", Price = 19.50m},
new Product {Name = "Corner flags", Category = "Football", Price = 34.95m},
new Product {Name = "Stadium", Category = "Football", Price = 150m},
new Product {Name = "Thinking cap", Category = "Chess", Price = 16m}
};
Chart chart = new Chart(400, 200,
@"<Chart BackColor=""Gray"" BackSecondaryColor=""WhiteSmoke""
BackGradientStyle=""DiagonalRight"" AntiAliasing=""All""
BorderlineDashStyle = ""Solid"" BorderlineColor = ""Gray"">
<BorderSkin SkinStyle = ""Emboss"" />
<ChartAreas>
<ChartArea Name=""Default"" _Template_=""All"" BackColor=""Wheat""
BackSecondaryColor=""White"" BorderColor=""64, 64, 64, 64""
BorderDashStyle=""Solid"" ShadowColor=""Transparent"">
</ChartArea>
</ChartAreas>
</Chart>");
chart.AddSeries(
chartType: "Pie",
yValues: productList.Select(e => e.Price).ToArray(),
xValue: productList.Select(e => e.Name).ToArray()
);
chart.Write();
}
}
}
*モデル* ****
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcApp.Models
{
public class Product
{
public string Name { get; set; }
public string Category { get; set; }
public decimal Price { get; set; }
}
}