Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6171


Ignore:
Timestamp:
05/09/11 22:42:37 (13 years ago)
Author:
mjesner
Message:

#1503 added controller for creating the image

Location:
branches/WebApplication/MVC2/HLWebOKBQueryPlugin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Controllers/ChartController.cs

    r6165 r6171  
    77using HLWebOKBQueryPlugin.Helpers;
    88using HLWebOKBQueryPlugin.OKBQueryService;
     9using System.Web.UI.DataVisualization.Charting;
     10using System.Drawing;
     11using System.IO;
    912
    1013namespace HLWebOKBQueryPlugin.Controllers {
     
    4346
    4447
     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
    45134    public ActionResult Index() {
    46135      ChartModel cm = new ChartModel();
  • branches/WebApplication/MVC2/HLWebOKBQueryPlugin/Views/Chart/BubbleChart.ascx

    r6165 r6171  
    2121
    2222
    23     <asp:Chart ID="bubbleChart" runat="server" Visible="true"  />
    24 
    25 
    26 <%
    27   if (((ChartModel)Model).Series != null) {
    28     //bubbleChart = new Chart();
    29     bubbleChart.Width = 150;
    30     bubbleChart.Height = 300;
    31     bubbleChart.Attributes.Add("align", "left");
    32     bubbleChart.Titles.Add("bubbe chart");
    33     bubbleChart.ChartAreas.Add(new ChartArea());
    34     Response.Write(((ChartModel)Model).Series.Points.Count);
    35     bubbleChart.Series.Add(((ChartModel)Model).Series);
    36     bubbleChart.Legends.Add(new Legend("DBAs"));
    37     bubbleChart.Legends[0].TableStyle = LegendTableStyle.Auto;
    38     bubbleChart.Legends[0].Docking = Docking.Bottom;
    39     bubbleChart.DataBind();
    40   }
    41 
    42 
    43 
    44   //Chart chart = new Chart();
    45   //chart.BackColor = System.Drawing.Color.Transparent;
    46   //chart.Width = Unit.Pixel(250);
    47   //chart.Height = Unit.Pixel(100);
    48 
    49   //Series series1 = new Series("Series1");
    50   //series1.ChartArea = "ca1";
    51   //series1.ChartType = SeriesChartType.Pie;
    52   //series1.Font = new System.Drawing.Font("Verdana", 8.25f, System.Drawing.FontStyle.Regular);
    53   //series1.Points.Add(new DataPoint {
    54   //  AxisLabel = "Value1", YValues = new double[] { 1, 2, 3.1 }
    55   //});
    56   //series1.Points.Add(new DataPoint {
    57   //  AxisLabel = "Value2", YValues = new double[] { 1, 2, 3.1 }
    58   //});
    59   //chart.Series.Add(series1);
    60 
    61   //ChartArea ca1 = new ChartArea("ca1");
    62   //ca1.BackColor = System.Drawing.Color.Transparent;
    63   //chart.ChartAreas.Add(ca1);
    64 
    65   //using (var ms = new System.IO.MemoryStream()) {
    66   //  chart.SaveImage(ms, ChartImageFormat.Png);
    67   //  ms.Seek(0, System.IO.SeekOrigin.Begin);
    68 
    69   //  Response.Write(new FileStreamResult(ms, "image/png"));
    70   //}
    71 
    72 
    73  %>
    74 
    75 
     23<img src="/Chart/CreateBubbleChart?<%= Model %>"  alt="" />
Note: See TracChangeset for help on using the changeset viewer.