How can I make chart in view with razor? Tried to use partial view (_Chart.cshtml):
@{
var usdChart = new Chart(width: 600, height: 400)
.AddTit
With your current code, it will not render the image in the main view. Instead it render just the image. It is because when you make the partial view call, the Chart.Write
method will convert the chart object to a jpg and write to the output stream.
You should create an action method which returns this partial view result and use that as the image src
attribute value
public ActionResult Chart()
{
return PartialView("_Chart");
}
and in the main view
<img src="@Url.Action("Chart")" />
When the page loads, it will make a separate http call to the image source url which returns just the image