Beispiel #1
1
        protected void Page_Load(object sender, EventArgs e)
        {
            webChartControl = new WebChartControl {
                Width = 640, Height = 360
            };
            this.form1.Controls.Add(webChartControl);
            DataTable seriesData = GetData();

            webChartControl.DataSource = seriesData;
            webChartControl.SeriesTemplate.SeriesDataMember   = "Year";
            webChartControl.SeriesTemplate.ArgumentDataMember = "Region";
            webChartControl.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Sales" });
            webChartControl.DataBind();
            webChartControl.SeriesTemplate.View = new SideBySideBarSeriesView();
            webChartControl.BoundDataChanged   += WebChartControl_BoundDataChanged;
        }
 public void SetData(IEnumerable <ChartData> data)
 {
     ChartData = data.ToArray();
     WebChartControl.DataSource = ChartData;
     WebChartControl.DataBind();
     AfterSetData(ChartData);
 }
    public static List <MyLegendItem> GenerateLegendItems(WebChartControl chart)
    {
        List <MyLegendItem> collection = new List <MyLegendItem>();
        Palette             p          = chart.PaletteRepository[chart.PaletteName];

        chart.DataBind();
        for (int i = 0; i < chart.Series.Count; i++)
        {
            MyLegendItem item = new MyLegendItem(chart.Series[i].Name, p[i % p.Count].Color);
            collection.Add(item);
        }
        return(collection);
    }
Beispiel #4
0
    protected void WebChartControl1_Init(object sender, EventArgs e)
    {
        WebChartControl chart = (WebChartControl)sender;
        GridViewDetailRowTemplateContainer container = chart.NamingContainer as GridViewDetailRowTemplateContainer;
        int    categoryId   = Convert.ToInt32(container.KeyValue);
        string categoryName = ASPxGridView1.GetRowValuesByKeyValue(categoryId, new string[] { "CategoryName" }).ToString();
        Series series       = new Series(categoryName, ViewType.Bar);

        series.ArgumentDataMember = "ProductName";
        series.ValueDataMembers.AddRange(new string[] { "UnitPrice" });
        chart.Series.Add(series);
        ((XYDiagram)chart.Diagram).AxisX.Label.Angle = 90;
        Session["CategoryID"] = categoryId;
        chart.DataSource      = detailDataSource.Select(DataSourceSelectArguments.Empty);
        chart.DataBind();
    }
Beispiel #5
0
        public static WebChartControl CreateChart(DataTable dt_descstats, string levels_x, string levels_legend, int width, int height)
        {
            WebChartControl WebChart = new WebChartControl();


            WebChart.DataSource       = dt_descstats;
            WebChart.SeriesDataMember = levels_legend;

            SideBySideBarSeriesView  view   = new SideBySideBarSeriesView();
            DataSourceBasedErrorBars errbar = new DataSourceBasedErrorBars("sd");

            errbar.Name = "SD";
            //errbar.NegativeErrorDataMember = "SDminus";
            //errbar.PositiveErrorDataMember = "SDplus";
            errbar.NegativeErrorDataMember = "Value_StdDev";
            errbar.PositiveErrorDataMember = "Value_StdDev";
            errbar.Direction           = ErrorBarDirection.Both;
            errbar.EndStyle            = ErrorBarEndStyle.Cap;
            errbar.Color               = Color.Black;
            errbar.LineStyle.Thickness = 1;

            view.Indicators.Add(errbar);

            //FixedValueErrorBars fixbar = new FixedValueErrorBars("fix");
            //fixbar.Name = "fix";
            //fixbar.NegativeError = 2;
            //fixbar.PositiveError = 10;
            //fixbar.Direction = ErrorBarDirection.Both;
            //fixbar.EndStyle = ErrorBarEndStyle.Cap;
            //fixbar.Color = Color.Red;
            //fixbar.LineStyle.Thickness = 3;

            //view.Indicators.Add(fixbar);

            WebChart.SeriesTemplate.ArgumentDataMember = levels_x;
            WebChart.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Value_Average" });
            WebChart.SeriesTemplate.View = view;

            WebChart.Width  = width;
            WebChart.Height = height;
            WebChart.DataBind();
            WebChart.EnableViewState = true;

            return(WebChart);
        }
Beispiel #6
0
    protected void chart_Init(object sender, EventArgs e)
    {
        WebChartControl chart = (WebChartControl)sender;
        GridViewDetailRowTemplateContainer container = chart.NamingContainer as GridViewDetailRowTemplateContainer;

        String oid         = container.KeyValue.ToString();
        String serviceName = grid.GetRowValuesByKeyValue(oid, new String[] { "ServiceName" }).ToString();
        String methodName  = grid.GetRowValuesByKeyValue(oid, new String[] { "MethodName" }).ToString();

        // Specify data members to bind the chart's series template.
        chart.SeriesDataMember                  = "Type";
        chart.SeriesTemplate.Label.Visible      = false;
        chart.SeriesTemplate.ArgumentDataMember = "DateTime";
        chart.SeriesTemplate.ArgumentScaleType  = ScaleType.DateTime;
        chart.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Value" });

        XYDiagram diagram = chart.Diagram as XYDiagram;

        diagram.AxisX.DateTimeGridAlignment = DateTimeMeasurementUnit.Second;
        diagram.AxisX.DateTimeMeasureUnit   = DateTimeMeasurementUnit.Second;
        diagram.AxisX.GridSpacing           = 1;

        diagram.AxisX.DateTimeOptions.Format       = DateTimeFormat.Custom;
        diagram.AxisX.DateTimeOptions.FormatString = "HH:mm";

        //diagram.AxisX.


        // Specify the template's series view.
        chart.SeriesTemplate.View          = new SideBySideBarSeriesView();
        chart.SeriesTemplate.Label.Visible = true;

        // Specify the template's name prefix.
        chart.SeriesNameTemplate.BeginText = "";

        // Generate a data table and bind the chart to it.
        DataView dv = CreateChartData(serviceName, methodName).DefaultView;

        dv.Sort = "DateTime asc";

        chart.DataSource = dv;
        chart.DataBind();
    }
Beispiel #7
0
        public static WebChartControl CreateHist(DataTable dt_hist, string histlevels, int width, int height)
        {
            WebChartControl WebChart = new WebChartControl();


            WebChart.DataSource       = dt_hist;
            WebChart.SeriesDataMember = "timept";

            SideBySideBarSeriesView view = new SideBySideBarSeriesView();

            WebChart.SeriesTemplate.ValueDataMembers.AddRange(new string[] { "Value_Average" });
            WebChart.SeriesTemplate.View = view;

            WebChart.Width  = width;
            WebChart.Height = height;
            WebChart.DataBind();
            WebChart.EnableViewState = true;

            return(WebChart);
        }
Beispiel #8
0
        protected void SyncWebChart_Load(object sender, EventArgs e)
        {
            DataTable       dt           = new DataTable();
            WebChartControl chartControl = (WebChartControl)sender;

            DevExpress.Web.GridViewDataItemTemplateContainer gridc = (DevExpress.Web.GridViewDataItemTemplateContainer)chartControl.Parent;
            string deviceid = DataBinder.Eval(gridc.DataItem, "DeviceID").ToString();

            dt = VSWebBL.DashboardBL.LotusTravelerHealthBLL.Ins.GetKeyUserDevices(deviceid);
            chartControl.DataSource = dt;
            chartControl.Series["MinSinceSync"].DataSource         = dt;
            chartControl.Series["MinSinceSync"].ArgumentDataMember = dt.Columns["DeviceID"].ToString();
            chartControl.Series["MinSinceSync"].ValueDataMembers.AddRange(dt.Columns["LastSyncMin"].ToString());
            chartControl.Series["MinSinceSync"].Visible = true;
            XYDiagram seriesXY = (XYDiagram)chartControl.Diagram;

            seriesXY.AxisY.Range.MinValue = minmin;
            seriesXY.AxisY.Range.MaxValue = maxmin;
            chartControl.DataBind();
        }
