Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Services.Hive.Statistics/3.3/App_Code/ChartHelper.cshtml @ 9643

Last change on this file since 9643 was 9643, checked in by pfleck, 11 years ago

#2063:
Added time selection for charts.
Implemented redrawing of charts using Ajax.

File size: 3.5 KB
Line 
1@* HeuristicLab
2 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
3 *
4 * This file is part of HeuristicLab.
5 *
6 * HeuristicLab is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * HeuristicLab is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
18 *@
19
20@helper AjaxDataRenderer() {
21    <script>
22        var ajaxDataRenderer = function (url, plot, options) {
23            var ret = null;
24            $.ajax({
25                async: false,
26                url: url,
27                dataType: "json",
28                success: function (data) {
29                    ret = data;
30                }
31            });
32            return ret;
33        };
34    </script>
35}
36
37@helper LineChartTime(string destinationTag, string url, string title = "",
38    double? minY = null, double? maxY = null, string axisYFormat = null) {
39       
40    <script>
41        var @(destinationTag)Plot = $.jqplot("@destinationTag", "@url", {
42            title: "@title",
43            highlighter: {
44                show: true,
45                sizeAdjust: 7.5
46            },
47            seriesDefaults: {
48                markerOptions: { show: false },
49                //fill: true
50            },
51            dataRenderer: ajaxDataRenderer,
52            axes: {
53                xaxis: {
54                    renderer: $.jqplot.DateAxisRenderer,
55                },
56                yaxis: {
57                    tickOptions: {
58                        @if (axisYFormat != null) {
59                            @:formatString: "@axisYFormat",
60                        }
61                    },
62                    @if (minY != null) {
63                        @:min: @minY,
64                    }
65                    @if (maxY != null) {
66                        @:max: @maxY,
67                    }
68                    pad: 0,
69                    autoscale: true
70                },
71            },
72            cursor: {
73                show: true,
74                showTooltip: false,
75                zoom: true,
76                looseZoom: true,
77                clickReset: false,
78                dblClickReset: false,
79                constrainZoomTo: 'x'
80            }
81        });
82       
83        @(destinationTag)Plot.replot( {resetAxes:true} );
84       
85        $('#@destinationTag').contextmenu(function() {
86            @(destinationTag)Plot.resetZoom();
87            @(destinationTag)Plot.replot( {resetAxes: true} );
88            return false;
89        });
90       
91        $(window).resize(function() {
92            @(destinationTag)Plot.replot( {resetAxes: true} );
93        });
94    </script>
95}
96
97@helper RefreshChart(string destinationTag, string url, string startDateVar, string endDateVar) {
98    @:$.ajax({url: "@(new HtmlString(url))?start=" + @startDateVar + "&end=" + @endDateVar, datatype: "json", success: function(result) {
99    @:    for (var i = 0; i < result.length; i++) {
100    @:        @(destinationTag)Plot.series[i].data = result[i];
101    @:    }
102    @:    @(destinationTag)Plot.replot( {resetAxes: true} )
103    @:}});
104}
Note: See TracBrowser for help on using the repository browser.