我的答案和解決方案(與解釋工作):
這適合MVC 4和MVC 3 .NET 4框架,並添加引用System.Web.DataVisualization.dll而不是.net System.Web.Helpers,DataVisualization.dll可以在 http://www.codeproject.com/Articles/125230/ASP-NET-MVC-Chart-Control
ChartApplication->外部參考
有DataVisualization的圖表的更多信息可以在那裏找到。
沒關係,它可以被替換爲:
public ActionResult Chart()
{
Chart chart = new Chart();
chart.ChartAreas.Add(new ChartArea());
chart.Series.Add(new Series("Data"));
chart.Legends.Add(new Legend("Stores"));
chart.Series["Data"].ChartType = SeriesChartType.Spline;
chart.Series["Data"].Points.AddXY(1.0, 5.0);
chart.Series["Data"].Points.AddXY(2.0, 9.0);
/*
chart.Series["Data"]["PieLabelStyle"] = "Outside";
chart.Series["Data"]["PieLineColor"] = "Black";
*/
/*
int ptIdx = chart.Series["Data"].Points.AddXY(1.0, 5.0);
DataPoint pt = chart.Series["Data"].Points[ptIdx];
pt.LegendText = "#VALX: #VALY";
pt.LegendUrl = "/Contact/Details/Hey";
*/
/*
chart.Series["Data"].Label = "#PERCENT{P0}";
chart.Series["Data"].Font = new Font("Segoe UI", 8.0f, FontStyle.Bold);
chart.Series["Data"].ChartType = SeriesChartType.Pie;
chart.Series["Data"]["PieLabelStyle"] = "Outside";
chart.Series["Data"].Legend = "Stores";
chart.Legends["Stores"].Docking = Docking.Bottom;
*/
var returnStream = new MemoryStream();
chart.ImageType = ChartImageType.Png;
chart.SaveImage(returnStream);
returnStream.Position = 0;
return new FileStreamResult(returnStream, "image/png");
}
或(對於MVC 4和MVC 3在.NET 4和System.Web.Helpers):
public ActionResult Chart()
{
var bytes = new Chart(600, 300).AddSeries(
chartType: "pie",
legend: "Sales in Store per Payment Collected",
xValue: new[] { "Jan", "Feb", "Mar", "Apr", "May" },
yValues: new[] { "20", "20", "40", "10", "10" }
)
.Write("png");
return null;
}
的和當然你需要在兩者中都加入.cshtml以下內容:
<img src="/Home/Chart" alt="" />
你也可以通過結合客戶端和服務器端來實現那個鏡像。拖放圖表控件,使用html和css進行定位。設置Series CustomProperties =「PieLineColor = Black,PieLabelStyle = Outside」,根據需要自定義Points,然後通過調用「Chart.Series [0] .Points [0] .SetValueY(value )'來設置每個餅圖片的值和'Chart1.Series [0] .Points [0] .Label = value'來設置外部標籤文本。不知道你如何分開餡餅。也許玩xAxis – Jcorretjer