Beispiel #9
0
        protected void DiskWebChart_Load(object sender, EventArgs e)
        {
            DataTable       dt           = new DataTable();
            WebChartControl chartControl = (WebChartControl)sender;

            DevExpress.Web.GridViewDataItemTemplateContainer gridc = (DevExpress.Web.GridViewDataItemTemplateContainer)chartControl.Parent;
            string srvname  = DataBinder.Eval(gridc.DataItem, "ServerName").ToString();
            string diskname = DataBinder.Eval(gridc.DataItem, "DiskName").ToString();

            dt = VSWebBL.DashboardBL.DiskHealthBLL.Ins.SetGraph(srvname, diskname);
            chartControl.DataSource                   = dt;
            chartControl.Series[0].DataSource         = dt;
            chartControl.Series[0].ArgumentDataMember = dt.Columns["DiskName"].ToString();
            chartControl.Series[0].ValueDataMembers.AddRange(dt.Columns["DiskUsed"].ToString());
            chartControl.Series[0].Visible            = true;
            chartControl.Series[1].DataSource         = dt;
            chartControl.Series[1].ArgumentDataMember = dt.Columns["DiskName"].ToString();
            chartControl.Series[1].ValueDataMembers.AddRange(dt.Columns["DiskFree"].ToString());
            chartControl.Series[1].Visible = true;
            chartControl.DataBind();
        }
Beispiel #10
0
    Stream CreateChart(IEnumerable <Sales_by_Category> sales)
    {
        var cc = new WebChartControl();

        cc.Width             = Unit.Pixel(600);
        cc.Height            = Unit.Pixel(400);
        cc.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;
        var series = new DevExpress.XtraCharts.Series("Products", DevExpress.XtraCharts.ViewType.Bar);

        series.DataSource         = sales;
        series.ArgumentDataMember = "ProductName";
        series.ValueScaleType     = DevExpress.XtraCharts.ScaleType.Numerical;
        series.ValueDataMembers.AddRange(new string[] { "ProductSales" });
        cc.Series.Add(series);
        Controls.Add(cc);
        cc.DataBind();
        MemoryStream stream = new MemoryStream();

        cc.ExportToImage(stream, System.Drawing.Imaging.ImageFormat.Png);
        stream.Position = 0;
        return(stream);
    }
        protected void ASPxButton4_Click(object sender, EventArgs e)
        {
            WebChartControl WebChartControl1 = new WebChartControl();

            WebChartControl1.Series.Clear();

            WebChartControl1.DataSource = sqlDataSource;

            this.ASPxPopupControl1.Controls.Add(WebChartControl1);
            Series series1 = new Series("DESPESAS", ViewType.Bar);
            series1.ArgumentDataMember = SeriesName;
            series1.ValueDataMembers.AddRange(new string[] { SeriesData });

            WebChartControl1.Series.Add(series1);

            WebChartControl1.Legend.Visible = false;

            ((XYDiagram)WebChartControl1.Diagram).Rotated = false;
            WebChartControl1.Width = new Unit(Convert.ToInt32("750"));

            WebChartControl1.DataBind();
        }
Beispiel #12
0
        void DrawChart(DataTable data, DateTime from, DateTime to, IntervalType interval, ValueRepresentation representation)
        {
            List <Interval> _intervals = new List <Interval>();

            if (interval == IntervalType.Day || interval == IntervalType.Week)
            {
                // Day by day or week by week
                for (int i = 0; i < (to.Subtract(from).TotalDays / (int)interval); i++)
                {
                    //Response.Write(i + 1);
                    //Response.Write(":   ");
                    //Response.Write((i * (int)interval) + 1);
                    //Response.Write(" - ");
                    //Response.Write((i * (int)interval) + 1 + 7);
                    //Response.Write("   |   ");
                    //Response.Write(from.AddDays((i * (int)interval) + 1 - 1));
                    //Response.Write(" - ");
                    //Response.Write(from.AddDays((i * (int)interval) + 1 - 1));
                    //Response.Write("<br>");

                    _intervals.Add(new Interval(from.AddDays((i * (int)interval) + 1 - 1), from.AddDays((i * (int)interval) + (int)interval + 1 - 1)));
                }
            }
            if (interval == IntervalType.Month)
            {
                for (int i = 0; i < to.Month - from.Month + ((to.Year - from.Year) * 12) + 1; i++)
                {
                    //Response.Write(i + 1);
                    //Response.Write(":   ");
                    //Response.Write(new DateTime(from.Year, from.Month, 1).AddMonths(i));
                    //Response.Write(" - ");
                    //Response.Write(new DateTime(from.Year, from.Month, 1).AddMonths(i+1).AddDays(-1));
                    //Response.Write("<br>");

                    _intervals.Add(new Interval(new DateTime(from.Year, from.Month, 1).AddMonths(i), new DateTime(from.Year, from.Month, 1).AddMonths(i + 1).AddDays(-1)));
                }
            }
            //List<>

            // Draw chart here item by item in _intervals

            WebChartControl chart = new WebChartControl();

            chart.EnableViewState = false;
            ChartTitle title = new ChartTitle();

            title.Text = "pokus";
            title.Font = new System.Drawing.Font("Tahoma", 10);
            chart.Titles.Add(title);
            chart.FillStyle.FillMode = FillMode.Solid;
            Dictionary <int, Series> series = new Dictionary <int, Series>();

            //foreach (int channelId in channels)
            //{
            //    Channel channel = db.Channels.Where(c => c.ChannelId == channelId).FirstOrDefault();
            //    if (channel == null) continue;
            //    Series s = new Series(channel.ChannelName, ViewType.Line);
            //    s.ValueScaleType = ScaleType.Numerical;
            //    s.ArgumentScaleType = ScaleType.DateTime;
            //    series.Add(channelId, s);
            //}



            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CanonConnectionStringMain"].ConnectionString))
            {
                conn.Open();

                List <string> seriesNames = new List <string>();

                int k = 0;
                // Create series
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = string.Format("SELECT DISTINCT {0} FROM PivotTable WHERE DateSale >= @Start AND DateSale < @End", ddlYGroupBy.SelectedValue);
                    cmd.Parameters.Add(new SqlParameter("@Start", SqlDbType.DateTime)
                    {
                        Value = _intervals[0].Start
                    });
                    cmd.Parameters.Add(new SqlParameter("@End", SqlDbType.DateTime)
                    {
                        Value = _intervals[_intervals.Count - 1].End
                    });

                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Series s = new Series(reader[0].ToString(), ViewType.Line);
                        s.ValueScaleType    = ScaleType.Numerical;
                        s.ArgumentScaleType = ScaleType.DateTime;
                        seriesNames.Add(reader[0].ToString());
                        series.Add(k, s);
                        k++;
                    }
                    reader.Close();
                }

                // Draw series
                foreach (Interval i in _intervals)
                {
                    for (int j = 0; j < seriesNames.Count; j++)
                    {
                        using (SqlCommand command = GenerateReportCommand(i.Start, i.End, seriesNames[j]))
                        {
                            command.Connection = conn;
                            SqlDataReader dr = command.ExecuteReader();

                            while (dr.Read())
                            {
                                // Here it comes
                                //Response.Write(dr[0]);
                                //Response.Write(" - ");
                                //Response.Write(dr[1]);
                                //Response.Write("<br>");
                                if (dr[0] is DBNull)
                                {
                                    series[j].Points.Add(new SeriesPoint(i.Start, new double[] { 0 }));
                                }
                                else
                                {
                                    series[j].Points.Add(new SeriesPoint(i.Start, new double[] { Convert.ToDouble(dr[0]) }));
                                }
                            }
                            dr.Close();
                        }
                    }
                }
            }

            foreach (KeyValuePair <int, Series> serie in series)
            {
                chart.Series.Add(serie.Value);
            }
            //diagram
            DevExpress.XtraCharts.XYDiagram xyDiagram = new XYDiagram();
            xyDiagram.AxisY.Title.Font               = new System.Drawing.Font("Tahoma", 8);
            xyDiagram.AxisY.Title.Text               = "CZK";
            xyDiagram.AxisY.Label.Staggered          = false;
            xyDiagram.AxisY.Title.Visible            = true;
            xyDiagram.AxisY.Range.SideMarginsEnabled = true;
            xyDiagram.AxisY.Interlaced               = true;

            xyDiagram.AxisX.Title.Font               = new System.Drawing.Font("Tahoma", 8);
            xyDiagram.AxisX.Label.Staggered          = true;
            xyDiagram.AxisX.Range.SideMarginsEnabled = true;
            xyDiagram.AxisX.Tickmarks.MinorVisible   = false;



            xyDiagram.AxisX.Range.MinValue = from;
            xyDiagram.AxisX.Range.MaxValue = to;

            switch (interval)
            {
            case IntervalType.Day:
                xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Day;
                break;

            case IntervalType.Week:
                xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Day;
                xyDiagram.AxisX.GridSpacingAuto     = false;
                xyDiagram.AxisX.GridSpacing         = 7;
                break;

            case IntervalType.Month:
                xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Month;
                break;
            }



            //xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Month;
            xyDiagram.EnableZooming = true;

            chart.Diagram = xyDiagram;
            chart.Width   = 800;
            chart.Height  = 500;
            chart.DataBind();
            pnlGraph.Controls.Add(chart);
        }
