Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wonder if anyone can help or point me to an example that achieves the following. I would like to use a Chart Helper in a View page that is capable of changing when the user inputs for instance the Chart Type (ie Pie, Column etc)
I can get this all to work using an MVC C# app, but I only seem to be able to get the Chart to refresh and display on its own ie not as an embedded image.

I wanted to do this without saving the chart as an image and then displaying that, but rather building the chart each time.

I need to get the following parts to work together;
I haven't included a Controller, as that the part I'm struggling with:
This is my dilemma, the Controller essentially seems to return a View. I need to pass the users choice eg "pie" to the Chart1.cshtml view but still render the entire Index view.
Any help would be greatly appreciated. Apologies for my errors below, I'm very new to this and I think its the MVC (Controller concept) I'm battling with

Chart1.cshtml

@Model chartModel

@{
var myChart = new Chart(width: 600, height: 400)
.AddTitle(Model.Title)
.AddSeries(
name: "Employee",
xValue: new[] { "Peter", "Andrew", "Julie", "Mary", "Dave" },
yValues: Model.GetyValues(),
chartType: Model.cType)
.Write();
}

Index.cshtml
...
@using (Html.BeginForm())
{

Select chart type:



<input type="text" name="chartType" value="Column/Pie/Area/Line">



<input class="button" id="submit" type="submit" value="Submit" />
}

<img src='@Url.Action("Chart1","Home")' />

Model

namespace MvcApp_chart4.Models
{
public class ChartModel
{
public string Title { get; set; }

private string _cType;
public string cType
{
get { return _cType; }
set { _cType = value; }
}


public Int32[] GetyValues()
{

Int32[] yValues = new Int32[] { 99, 98, 92, 97, 95 };
return yValues;
}
}
}

Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900