1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Web;
|
---|
5 | using System.Web.Mvc;
|
---|
6 | using HLWebOKBQueryPlugin.Models;
|
---|
7 | using HLWebOKBQueryPlugin.Helpers;
|
---|
8 | using HLWebOKBQueryPlugin.OKBQueryService;
|
---|
9 | using System.Web.UI.DataVisualization.Charting;
|
---|
10 | using System.Drawing;
|
---|
11 | using System.IO;
|
---|
12 |
|
---|
13 | namespace HLWebOKBQueryPlugin.Controllers {
|
---|
14 | public class ChartController : Controller {
|
---|
15 | //
|
---|
16 | // GET: /Chart/
|
---|
17 |
|
---|
18 |
|
---|
19 | public ActionResult UpdateBubbleChart(FormCollection collection) {
|
---|
20 |
|
---|
21 |
|
---|
22 | String selectedAxisX = collection.Get("valuesAxisXCombobox");
|
---|
23 | String selectedAxisY = collection.Get("valuesAxisYCombobox");
|
---|
24 | String selectedBubbleSize = collection.Get("bubbleSizeCombobox");
|
---|
25 |
|
---|
26 | Response.Write("axis x => " + selectedAxisX);
|
---|
27 | Response.Write("axis y => " + selectedAxisY);
|
---|
28 | Response.Write("size => " + selectedBubbleSize);
|
---|
29 |
|
---|
30 | ChartModel cm = new ChartModel();
|
---|
31 |
|
---|
32 | // Later, we will get the runs from the session ...
|
---|
33 | QueryServiceClient client = Query.GetClientFactory("okbtester", "okbtester");
|
---|
34 |
|
---|
35 | long[] runIds = new long[5];
|
---|
36 | for (int i = 0; i < 5; i++) {
|
---|
37 | runIds[i] = i;
|
---|
38 | }
|
---|
39 | Run[] runs = client.GetRuns(runIds, false);
|
---|
40 |
|
---|
41 | cm.UpdateRunCollection(runs);
|
---|
42 | cm.UpdateBubbleChart(selectedAxisY, selectedAxisX, selectedBubbleSize);
|
---|
43 |
|
---|
44 | return View("Index",cm);
|
---|
45 | }
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 | public FileResult CreateBubbleChart(ChartModel model)
|
---|
50 | {
|
---|
51 | IList<int> items = new List<int>();
|
---|
52 |
|
---|
53 | items.Add(1);
|
---|
54 | items.Add(2);
|
---|
55 | items.Add(5);
|
---|
56 | items.Add(10);
|
---|
57 |
|
---|
58 | Chart chart = new Chart();
|
---|
59 | chart.Width = 700;
|
---|
60 | chart.Height = 300;
|
---|
61 | chart.BackColor = Color.FromArgb(211, 223, 240);
|
---|
62 | chart.BorderlineDashStyle = ChartDashStyle.Solid;
|
---|
63 | chart.BackSecondaryColor = Color.White;
|
---|
64 | chart.BackGradientStyle = GradientStyle.TopBottom;
|
---|
65 | chart.BorderlineWidth = 1;
|
---|
66 | chart.Palette = ChartColorPalette.BrightPastel;
|
---|
67 | chart.BorderlineColor = Color.FromArgb(26, 59, 105);
|
---|
68 | chart.RenderType = RenderType.BinaryStreaming;
|
---|
69 | chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
|
---|
70 | chart.AntiAliasing = AntiAliasingStyles.All;
|
---|
71 | chart.TextAntiAliasingQuality = TextAntiAliasingQuality.Normal;
|
---|
72 | chart.Titles.Add("Bubble Chart");
|
---|
73 | //chart.Legends.Add(CreateLegend());
|
---|
74 | chart.Series.Add(CreateSeries(items,SeriesChartType.Bubble));
|
---|
75 | chart.ChartAreas.Add(CreateChartArea());
|
---|
76 |
|
---|
77 |
|
---|
78 |
|
---|
79 | MemoryStream ms = new MemoryStream();
|
---|
80 | chart.SaveImage(ms);
|
---|
81 | return File(ms.GetBuffer(), @"image/png");
|
---|
82 | }
|
---|
83 |
|
---|
84 |
|
---|
85 |
|
---|
86 | public Series CreateSeries(IList<int> results, SeriesChartType chartType)
|
---|
87 | {
|
---|
88 | Series seriesDetail = new Series();
|
---|
89 | seriesDetail.Name = "Result Chart";
|
---|
90 | seriesDetail.IsValueShownAsLabel = false;
|
---|
91 | seriesDetail.Color = Color.FromArgb(198, 99, 99);
|
---|
92 | seriesDetail.ChartType = chartType;
|
---|
93 | seriesDetail.BorderWidth = 2;
|
---|
94 | DataPoint point;
|
---|
95 |
|
---|
96 | foreach (int result in results)
|
---|
97 | {
|
---|
98 | point = new DataPoint();
|
---|
99 | point.AxisLabel = result.ToString();
|
---|
100 | point.YValues = new double[] { (double)result };
|
---|
101 | seriesDetail.Points.Add(point);
|
---|
102 | }
|
---|
103 | seriesDetail.ChartArea = "Result Chart";
|
---|
104 | return seriesDetail;
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 |
|
---|
109 | public ChartArea CreateChartArea()
|
---|
110 | {
|
---|
111 | ChartArea chartArea = new ChartArea();
|
---|
112 | chartArea.Name = "Result Chart";
|
---|
113 | chartArea.BackColor = Color.Transparent;
|
---|
114 | chartArea.AxisX.IsLabelAutoFit = false;
|
---|
115 | chartArea.AxisY.IsLabelAutoFit = false;
|
---|
116 | chartArea.AxisX.LabelStyle.Font =
|
---|
117 | new Font("Verdana,Arial,Helvetica,sans-serif",
|
---|
118 | 8F, FontStyle.Regular);
|
---|
119 | chartArea.AxisY.LabelStyle.Font =
|
---|
120 | new Font("Verdana,Arial,Helvetica,sans-serif",
|
---|
121 | 8F, FontStyle.Regular);
|
---|
122 | chartArea.AxisY.LineColor = Color.FromArgb(64, 64, 64, 64);
|
---|
123 | chartArea.AxisX.LineColor = Color.FromArgb(64, 64, 64, 64);
|
---|
124 | chartArea.AxisY.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64);
|
---|
125 | chartArea.AxisX.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64);
|
---|
126 | chartArea.AxisX.Interval = 1;
|
---|
127 |
|
---|
128 | return chartArea;
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 |
|
---|
133 |
|
---|
134 | public ActionResult Index() {
|
---|
135 | ChartModel cm = new ChartModel();
|
---|
136 |
|
---|
137 | // Later, we will get the runs from the session ...
|
---|
138 | QueryServiceClient client = Query.GetClientFactory("okbtester", "okbtester");
|
---|
139 |
|
---|
140 | long[] runIds = new long[5];
|
---|
141 | for (int i = 0; i < 5; i++) {
|
---|
142 | runIds[i] = i;
|
---|
143 | }
|
---|
144 | Run[] runs = client.GetRuns(runIds, false);
|
---|
145 |
|
---|
146 | cm.UpdateRunCollection(runs);
|
---|
147 |
|
---|
148 |
|
---|
149 | return View(cm);
|
---|
150 | }
|
---|
151 |
|
---|
152 | // [ChildActionOnly]
|
---|
153 | public ActionResult BubbleChart() {
|
---|
154 | ChartModel cm = new ChartModel();
|
---|
155 |
|
---|
156 | return PartialView("BubbleChart", cm); // name of usercontrol
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | //public ActionResult BoxPlot()
|
---|
161 | //{
|
---|
162 | // return View();
|
---|
163 | //}
|
---|
164 |
|
---|
165 | }
|
---|
166 | }
|
---|