Beispiel #13
0
        public void Bind()
        {
            List <int>         channels = this.Channels;
            List <int>         products = this.Products;
            CanonDataContext   db       = Cdb.Instance;
            List <MainMonitor> list     = CanonMainMonitor.GetValuesForChart(deStartDate.Date,
                                                                             deFinishDate.Date, channels, products);

            foreach (int productId in products)
            {
                Product product = db.Products.Where(p => p.ProductId == productId).FirstOrDefault();
                if (product == null)
                {
                    continue;
                }
                WebChartControl chart = new WebChartControl();
                chart.EnableViewState = false;
                ChartTitle title = new ChartTitle();
                title.Text = string.Format(Utilities.GetResourceString("Common", "ChartHeader"),
                                           product.ProductName, deStartDate.Date.ToString("dd.MM.yyyy"),
                                           deFinishDate.Date.ToString("dd.MM.yyyy"));
                title.Font = new System.Drawing.Font("Tahoma", 10);
                chart.Titles.Add(title);
                chart.FillStyle.FillMode = FillMode.Solid;
                Dictionary <int, Series> series = new Dictionary <int, Series>();
                Series s0 = new Series("Recommended price", ViewType.Line);
                s0.ValueScaleType    = ScaleType.Numerical;
                s0.ArgumentScaleType = ScaleType.DateTime;
                series.Add(0, s0);
                foreach (int channelId in channels)
                {
                    Channel channel = db.Channels.Where(c => c.ChannelId == channelId).FirstOrDefault();
                    if (channel == null)
                    {
                        continue;
                    }
                    Series s = new Series(channel.ChannelName, ViewType.Line);
                    s.ValueScaleType    = ScaleType.Numerical;
                    s.ArgumentScaleType = ScaleType.DateTime;
                    series.Add(channelId, s);
                }
                foreach (MainMonitor mm in list)
                {
                    if (mm.ProductId != productId)
                    {
                        continue;
                    }
                    series[mm.ChannelId].Points.Add(new SeriesPoint(mm.CalcDate, new double[] { (double)mm.ChannelPrice }));
                    series[0].Points.Add(new SeriesPoint(mm.CalcDate, new double[] { (double)mm.RecommendedPrice }));
                }
                foreach (KeyValuePair <int, Series> serie in series)
                {
                    chart.Series.Add(serie.Value);
                }
                //diagram
                DevExpress.XtraCharts.XYDiagram xyDiagram = new XYDiagram();
                xyDiagram.AxisY.Title.Font               = new System.Drawing.Font("Tahoma", 8);
                xyDiagram.AxisY.Title.Text               = "CZK";
                xyDiagram.AxisY.Label.Staggered          = false;
                xyDiagram.AxisY.Title.Visible            = true;
                xyDiagram.AxisY.Range.SideMarginsEnabled = true;
                xyDiagram.AxisY.Interlaced               = true;

                xyDiagram.AxisX.Title.Font               = new System.Drawing.Font("Tahoma", 8);
                xyDiagram.AxisX.Label.Staggered          = true;
                xyDiagram.AxisX.Range.SideMarginsEnabled = true;
                xyDiagram.AxisX.Tickmarks.MinorVisible   = false;
                chart.Diagram = xyDiagram;
                chart.Width   = 700;
                chart.Height  = 500;
                chart.DataBind();
                panelPics.Controls.Add(chart);

                this.FilesToSave.Add(this.SaveChartIntoFile(product.ProductName, chart));
            }
        }
