1+ using DataChart_Core_Overview . Models ;
2+ using Infragistics . Web . Mvc ;
3+ using Interfaces ;
4+ using Microsoft . AspNetCore . Mvc ;
5+ using Microsoft . Extensions . Logging ;
6+ using System . Collections . Generic ;
7+ using System . Diagnostics ;
8+
9+ namespace DataChart_Core_Overview . Controllers
10+ {
11+ public class HomeController : Controller
12+ {
13+ private readonly ILogger < HomeController > _logger ;
14+ private IUnitOfWork _unitOfWork ;
15+
16+ public HomeController ( ILogger < HomeController > logger , IUnitOfWork unitOfWork )
17+ {
18+ _logger = logger ;
19+ _unitOfWork = unitOfWork ;
20+ }
21+
22+ public IActionResult Index ( )
23+ {
24+ IList < DataChart > charts = new List < DataChart > ( ) ;
25+ charts . Add ( new DataChart { ID = "columnChart" , Chart = createChartModel ( "Column" ) } ) ;
26+ charts . Add ( new DataChart { ID = "PointChart" , Chart = createChartModel ( "Point" ) } ) ;
27+ charts . Add ( new DataChart { ID = "LineChart" , Chart = createChartModel ( "Line" ) } ) ;
28+ charts . Add ( new DataChart { ID = "SplineChart" , Chart = createChartModel ( "Spline" ) } ) ;
29+ charts . Add ( new DataChart { ID = "AreaChart" , Chart = createChartModel ( "Area" ) } ) ;
30+ charts . Add ( new DataChart { ID = "SplineAreaChart" , Chart = createChartModel ( "Spline Area" ) } ) ;
31+ charts . Add ( new DataChart { ID = "StepLineChart" , Chart = createChartModel ( "Step Line" ) } ) ;
32+ charts . Add ( new DataChart { ID = "StepArea" , Chart = createChartModel ( "Step Area" ) } ) ;
33+ charts . Add ( new DataChart { ID = "WaterfallChart" , Chart = createChartModel ( "Waterfall" ) } ) ;
34+
35+ return View ( charts ) ;
36+ }
37+
38+ public IActionResult Privacy ( )
39+ {
40+ return View ( ) ;
41+ }
42+
43+ private DataChartModel createChartModel ( string type )
44+ {
45+ var model = new DataChartModel ( ) ;
46+ string width = "350px" ;
47+ string height = "300px" ;
48+ model . DataSource = _unitOfWork . Categories . GetUnitsSoldByMonthForSpecificCountries ( ) ;
49+
50+ if ( type == "Column" )
51+ {
52+ width = "900px" ;
53+ height = "400px" ;
54+ model . Legend = new LegendModel { ID = "legend" } ;
55+ model . Subtitle = "How many uniter have been sold from each product category" ;
56+ model . DataSource = _unitOfWork . Categories . GetSpecificCountries ( ) ;
57+ }
58+
59+ model . Title = type == "Column" ? "Units sold by category" : type ;
60+ model . Width = width ;
61+ model . Height = height ;
62+
63+ model . Axes . Add ( new CategoryXAxisModel
64+ {
65+ Name = "xAxis" ,
66+ Title = type == "Column" ? "Product Category" : null ,
67+ Label = type == "Column" ? "Category" : "Month" ,
68+ TopMargin = 10
69+ } ) ;
70+
71+ model . Axes . Add ( new NumericYAxisModel
72+ {
73+ Name = "yAxis" ,
74+ Title = type == "Column" ? "Product Category" : null ,
75+ MaximumValue = type == "Column" ? 1900 : 300 ,
76+ RightMargin = 5
77+ } ) ;
78+
79+ model . Series . Add ( createSeries ( "USA" , "USA" , type ) ) ;
80+ model . Series . Add ( createSeries ( "Germany" , "Germany" , type ) ) ;
81+ model . Series . Add ( createSeries ( "Brazil" , "Brazil" , type ) ) ;
82+
83+ return model ;
84+ }
85+
86+ private SeriesModel createSeries ( string seriesMemberPath , string seriesName , string type )
87+ {
88+ HorizontalAnchoredCategorySeriesModel series ;
89+
90+ switch ( type )
91+ {
92+ case "Point" :
93+ series = new PointSeriesModel ( ) ;
94+ break ;
95+
96+ case "Line" :
97+ series = new LineSeriesModel ( ) ;
98+ break ;
99+
100+ case "Spline" :
101+ series = new SplineSeriesModel ( ) ;
102+ break ;
103+
104+ case "Area" :
105+ series = new AreaSeriesModel ( ) ;
106+ break ;
107+
108+ case "Spline Area" :
109+ series = new SplineAreaSeriesModel ( ) ;
110+ break ;
111+
112+ case "Step Line" :
113+ series = new StepLineSeriesModel ( ) ;
114+ break ;
115+
116+ case "Step Area" :
117+ series = new StepAreaSeriesModel ( ) ;
118+ break ;
119+
120+ case "Waterfall" :
121+ series = new WaterfallSeriesModel ( ) ;
122+ break ;
123+
124+ default :
125+ series = new ColumnSeriesModel ( ) ;
126+ break ;
127+ }
128+
129+ series . XAxis = "xAxis" ;
130+ series . YAxis = "yAxis" ;
131+ series . Name = seriesName ;
132+ series . Title = seriesName ;
133+ series . ValueMemberPath = seriesMemberPath ;
134+ series . MarkerType = type == "Point" ? MarkerType . Circle : MarkerType . None ;
135+ series . Thickness = ( type == "Column" && type == "waterfall" ) ? 1 : 3 ;
136+ series . IsTransitionInEnabled = true ;
137+ series . IsHighlightingEnabled = true ;
138+ series . ShowTooltip = true ;
139+
140+ return series ;
141+ }
142+
143+ [ ResponseCache ( Duration = 0 , Location = ResponseCacheLocation . None , NoStore = true ) ]
144+ public IActionResult Error ( )
145+ {
146+ return View ( new ErrorViewModel { RequestId = Activity . Current ? . Id ?? HttpContext . TraceIdentifier } ) ;
147+ }
148+ }
149+ }
0 commit comments