I want to use Chart in my MVC Dashboard form.
I have used following code.
@{
var key = new Chart(width: 300, height: 300)
.AddTitle("Employee Chart")
.AddSeries(
chartType: "Bubble",
name: "Employee",
xValue: new[] { "Peter", "Andrew", "Julie", "Dave" },
yValues: new[] { "2", "7", "5", "3" });
}
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<div>
@key.Write()
</div>
</div>
</body>
</html>
but @key.Write()
writes chart in whole page but I want it in partial form not in whole form with other content in Dashboard page.
Can anybody help me for this.
Move your chart code to controller action like this:
public ActionResult GetChartImage()
{
var key = new Chart(width: 300, height: 300)
.AddTitle("Employee Chart")
.AddSeries(
chartType: "Bubble",
name: "Employee",
xValue: new[] { "Peter", "Andrew", "Julie", "Dave" },
yValues: new[] { "2", "7", "5", "3" });
return File(key.ToWebImage().GetBytes(), "image/jpeg");
}
(include using System.Web.Helpers namespace) and modify your view:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<div>
<img src="@Url.Action("GetChartImage")" />
</div>
</div>
</body>
</html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With