Beispiel #14
0
        void DrawChart(DataTable data, DateTime from, DateTime to, IntervalType interval, ValueRepresentation representation, bool ajax)
        {
            List <Interval> _intervals = new List <Interval>();

            if (interval == IntervalType.Day || interval == IntervalType.Week)
            {
                // Day by day or week by week
                for (int i = 0; i < (to.Subtract(from).TotalDays / (int)interval); i++)
                {
                    _intervals.Add(new Interval(from.AddDays((i * (int)interval) + 1 - 1), from.AddDays((i * (int)interval) + (int)interval + 1 - 1)));
                }
            }
            if (interval == IntervalType.Month)
            {
                for (int i = 0; i < to.Month - from.Month + ((to.Year - from.Year) * 12) + 1; i++)
                {
                    _intervals.Add(new Interval(new DateTime(from.Year, from.Month, 1).AddMonths(i), new DateTime(from.Year, from.Month, 1).AddMonths(i + 1).AddDays(-1)));
                }
            }

            if (interval == IntervalType.Year)
            {
                for (int i = 0; i < to.Year - from.Year + 1; i++)
                {
                    _intervals.Add(new Interval(new DateTime(from.Year, from.Month, 1).AddYears(i), new DateTime(from.Year, from.Month, 1).AddYears(i + 1).AddDays(-1)));
                }
            }
            //foreach (Interval ii in _intervals)
            //{
            //    Response.Write(ii.Start);
            //    Response.Write(" - ");
            //    Response.Write(ii.End);
            //    Response.Write("<br>");
            //}

            // Draw chart here item by item in _intervals

            WebChartControl chart = new WebChartControl();

            if (!ajax)
            {
                chart.EnableViewState = false;
                ChartTitle title = new ChartTitle();
                title.Text = "Graf dle " + ddlYGroupBy.SelectedItem.Text.ToLower() + ":";
                title.Font = new System.Drawing.Font("Tahoma", 10);
                chart.Titles.Add(title);
                chart.FillStyle.FillMode = FillMode.Solid;
            }
            Dictionary <int, Series> series = new Dictionary <int, Series>();

            List <bool> seriesVisibilities = new List <bool>();

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CanonConnectionStringMain"].ConnectionString))
            {
                conn.Open();

                List <string> seriesNames    = new List <string>();
                List <string> seriesCriteria = new List <string>();

                int k = 0;
                Culture = "cs-CZ";
                // Create series
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection = conn;

                    StringBuilder text = new StringBuilder("");

#warning extract to function
                    if (ddlYFilterType.SelectedIndex > 0)
                    {
                        if (_filerYValues.Count > 0)
                        {
                            text.Append(" AND (");
                            // Y Filter
                            int i = 0;
                            foreach (string s in _filerYValues)
                            {
                                text.Append(ddlYFilterType.SelectedValue);
                                text.Append(" = '");
                                text.Append(s);
                                text.Append("' ");
                                if (i < _filerYValues.Count - 1)
                                {
                                    text.Append("OR ");
                                }
                                i++;
                            }
                            text.Append(") ");
                        }
                    }
                    string top = "";
                    if (chbTop.Checked)
                    {
                        int tp = Convert.ToInt32(txtTop.Text);
                        if (!ajax)
                        {
                            tp += 1;
                        }
                        top = "TOP " + tp;
                    }

                    cmd.CommandText = string.Format("SELECT {2} {0}, {0} AS Value FROM PivotTable WHERE DateSale >= @Start AND DateSale < @End {1} GROUP BY {0} ORDER BY Sum(CAST(replace(TurnoverEUR, ',', '.') as Decimal)) DESC", ddlYGroupBy.SelectedValue, text, top);

                    cmd.Parameters.Add(new SqlParameter("@Start", SqlDbType.DateTime)
                    {
                        Value = _intervals[0].Start
                    });
                    cmd.Parameters.Add(new SqlParameter("@End", SqlDbType.DateTime)
                    {
                        Value = _intervals[_intervals.Count - 1].End
                    });

                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        if (ddlYGroupBy.SelectedValue == "ReselerGroupJoined")
                        {
                            seriesNames.Add(reader[1].ToString().Trim() == "" ? "NO-NAME" : reader[1].ToString());
                        }
                        else
                        {
                            seriesNames.Add(reader[1].ToString().Trim() == "" ? "(neuvedeno)" : reader[1].ToString());
                        }

                        if (!ajax)
                        {
                            Series s;
                            if (rblValueDisplayMode.SelectedValue == "2" || ddlXValueType.SelectedValue == "Data")
                            {
                                s = new Series(reader[1].ToString(), ViewType.StackedBar);
                            }
                            else
                            {
                                s = new Series(reader[1].ToString(), ViewType.Line);
                            }
                            s.ValueScaleType = ScaleType.Numerical;
                            if (ddlXValueType.SelectedValue == "Time")
                            {
                                s.ArgumentScaleType = ScaleType.DateTime;
                            }
                            if (ddlXValueType.SelectedValue == "Data")
                            {
                                s.ArgumentScaleType = ScaleType.Qualitative;
                            }

                            if (ddlYValueType.SelectedValue == "4")
                            {
                                if (rblValueDisplayMode.SelectedValue != "2")
                                {
                                    s.PointOptions.ValueNumericOptions.Format = NumericFormat.Currency;
                                }
                                if (rblValueDisplayMode.SelectedValue == "2")
                                {
                                    s.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
                                }
                            }
                            //s.PointOptions.ValueNumericOptions.Format = NumericFormat.Currency;
                            seriesCriteria.Add(reader[0].ToString());
                            seriesVisibilities.Add(false);
                            series.Add(k, s);
                            k++;
                        }
                    }
                    reader.Close();
                }

                // Draw series
                // By Time

                // Enumerate series here and send them via ajax
                if (ajax)
                {
                    lbYHaving.Items.Clear();
                    lbYHaving.Items.Add(allValues);
                    foreach (string s in seriesNames)
                    {
                        lbYHaving.Items.Add(s);
                    }
                    DataBind(lbYHaving);

                    return;
                }

                if (ddlXValueType.SelectedValue == "Time")
                {
                    foreach (Interval i in _intervals)
                    {
                        for (int j = 0; j < seriesNames.Count; j++)
                        {
                            using (SqlCommand command = GenerateReportCommand(i.Start, i.End, seriesCriteria[j]))
                            {
                                command.Connection = conn;
                                SqlDataReader dr = command.ExecuteReader();

                                while (dr.Read())
                                {
                                    // Here it comes
                                    if (dr[0] is DBNull)
                                    {
                                        series[j].Points.Add(new SeriesPoint(i.Start, new double[] { 0 }));
                                    }
                                    else
                                    {
                                        series[j].Points.Add(new SeriesPoint(i.Start, new double[] { Convert.ToDouble(dr[0]) }));
                                        seriesVisibilities[j] = true;
                                    }
                                }
                                dr.Close();
                            }
                        }
                    }
                }
                if (ddlXValueType.SelectedValue == "Data")
                {
                    using (SqlCommand command_data = new SqlCommand())
                    {
                        command_data.Connection  = conn;
                        command_data.CommandText = "SELECT DISTINCT " + ddlXGroupByData.SelectedValue + " FROM PivotTable WHERE DateSale >= @Start AND DateSale < @End";
                        command_data.Parameters.Add(new SqlParameter("@Start", SqlDbType.DateTime)
                        {
                            Value = _intervals[0].Start
                        });
                        command_data.Parameters.Add(new SqlParameter("@End", SqlDbType.DateTime)
                        {
                            Value = _intervals[_intervals.Count - 1].End
                        });

                        SqlDataReader reader = command_data.ExecuteReader();
                        List <string> xData  = new List <string>();

                        while (reader.Read())
                        {
                            xData.Add(reader[0].ToString());
                        }
                        reader.Close();

                        foreach (string xd in xData)
                        {
                            for (int j = 0; j < seriesNames.Count; j++)
                            {
                                using (SqlCommand command = GenerateReportCommandByData(xd, seriesCriteria[j]))
                                {
                                    command.Connection = conn;
                                    SqlDataReader dr = command.ExecuteReader();

                                    while (dr.Read())
                                    {
                                        // Here it comes
                                        if (dr[0] is DBNull)
                                        {
                                            series[j].Points.Add(new SeriesPoint(xd, new double[] { 0 }));
                                        }
                                        else
                                        {
                                            series[j].Points.Add(new SeriesPoint(xd, new double[] { Convert.ToDouble(dr[0]) }));
                                            seriesVisibilities[j] = true;
                                        }
                                    }
                                    dr.Close();
                                }
                            }
                        }
                    }
                }
            }

            int    l       = 0;
            object yHaving = Request[lbYHaving.ClientID.Replace('_', '$')];


            if (yHaving == null)
            {
                yHaving = allValues;
            }

            lbYHaving.Items.Clear();

            if (yHaving.ToString() != allValues)
            {
                {
                    for (int i = 0; i < series.Count; i++)
                    {
                        if (seriesVisibilities[i])
                        {
                            lbYHaving.Items.Add(series[i].Name);
                            foreach (string s in yHaving.ToString().Split(','))
                            {
                                if (s == series[i].Name)
                                {
                                    lbYHaving.Items[l].Selected = true;
                                    seriesVisibilities[i]       = true;
                                    break;
                                }
                                else
                                {
                                    seriesVisibilities[i] = false;
                                }
                            }
                            l++;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < series.Count; i++)
                {
                    if (seriesVisibilities[i] && yHaving.ToString() != allValues)
                    {
                        lbYHaving.Items.Add(series[i].Name);
                    }
                }
            }

            lbYHaving.Items.Insert(0, allValues);
            if (yHaving.ToString() == allValues)
            {
                lbYHaving.Items[0].Selected = true;
            }

            // Other
            for (int i = 0; i < series.Count; i++)
            {
                if (seriesVisibilities[i])
                {
                    if (seriesVisibilities[i] && yHaving.ToString() == allValues)
                    {
                        lbYHaving.Items.Add(series[i].Name);
                    }
                    chart.Series.Add(series[i]);
                }
            }

            #region Compute sum

            Series suma = new Series("Suma", ViewType.Line);
            suma.ValueScaleType    = ScaleType.Numerical;
            suma.ArgumentScaleType = ScaleType.DateTime;
            if (ddlYValueType.SelectedValue == "4")
            {
                if (rblValueDisplayMode.SelectedValue != "2")
                {
                    suma.PointOptions.ValueNumericOptions.Format = NumericFormat.Currency;
                }
                if (rblValueDisplayMode.SelectedValue == "2")
                {
                    suma.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
                }
            }


            DataTable grid          = new DataTable();
            string    xArgumentName = ddlXValueType.SelectedItem.Text + " - dle ";

            if (ddlXValueType.SelectedValue == "Time")
            {
                xArgumentName += ddlXGroupByTime.SelectedItem.Text.ToLower();
            }
            else
            {
                xArgumentName += ddlXGroupByData.SelectedItem.Text.ToLower();
            }

            grid.Columns.Add(new DataColumn(xArgumentName));
            for (int i = 0; i < chart.Series.Count; i++)
            {
                grid.Columns.Add(new DataColumn(chart.Series[i].Name));
            }

            double sum;
            for (int j = 0; j < chart.Series[0].Points.Count; j++)
            {
                sum = 0;
                DataRow dr = grid.NewRow();
                if (ddlXValueType.SelectedValue == "Time")
                {
                    dr[0] = Convert.ToDateTime(chart.Series[0].Points[j].Argument).ToString("dd.MM.yyyy");
                }
                else
                {
                    dr[0] = chart.Series[0].Points[j].Argument;
                }
                for (int i = 0; i < chart.Series.Count; i++)
                {
                    dr[i + 1] = chart.Series[i].Points[j].Values[0];
                    sum      += chart.Series[i].Points[j].Values[0];
                }
                grid.Rows.Add(dr);
                suma.Points.Add(new SeriesPoint(chart.Series[0].Points[j].Argument, new double[] { sum }));

                // Percent
                if (rblValueDisplayMode.SelectedValue == "2")
                {
                    for (int i = 0; i < chart.Series.Count; i++)
                    {
                        if (sum == 0)
                        {
                            chart.Series[i].Points[j].Values[0] = 0;
                        }
                        else
                        {
                            chart.Series[i].Points[j].Values[0] = Math.Round(((chart.Series[i].Points[j].Values[0] / sum) * 1), 2);
                        }
                    }
                }

                if (rblValueDisplayMode.SelectedValue == "3")
                {
                    if (j > 0)
                    {
                        for (int i = 0; i < chart.Series.Count; i++)
                        {
                            chart.Series[i].Points[j].Values[0] = chart.Series[i].Points[j].Values[0] - chart.Series[i].Points[j - 1].Values[0];
                        }
                    }
                    else
                    {
                        for (int i = 0; i < chart.Series.Count; i++)
                        {
                            chart.Series[i].Points[j].Values[0] = 0;
                        }
                    }
                }
            }
            suma.View.Color = System.Drawing.Color.Black;
            series.Add(series.Count, suma);
            if (rblValueDisplayMode.SelectedValue == "1")
            {
                chart.Series.Add(series[series.Count - 1]);
            }

            if (chbShowSum.Checked && rblValueDisplayMode.SelectedValue == "1" && ddlXValueType.SelectedValue == "Time")
            {
                int toBeRemoved = chart.Series.Count - 1;
                for (int j = 0; j < toBeRemoved; j++)
                {
                    chart.Series.RemoveAt(0);
                }
            }

            // Show grid

            DataRow drSum = grid.NewRow();
            for (int i = 1; i < grid.Columns.Count; i++)
            {
                double dSum = 0;
                for (int j = 0; j < grid.Rows.Count; j++)
                {
                    dSum += Convert.ToDouble(grid.Rows[j][i]);
                }
                drSum[i] = dSum;
            }
            grid.Columns.Add(new DataColumn("Součet za svislou osu"));
            for (int i = 0; i < grid.Rows.Count; i++)
            {
                double dSum = 0;
                for (int j = 1; j < grid.Columns.Count - 1; j++)
                {
                    dSum += Convert.ToDouble(grid.Rows[i][j] == null ? "0" : grid.Rows[i][j]);
                }
                if (rblValueDisplayMode.SelectedValue == "2")
                {
                    for (int j = 1; j < grid.Columns.Count - 1; j++)
                    {
                        if (dSum == 0)
                        {
                            grid.Rows[i][j] = "0";
                        }
                        else
                        {
                            grid.Rows[i][j] = (Math.Round(Convert.ToDouble(grid.Rows[i][j] == null ? "0" : grid.Rows[i][j]) / dSum, 4) * 100).ToString() + " %";
                        }
                    }
                }
                grid.Rows[i][grid.Columns[grid.Columns.Count - 1]] = dSum;
            }
            grid.Rows.Add(drSum);
            grid.Rows[grid.Rows.Count - 1][0] = "Součet za vodorovnou osu";
            gvGrid.DataSource = grid;
            gvGrid.DataBind();

            #endregion

            #region Customize chart

            DevExpress.XtraCharts.XYDiagram xyDiagram = new XYDiagram();

            if (ddlYValueType.SelectedIndex == 0)
            {
                xyDiagram.AxisY.Title.Text = "EUR";
            }
            if (ddlYValueType.SelectedIndex == 1)
            {
                xyDiagram.AxisY.Title.Text = "Kusů";
            }

            xyDiagram.AxisY.Title.Font               = new System.Drawing.Font("Tahoma", 8);
            xyDiagram.AxisY.Label.Staggered          = false;
            xyDiagram.AxisY.Title.Visible            = true;
            xyDiagram.AxisY.Range.SideMarginsEnabled = true;
            xyDiagram.AxisY.Interlaced               = true;

            xyDiagram.AxisX.Title.Font               = new System.Drawing.Font("Tahoma", 8);
            xyDiagram.AxisX.Label.Staggered          = true;
            xyDiagram.AxisX.Range.SideMarginsEnabled = true;
            xyDiagram.AxisX.Tickmarks.MinorVisible   = false;

            xyDiagram.AxisX.Range.MinValue = from;
            xyDiagram.AxisX.Range.MaxValue = to;

            switch (interval)
            {
            case IntervalType.Day:
                xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Day;
                break;

            case IntervalType.Week:
                xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Day;
                xyDiagram.AxisX.GridSpacingAuto     = false;
                xyDiagram.AxisX.GridSpacing         = 7;
                break;

            case IntervalType.Month:
                xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Month;
                break;

            case IntervalType.Year:
                xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Year;
                break;
            }
            xyDiagram.EnableZooming = true;

            chart.Diagram = xyDiagram;
            chart.Width   = Convert.ToInt32(txtScreenWidth.Text) - 50;
            chart.Height  = 602;
            //chart.Height = Convert.ToInt32(txtScreenHeight.Text) - 230;

            #endregion

            chart.DataBind();
            pnlGraph.Controls.Add(chart);
        }
Beispiel #15
0
        public void Bind()
        {
            List<int> channels = this.Channels;
            List<int> products = this.Products;
            CanonDataContext db = Cdb.Instance;
            List<MainMonitor> list = CanonMainMonitor.GetValuesForChart(deStartDate.Date,
                                               deFinishDate.Date, channels, products);
            foreach (int productId in products)
            {
                Product product = db.Products.Where(p => p.ProductId == productId).FirstOrDefault();
                if (product == null) continue;
                WebChartControl chart = new WebChartControl();
                chart.EnableViewState = false;
                ChartTitle title = new ChartTitle();
                title.Text = string.Format(Utilities.GetResourceString("Common", "ChartHeader"),
                                           product.ProductName, deStartDate.Date.ToString("dd.MM.yyyy"),
                                           deFinishDate.Date.ToString("dd.MM.yyyy"));
                title.Font = new System.Drawing.Font("Tahoma", 10);
                chart.Titles.Add(title);
                chart.FillStyle.FillMode = FillMode.Solid;
                Dictionary<int, Series> series = new Dictionary<int, Series>();
                Series s0 = new Series("Recommended price", ViewType.Line);
                s0.ValueScaleType = ScaleType.Numerical;
                s0.ArgumentScaleType = ScaleType.DateTime;
                series.Add(0, s0);
                foreach (int channelId in channels)
                {
                    Channel channel = db.Channels.Where(c=> c.ChannelId==channelId).FirstOrDefault();
                    if (channel == null) continue;
                    Series s = new Series(channel.ChannelName, ViewType.Line);
                    s.ValueScaleType = ScaleType.Numerical;
                    s.ArgumentScaleType = ScaleType.DateTime;
                    series.Add(channelId, s);
                }
                foreach (MainMonitor mm in list)
                {
                    if (mm.ProductId != productId) continue;
                    series[mm.ChannelId].Points.Add(new SeriesPoint(mm.CalcDate, new double[] { (double)mm.ChannelPrice }));
                    series[0].Points.Add(new SeriesPoint(mm.CalcDate, new double[] { (double)mm.RecommendedPrice }));
                }
                foreach (KeyValuePair<int, Series> serie in series)
                    chart.Series.Add(serie.Value);
                //diagram
                DevExpress.XtraCharts.XYDiagram xyDiagram = new XYDiagram();
                xyDiagram.AxisY.Title.Font = new System.Drawing.Font("Tahoma", 8);
                xyDiagram.AxisY.Title.Text = "CZK";
                xyDiagram.AxisY.Label.Staggered = false;
                xyDiagram.AxisY.Title.Visible = true;
                xyDiagram.AxisY.Range.SideMarginsEnabled = true;
                xyDiagram.AxisY.Interlaced = true;

                xyDiagram.AxisX.Title.Font = new System.Drawing.Font("Tahoma", 8);
                xyDiagram.AxisX.Label.Staggered = true;
                xyDiagram.AxisX.Range.SideMarginsEnabled = true;
                xyDiagram.AxisX.Tickmarks.MinorVisible = false;
                chart.Diagram = xyDiagram;
                chart.Width = 700;
                chart.Height = 500;
                chart.DataBind();
                panelPics.Controls.Add(chart);

                this.FilesToSave.Add(this.SaveChartIntoFile(product.ProductName, chart));
            }
        }
Beispiel #16
0
        void DrawChart(DataTable data, DateTime from, DateTime to, IntervalType interval, ValueRepresentation representation)
        {
            List<Interval> _intervals = new List<Interval>();

            if (interval == IntervalType.Day || interval == IntervalType.Week)
            {
                // Day by day or week by week
                for (int i = 0; i < (to.Subtract(from).TotalDays / (int)interval); i++)
                {
                    //Response.Write(i + 1);
                    //Response.Write(":   ");
                    //Response.Write((i * (int)interval) + 1);
                    //Response.Write(" - ");
                    //Response.Write((i * (int)interval) + 1 + 7);
                    //Response.Write("   |   ");
                    //Response.Write(from.AddDays((i * (int)interval) + 1 - 1));
                    //Response.Write(" - ");
                    //Response.Write(from.AddDays((i * (int)interval) + 1 - 1));
                    //Response.Write("<br>");

                    _intervals.Add(new Interval(from.AddDays((i * (int)interval) + 1 - 1), from.AddDays((i * (int)interval) + (int)interval + 1 - 1)));

                }
            }
            if (interval == IntervalType.Month)
            {
                for (int i = 0; i < to.Month - from.Month + ((to.Year - from.Year) * 12) + 1; i++)
                {
                    //Response.Write(i + 1);
                    //Response.Write(":   ");
                    //Response.Write(new DateTime(from.Year, from.Month, 1).AddMonths(i));
                    //Response.Write(" - ");
                    //Response.Write(new DateTime(from.Year, from.Month, 1).AddMonths(i+1).AddDays(-1));
                    //Response.Write("<br>");

                    _intervals.Add(new Interval(new DateTime(from.Year, from.Month, 1).AddMonths(i), new DateTime(from.Year, from.Month, 1).AddMonths(i + 1).AddDays(-1)));
                }
            }
            //List<>

            // Draw chart here item by item in _intervals

            WebChartControl chart = new WebChartControl();
            chart.EnableViewState = false;
            ChartTitle title = new ChartTitle();
            title.Text = "pokus";
            title.Font = new System.Drawing.Font("Tahoma", 10);
            chart.Titles.Add(title);
            chart.FillStyle.FillMode = FillMode.Solid;
            Dictionary<int, Series> series = new Dictionary<int, Series>();

            //foreach (int channelId in channels)
            //{
            //    Channel channel = db.Channels.Where(c => c.ChannelId == channelId).FirstOrDefault();
            //    if (channel == null) continue;
            //    Series s = new Series(channel.ChannelName, ViewType.Line);
            //    s.ValueScaleType = ScaleType.Numerical;
            //    s.ArgumentScaleType = ScaleType.DateTime;
            //    series.Add(channelId, s);
            //}

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CanonConnectionStringMain"].ConnectionString))
            {
                conn.Open();

                List<string> seriesNames = new List<string>();

                int k = 0;
                // Create series
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection = conn;
                    cmd.CommandText = string.Format("SELECT DISTINCT {0} FROM PivotTable WHERE DateSale >= @Start AND DateSale < @End", ddlYGroupBy.SelectedValue);
                    cmd.Parameters.Add(new SqlParameter("@Start", SqlDbType.DateTime) { Value = _intervals[0].Start });
                    cmd.Parameters.Add(new SqlParameter("@End", SqlDbType.DateTime) { Value = _intervals[_intervals.Count - 1].End });

                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        Series s = new Series(reader[0].ToString(), ViewType.Line);
                        s.ValueScaleType = ScaleType.Numerical;
                        s.ArgumentScaleType = ScaleType.DateTime;
                        seriesNames.Add(reader[0].ToString());
                        series.Add(k, s);
                        k++;
                    }
                    reader.Close();
                }

                // Draw series
                foreach (Interval i in _intervals)
                {
                    for (int j = 0; j < seriesNames.Count; j++ )
                    {
                        using (SqlCommand command = GenerateReportCommand(i.Start, i.End, seriesNames[j]))
                        {
                            command.Connection = conn;
                            SqlDataReader dr = command.ExecuteReader();

                            while (dr.Read())
                            {
                                // Here it comes
                                //Response.Write(dr[0]);
                                //Response.Write(" - ");
                                //Response.Write(dr[1]);
                                //Response.Write("<br>");
                                if (dr[0] is DBNull)
                                {
                                    series[j].Points.Add(new SeriesPoint(i.Start, new double[] { 0 }));
                                }
                                else
                                {
                                    series[j].Points.Add(new SeriesPoint(i.Start, new double[] { Convert.ToDouble(dr[0]) }));
                                }
                            }
                            dr.Close();
                        }
                    }
                }
            }

            foreach (KeyValuePair<int, Series> serie in series)
                chart.Series.Add(serie.Value);
            //diagram
            DevExpress.XtraCharts.XYDiagram xyDiagram = new XYDiagram();
            xyDiagram.AxisY.Title.Font = new System.Drawing.Font("Tahoma", 8);
            xyDiagram.AxisY.Title.Text = "CZK";
            xyDiagram.AxisY.Label.Staggered = false;
            xyDiagram.AxisY.Title.Visible = true;
            xyDiagram.AxisY.Range.SideMarginsEnabled = true;
            xyDiagram.AxisY.Interlaced = true;

            xyDiagram.AxisX.Title.Font = new System.Drawing.Font("Tahoma", 8);
            xyDiagram.AxisX.Label.Staggered = true;
            xyDiagram.AxisX.Range.SideMarginsEnabled = true;
            xyDiagram.AxisX.Tickmarks.MinorVisible = false;

            xyDiagram.AxisX.Range.MinValue = from;
            xyDiagram.AxisX.Range.MaxValue = to;

            switch (interval)
            {
                case IntervalType.Day:
                    xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Day;
                    break;
                case IntervalType.Week:
                    xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Day;
                    xyDiagram.AxisX.GridSpacingAuto = false;
                    xyDiagram.AxisX.GridSpacing = 7;
                    break;
                case IntervalType.Month:
                    xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Month;
                    break;
            }

            //xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Month;
            xyDiagram.EnableZooming = true;

            chart.Diagram = xyDiagram;
            chart.Width = 800;
            chart.Height = 500;
            chart.DataBind();
            pnlGraph.Controls.Add(chart);
        }
