...">

ASP.NET 3.0 chart assistant. Images

Suppose I have an assistant:

@helper RenderChart()
{
    <div id="chart-content")" style="margin-top:15px;">
        @*Draw Graph Here*@
        @{
        var key = new Chart(width: 60, height: 40)
        .AddSeries(
            chartType: "pie",
            legend: "Rainfall",
            xValue: new[] { "Jan", "Feb", "Mar", "Apr", "May" },
            yValues: new[] { "20", "20", "40", "10", "10" })
        .Write();}                        
    </div>      
}

I call this helper in one of my parts, such as

@Helpers.RenderChart()

and then I get only the image in response and nothing more, just one image and another content.

Can anyone know how to fix this?

It looks like the .Write () method writes the image in response, but I only need to generate the image.

+3
source share
2 answers

You must display the chart using a separate action method and call this method using Url.Action inside some image source.

HomeController.cs

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult Chart()
    {
        return View();
    }
}

Chart.cshtml

@{ 
    var basicChart = new Chart(width: 600, height: 400) 
        .AddTitle("Chart Title") 
        .AddSeries( 
            name: "Employee", 
            xValue: new[] {  "Peter", "Andrew", "Julie", "Mary", "Dave" }, 
            yValues: new[] { "2", "6", "4", "5", "3" }) 
        .Write(); 
}

Index.cshtml

@{
    ViewBag.Title = "Index";
}
<h2>
    Index
</h2>
@RenderChart()

@helper RenderChart()
{
    <div id="chart-content" style="margin-top: 15px">
        <img src="@Url.Action("Chart")" alt="Chart is here"/>
    </div>
}
+1
source

You can take a look at the tutorials .

0
source

All Articles