Nov 26, 2013, 3:54 AM
[CLOSED] Build Line Char from MVC Controller
Hi Ext.Net Team,
Below is my test code:
//Model
How can i move this method in the MVC controller i.e. in a .CS file. ?
Thanks in Advance
Below is my test code:
//Model
public class TestClass
{
public double? MeanEstimatedPrice { get; set; }
public double? MaxEstimatedPrice { get; set; }
public double? MinEstimatedPrice { get; set; }
public string CountryName { get; set; }
public static List<TestClass> GetRecords()
{
List<TestClass> list = new List<TestClass>();
list.Add(new TestClass() { MeanEstimatedPrice = 12, MaxEstimatedPrice = 12, MinEstimatedPrice = 10, CountryName = "Albania" });
list.Add(new TestClass() { MeanEstimatedPrice = 12, MaxEstimatedPrice = 12, MinEstimatedPrice = 10, CountryName = "Lativia" });
list.Add(new TestClass() { MeanEstimatedPrice = 10, MaxEstimatedPrice = 12, MinEstimatedPrice = 10, CountryName = "France" });
list.Add(new TestClass() { MeanEstimatedPrice = 16, MaxEstimatedPrice = 12, MinEstimatedPrice = 10, CountryName = "Belgium" });
return list;
}
}
//View@functions
{
string currDesc = string.Empty;
bool isAllCombined = false;
string CategoryTitle = string.Empty;
bool IsLocalCurrency = false;
string NumericAxisTitle = string.Empty;
double minValue;
bool isMonteCarlo = false;
private Store CreateStore(bool isMonteCarlo)
{
Store store = new Store();
store.ID = "StoreGSnapShot1";
var model = new Model();
model.Fields.Add(new ModelField("MeanEstimatedPrice", ModelFieldType.String));
model.Fields.Add(new ModelField("CountryName", ModelFieldType.String));
model.Fields.Add(new ModelField("PACK_CURRENCY_DESC", ModelFieldType.String));
store.Model.Add(model);
return store;
}
private void Initchart(Container pnlGrafico)
{
var result = TestClass.GetRecords();
Ext.Net.Chart chtGrafico = new Ext.Net.Chart()
{
ID = "SnapShotChart",
Animate = true,
Height = 300,
Shadow = true,
};
CategoryTitle = "Countries";
chtGrafico.LegendConfig = new ChartLegend() { Position = LegendPosition.Bottom };
var store = CreateStore(isMonteCarlo);
store.DataSource = result;
chtGrafico.Store.Add(store);
minValue = result.Min(x => x.MeanEstimatedPrice.Value);
minValue = Math.Round(minValue, 2);
var maxValue = result.Max(x => x.MeanEstimatedPrice.Value);
//if (minValue > 0.1)
minValue = 0;
string handlerTips = "";
handlerTips = " var stringValue = '" + currDesc + " '+ Ext.util.Format.number(value, '0.0000'); return stringValue;";
AxisLabel l = new AxisLabel();
l.Renderer.Handler = handlerTips;
List<string> listName = new List<string>();
NumericAxis numericAxis = new NumericAxis()
{
Fields = new[] { "MeanEstimatedPrice" },
Grid = true,
Title = "Price per UOM",
Minimum = minValue,
Label = l
};
if (maxValue < 0.1)
numericAxis.Maximum = maxValue;
chtGrafico.Axes.Add(numericAxis);
CategoryAxis categoryAxis = new CategoryAxis()
{
Fields = new string[] { "CountryName" },
Title = CategoryTitle,
Position = Position.Bottom
};
chtGrafico.Axes.Add(categoryAxis);
var series = CreateChartSeries1(result, isMonteCarlo, listName, isAllCombined);
foreach (var ser in series)
{
chtGrafico.Series.Add(ser);
}
//Add Chart Title Label as a Sprite not working
var lblChartTitle= new Sprite {Type = SpriteType.Text, Text = "My Custom Text", X = 100, Y = 200, Fill = "#000", SpriteID = "MyCustomText" };
chtGrafico.Add(lblChartTitle);
//Add Chart
pnlGrafico.Items.Add(chtGrafico);
}
private SeriesCollection CreateChartSeries1(List<TestClass> list, bool isMonteCarlo, List<String> llist, bool isAllCombined)
{
SeriesCollection absSeries = new SeriesCollection();
absSeries = new SeriesCollection();
string handler = string.Empty;
var countryList = list.Select(x => x.CountryName).ToList();
var colors = new string
[list.Count];
KnownColor[] names = (KnownColor[])Enum.GetValues(typeof(KnownColor));
for (int i = 0; i < list.Count; i++)
{
if (i <= 143)
{
KnownColor randomColorName = names[30 + i];
colors[i] = Color.FromKnownColor(randomColorName).Name;
}
else
{
KnownColor randomColorName = names[i];
colors[i] = Color.FromKnownColor(randomColorName).Name;
}
}
System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
var colorarr = js.Serialize(colors);
absSeries.Add(
Html.X().ColumnSeries()
.Axis(Position.Left)
.XField("CountryName")
.YField("MeanEstimatedPrice")
.Titles(countryList.ToArray())
.Highlight(true)
.Tips(Html.X().ChartTip()
.TrackMouse(true)
.Width(250)
.Height(28)
)
.Renderer(r => r.Handler = @"
var c= new Array();
var colorsArr =" + colorarr + @";
attributes.fill = colorsArr[index % colorsArr.length];
return attributes;")
);
return absSeries;
}
}
<div>
@(Html.X().Container()
.ID("container_SnapShot")
.Height(550)
.DefaultAnchor("100%")
.Layout(LayoutType.Fit)
.Control(item => this.Initchart(item))
)
@( Html.X().Container().ID("NodataContainer").Items())
@* //X.Label(Model.ChartTitle).ID("lblSnapShotNoData").StyleSpec("font: bold 18px Arial;").Hidden(true).Text("No data found")))*@
</div>
As you can see in the above code, the Initchart method is in the same .cshtml page.How can i move this method in the MVC controller i.e. in a .CS file. ?
Thanks in Advance
Last edited by Daniil; Nov 29, 2013 at 2:22 PM.
Reason: [CLOSED]