Beispiel #17
0
        void DrawChart(DataTable data, DateTime from, DateTime to, IntervalType interval, ValueRepresentation representation, bool ajax)
        {
            List<Interval> _intervals = new List<Interval>();

                if (interval == IntervalType.Day || interval == IntervalType.Week)
                {
                    // Day by day or week by week
                    for (int i = 0; i < (to.Subtract(from).TotalDays / (int)interval); i++)
                    {
                        _intervals.Add(new Interval(from.AddDays((i * (int)interval) + 1 - 1), from.AddDays((i * (int)interval) + (int)interval + 1 - 1)));

                    }
                }
                if (interval == IntervalType.Month)
                {
                    for (int i = 0; i < to.Month - from.Month + ((to.Year - from.Year) * 12) + 1; i++)
                    {
                        _intervals.Add(new Interval(new DateTime(from.Year, from.Month, 1).AddMonths(i), new DateTime(from.Year, from.Month, 1).AddMonths(i + 1).AddDays(-1)));
                    }
                }

                if (interval == IntervalType.Year)
                {
                    for (int i = 0; i < to.Year - from.Year + 1; i++)
                    {
                        _intervals.Add(new Interval(new DateTime(from.Year, from.Month, 1).AddYears(i), new DateTime(from.Year, from.Month, 1).AddYears(i + 1).AddDays(-1)));
                    }
                }
            //foreach (Interval ii in _intervals)
            //{
            //    Response.Write(ii.Start);
            //    Response.Write(" - ");
            //    Response.Write(ii.End);
            //    Response.Write("<br>");
            //}

            // Draw chart here item by item in _intervals

            WebChartControl chart = new WebChartControl();

            if (!ajax)
            {
                chart.EnableViewState = false;
                ChartTitle title = new ChartTitle();
                title.Text = "Graf dle " + ddlYGroupBy.SelectedItem.Text.ToLower() + ":";
                title.Font = new System.Drawing.Font("Tahoma", 10);
                chart.Titles.Add(title);
                chart.FillStyle.FillMode = FillMode.Solid;
            }
            Dictionary<int, Series> series = new Dictionary<int, Series>();

            List<bool> seriesVisibilities = new List<bool>();
            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CanonConnectionStringMain"].ConnectionString))
            {
                conn.Open();

                List<string> seriesNames = new List<string>();
                List<string> seriesCriteria = new List<string>();

                int k = 0;
                Culture = "cs-CZ";
                // Create series
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection = conn;

                    StringBuilder text = new StringBuilder("");

            #warning extract to function
                    if (ddlYFilterType.SelectedIndex > 0)
                    {
                        if (_filerYValues.Count > 0)
                        {
                            text.Append(" AND (");
                            // Y Filter
                            int i = 0;
                            foreach (string s in _filerYValues)
                            {
                                text.Append(ddlYFilterType.SelectedValue);
                                text.Append(" = '");
                                text.Append(s);
                                text.Append("' ");
                                if (i < _filerYValues.Count - 1)
                                {
                                    text.Append("OR ");
                                }
                                i++;
                            }
                            text.Append(") ");
                        }
                    }
                    string top = "";
                    if (chbTop.Checked)
                    {
                        int tp = Convert.ToInt32(txtTop.Text);
                        if (!ajax)
                        {
                            tp += 1;
                        }
                        top = "TOP " + tp;
                    }

                    cmd.CommandText = string.Format("SELECT {2} {0}, {0} AS Value FROM PivotTable WHERE DateSale >= @Start AND DateSale < @End {1} GROUP BY {0} ORDER BY Sum(CAST(replace(TurnoverEUR, ',', '.') as Decimal)) DESC", ddlYGroupBy.SelectedValue, text, top);

                    cmd.Parameters.Add(new SqlParameter("@Start", SqlDbType.DateTime) { Value = _intervals[0].Start });
                    cmd.Parameters.Add(new SqlParameter("@End", SqlDbType.DateTime) { Value = _intervals[_intervals.Count - 1].End });

                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        if (ddlYGroupBy.SelectedValue == "ReselerGroupJoined")
                        {
                            seriesNames.Add(reader[1].ToString().Trim() == "" ? "NO-NAME" : reader[1].ToString());
                        }
                        else
                        {
                            seriesNames.Add(reader[1].ToString().Trim() == "" ? "(neuvedeno)" : reader[1].ToString());
                        }

                        if (!ajax)
                        {
                            Series s;
                            if (rblValueDisplayMode.SelectedValue == "2" || ddlXValueType.SelectedValue == "Data")
                            {
                                s = new Series(reader[1].ToString(), ViewType.StackedBar);
                            }
                            else
                            {
                                s = new Series(reader[1].ToString(), ViewType.Line);
                            }
                            s.ValueScaleType = ScaleType.Numerical;
                            if (ddlXValueType.SelectedValue == "Time")
                            {
                                s.ArgumentScaleType = ScaleType.DateTime;
                            }
                            if (ddlXValueType.SelectedValue == "Data")
                            {
                                s.ArgumentScaleType = ScaleType.Qualitative;
                            }

                            if (ddlYValueType.SelectedValue == "4")
                            {
                                if (rblValueDisplayMode.SelectedValue != "2")
                                {
                                    s.PointOptions.ValueNumericOptions.Format = NumericFormat.Currency;
                                }
                                if (rblValueDisplayMode.SelectedValue == "2")
                                {
                                    s.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
                                }
                            }
                            //s.PointOptions.ValueNumericOptions.Format = NumericFormat.Currency;
                            seriesCriteria.Add(reader[0].ToString());
                            seriesVisibilities.Add(false);
                            series.Add(k, s);
                            k++;
                        }
                    }
                    reader.Close();
                }

                // Draw series
                // By Time

                // Enumerate series here and send them via ajax
                if (ajax)
                {
                    lbYHaving.Items.Clear();
                    lbYHaving.Items.Add(allValues);
                    foreach (string s in seriesNames)
                    {
                        lbYHaving.Items.Add(s);
                    }
                    DataBind(lbYHaving);

                    return;
                }

                if (ddlXValueType.SelectedValue == "Time")
                {
                    foreach (Interval i in _intervals)
                    {
                        for (int j = 0; j < seriesNames.Count; j++)
                        {
                            using (SqlCommand command = GenerateReportCommand(i.Start, i.End, seriesCriteria[j]))
                            {
                                command.Connection = conn;
                                SqlDataReader dr = command.ExecuteReader();

                                while (dr.Read())
                                {
                                    // Here it comes
                                    if (dr[0] is DBNull)
                                    {
                                        series[j].Points.Add(new SeriesPoint(i.Start, new double[] { 0 }));
                                    }
                                    else
                                    {
                                        series[j].Points.Add(new SeriesPoint(i.Start, new double[] { Convert.ToDouble(dr[0]) }));
                                        seriesVisibilities[j] = true;
                                    }
                                }
                                dr.Close();
                            }
                        }
                    }
                }
                if (ddlXValueType.SelectedValue == "Data")
                {
                    using (SqlCommand command_data = new SqlCommand())
                    {
                        command_data.Connection = conn;
                        command_data.CommandText = "SELECT DISTINCT " + ddlXGroupByData.SelectedValue + " FROM PivotTable WHERE DateSale >= @Start AND DateSale < @End";
                        command_data.Parameters.Add(new SqlParameter("@Start", SqlDbType.DateTime) { Value = _intervals[0].Start });
                        command_data.Parameters.Add(new SqlParameter("@End", SqlDbType.DateTime) { Value = _intervals[_intervals.Count - 1].End });

                        SqlDataReader reader = command_data.ExecuteReader();
                        List<string> xData = new List<string>();

                        while (reader.Read())
                        {
                            xData.Add(reader[0].ToString());
                        }
                        reader.Close();

                        foreach(string xd in xData)
                        {
                            for (int j = 0; j < seriesNames.Count; j++)
                            {
                                using (SqlCommand command = GenerateReportCommandByData(xd, seriesCriteria[j]))
                                {
                                    command.Connection = conn;
                                    SqlDataReader dr = command.ExecuteReader();

                                    while (dr.Read())
                                    {
                                        // Here it comes
                                        if (dr[0] is DBNull)
                                        {
                                            series[j].Points.Add(new SeriesPoint(xd, new double[] { 0 }));
                                        }
                                        else
                                        {
                                            series[j].Points.Add(new SeriesPoint(xd, new double[] { Convert.ToDouble(dr[0]) }));
                                            seriesVisibilities[j] = true;
                                        }
                                    }
                                    dr.Close();
                                }
                            }
                        }
                    }
                }
            }

            int l = 0;
            object yHaving = Request[lbYHaving.ClientID.Replace('_', '$')];

            if (yHaving == null)
            {
                yHaving = allValues;
            }

            lbYHaving.Items.Clear();

            if (yHaving.ToString() != allValues)
            {
                {
                    for (int i = 0; i < series.Count; i++)
                    {
                        if (seriesVisibilities[i])
                        {
                            lbYHaving.Items.Add(series[i].Name);
                            foreach (string s in yHaving.ToString().Split(','))
                            {
                                if (s == series[i].Name)
                                {
                                    lbYHaving.Items[l].Selected = true;
                                    seriesVisibilities[i] = true;
                                    break;
                                }
                                else
                                {
                                    seriesVisibilities[i] = false;
                                }
                            }
                            l++;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < series.Count; i++)
                {
                    if (seriesVisibilities[i] && yHaving.ToString() != allValues)
                    {
                        lbYHaving.Items.Add(series[i].Name);
                    }
                }
            }

            lbYHaving.Items.Insert(0, allValues);
            if (yHaving.ToString() == allValues)
            {
                lbYHaving.Items[0].Selected = true;
            }

            // Other
            for (int i = 0; i < series.Count; i++)
            {
                if (seriesVisibilities[i])
                {

                    if (seriesVisibilities[i] && yHaving.ToString() == allValues)
                    {
                        lbYHaving.Items.Add(series[i].Name);
                    }
                    chart.Series.Add(series[i]);
                }
            }

            #region Compute sum

            Series suma = new Series("Suma", ViewType.Line);
            suma.ValueScaleType = ScaleType.Numerical;
            suma.ArgumentScaleType = ScaleType.DateTime;
            if (ddlYValueType.SelectedValue == "4")
            {
                if (rblValueDisplayMode.SelectedValue != "2")
                {
                    suma.PointOptions.ValueNumericOptions.Format = NumericFormat.Currency;
                }
                if (rblValueDisplayMode.SelectedValue == "2")
                {
                    suma.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
                }
            }

            DataTable grid = new DataTable();
            string xArgumentName = ddlXValueType.SelectedItem.Text + " - dle ";

            if (ddlXValueType.SelectedValue == "Time")
            {
                xArgumentName += ddlXGroupByTime.SelectedItem.Text.ToLower();
            }
            else
            {
                xArgumentName += ddlXGroupByData.SelectedItem.Text.ToLower();
            }

            grid.Columns.Add(new DataColumn(xArgumentName));
            for (int i = 0; i < chart.Series.Count; i++)
            {
                grid.Columns.Add(new DataColumn(chart.Series[i].Name));
            }

            double sum;
            for (int j = 0; j < chart.Series[0].Points.Count; j++)
            {
                sum = 0;
                DataRow dr = grid.NewRow();
                if (ddlXValueType.SelectedValue == "Time")
                {
                    dr[0] = Convert.ToDateTime(chart.Series[0].Points[j].Argument).ToString("dd.MM.yyyy");
                }
                else
                {
                    dr[0] = chart.Series[0].Points[j].Argument;
                }
                for (int i = 0; i < chart.Series.Count; i++)
                {
                    dr[i+1] = chart.Series[i].Points[j].Values[0];
                    sum += chart.Series[i].Points[j].Values[0];
                }
                grid.Rows.Add(dr);
                suma.Points.Add(new SeriesPoint(chart.Series[0].Points[j].Argument, new double[] { sum }));

                // Percent
                if (rblValueDisplayMode.SelectedValue == "2")
                {
                    for (int i = 0; i < chart.Series.Count; i++)
                    {
                        if (sum == 0)
                        {
                            chart.Series[i].Points[j].Values[0] = 0;
                        }
                        else
                        {
                            chart.Series[i].Points[j].Values[0] = Math.Round(((chart.Series[i].Points[j].Values[0] / sum) * 1), 2);
                        }
                    }
                }

                if (rblValueDisplayMode.SelectedValue == "3")
                {
                    if (j > 0)
                    {
                        for (int i = 0; i < chart.Series.Count; i++)
                        {
                            chart.Series[i].Points[j].Values[0] = chart.Series[i].Points[j].Values[0] - chart.Series[i].Points[j - 1].Values[0];
                        }
                    }
                    else
                    {
                        for (int i = 0; i < chart.Series.Count; i++)
                        {
                            chart.Series[i].Points[j].Values[0] = 0;
                        }
                    }

                }
            }
            suma.View.Color = System.Drawing.Color.Black;
            series.Add(series.Count, suma);
            if (rblValueDisplayMode.SelectedValue == "1")
            {
                chart.Series.Add(series[series.Count - 1]);
            }

            if (chbShowSum.Checked && rblValueDisplayMode.SelectedValue == "1" && ddlXValueType.SelectedValue == "Time")
            {
                int toBeRemoved = chart.Series.Count - 1;
                for (int j = 0; j < toBeRemoved; j++)
                {
                    chart.Series.RemoveAt(0);
                }
            }

            // Show grid

            DataRow drSum = grid.NewRow();
            for(int i = 1; i < grid.Columns.Count; i++)
            {
                double dSum = 0;
                for (int j = 0; j < grid.Rows.Count; j++)
                {
                    dSum += Convert.ToDouble(grid.Rows[j][i]);
                }
                drSum[i] = dSum;
            }
            grid.Columns.Add(new DataColumn("Součet za svislou osu"));
            for (int i = 0; i < grid.Rows.Count; i++)
            {
                double dSum = 0;
                for (int j = 1; j < grid.Columns.Count - 1; j++)
                {
                    dSum += Convert.ToDouble(grid.Rows[i][j] == null ? "0" : grid.Rows[i][j]);
                }
                if (rblValueDisplayMode.SelectedValue == "2")
                {
                    for (int j = 1; j < grid.Columns.Count - 1; j++)
                    {
                        if (dSum == 0)
                        {
                            grid.Rows[i][j] = "0";
                        }
                        else
                        {
                            grid.Rows[i][j] = (Math.Round(Convert.ToDouble(grid.Rows[i][j] == null ? "0" : grid.Rows[i][j]) / dSum, 4) * 100).ToString() + " %";
                        }
                    }
                }
                grid.Rows[i][grid.Columns[grid.Columns.Count-1]] = dSum;
            }
            grid.Rows.Add(drSum);
            grid.Rows[grid.Rows.Count - 1][0] = "Součet za vodorovnou osu";
            gvGrid.DataSource = grid;
            gvGrid.DataBind();

            #endregion

            #region Customize chart

            DevExpress.XtraCharts.XYDiagram xyDiagram = new XYDiagram();

            if (ddlYValueType.SelectedIndex == 0)
            {
                xyDiagram.AxisY.Title.Text = "EUR";
            }
            if (ddlYValueType.SelectedIndex == 1)
            {
                xyDiagram.AxisY.Title.Text = "Kusů";
            }

            xyDiagram.AxisY.Title.Font = new System.Drawing.Font("Tahoma", 8);
            xyDiagram.AxisY.Label.Staggered = false;
            xyDiagram.AxisY.Title.Visible = true;
            xyDiagram.AxisY.Range.SideMarginsEnabled = true;
            xyDiagram.AxisY.Interlaced = true;

            xyDiagram.AxisX.Title.Font = new System.Drawing.Font("Tahoma", 8);
            xyDiagram.AxisX.Label.Staggered = true;
            xyDiagram.AxisX.Range.SideMarginsEnabled = true;
            xyDiagram.AxisX.Tickmarks.MinorVisible = false;

            xyDiagram.AxisX.Range.MinValue = from;
            xyDiagram.AxisX.Range.MaxValue = to;

            switch (interval)
            {
                case IntervalType.Day:
                    xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Day;
                    break;
                case IntervalType.Week:
                    xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Day;
                    xyDiagram.AxisX.GridSpacingAuto = false;
                    xyDiagram.AxisX.GridSpacing = 7;
                    break;
                case IntervalType.Month:
                    xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Month;
                    break;
                case IntervalType.Year:
                    xyDiagram.AxisX.DateTimeMeasureUnit = DateTimeMeasurementUnit.Year;
                    break;
            }
            xyDiagram.EnableZooming = true;

            chart.Diagram = xyDiagram;
            chart.Width = Convert.ToInt32(txtScreenWidth.Text) - 50;
            chart.Height = 602;
            //chart.Height = Convert.ToInt32(txtScreenHeight.Text) - 230;

            #endregion

            chart.DataBind();
            pnlGraph.Controls.Add(chart);
        }