Beispiel #1
0
        protected void btPesquisar_OnClick(object sender, EventArgs e)
        {
            string sErro = string.Empty;

            string sWhere = " DATAVENCIMENTO BETWEEN CONVERT(CHAR(10),'" + DateTime.Parse(txtDataDe.Text).ToString("yyyyMMdd") + "', 101) AND CONVERT(CHAR(10),'" + DateTime.Parse(txtDataAte.Text).ToString("yyyyMMdd") + "', 101)";

            List<AccountPayable> listContas = new AccountPayableDAO(IdUserSession).FindByWhere(sWhere, out sErro);
            ChartPointCollection pCollection = new ChartPointCollection();

            Dictionary<string, decimal> listTopCategorias = new Dictionary<string, decimal>();
            decimal dValorTotal = 0;
            foreach (AccountPayable pConta in listContas)
            {
                if (listTopCategorias.ContainsKey(pConta.CategoryDescription))
                {
                    listTopCategorias[pConta.CategoryDescription] += pConta.TotalPrice;
                }
                else
                {
                    listTopCategorias.Add(pConta.CategoryDescription, pConta.TotalPrice);
                }

                dValorTotal += pConta.TotalPrice;
            }

            var list = listTopCategorias.OrderBy(p => p.Value);
            foreach (KeyValuePair<string, decimal> pConta in list)
            {
                ChartPoint p = new ChartPoint();
                p.Text = pConta.Key;
                decimal dPercentual = (pConta.Value * 100) / dValorTotal;
                p.Y = Double.Parse(ValorComFormatacao(dPercentual, 2).ToString());

                pCollection.Add(p);
            }

            ChartSeriesSettings c = new ChartSeriesSettings();
            c.Data = pCollection;

            PieChart.Type = ChartType.Pie;
            PieChart.Series.Add(c);
        }
Beispiel #2
0
        protected void btPesquisarColuna_OnClick(object sender, EventArgs e)
        {
            string sErro = string.Empty;

            string sWhere = " DATAVENCIMENTO BETWEEN CONVERT(CHAR(10),'" + DateTime.Parse("01/01/" + ddlYear.SelectedValue).ToString("yyyyMMdd") + "', 101) AND CONVERT(CHAR(10),'" +
                DateTime.Parse("31/12/" + ddlYear.SelectedValue).ToString("yyyyMMdd") + "', 101)";

            List<AccountPayable> listContas = new AccountPayableDAO(IdUserSession).FindByWhere(sWhere, out sErro);

            DataTable dtAno = CreateTableYear();
            Dictionary<string, decimal> listTopCategorias = new Dictionary<string, decimal>();

            //Preenchendo o DataTable com as informações
            foreach (AccountPayable pConta in listContas)
            {
                string sCategoriaDescricao = pConta.CategoryDescription;

                if (ddlType.SelectedValue.Equals("Total"))
                {
                    sCategoriaDescricao = "Total";//QualMes(pConta.DataVencimento.Month, true);

                }

                DataRow[] dr = dtAno.Select("CATEGORIA = '" + sCategoriaDescricao + "'");
                string sMesIndex = WichMonth(pConta.MaturityDate.Month);
                //Verificar se na tabela já existe a categoria
                if (dr != null && dr.Length > 0)
                {
                    int iIndex = int.Parse(dr[0]["INDEX"].ToString());
                    //Se existir verifica qual é o Mês desta conta e preenche a tabela referente ao mes
                    dtAno.Rows[iIndex][sMesIndex] =
                        Decimal.Parse(dtAno.Rows[iIndex][sMesIndex].ToString()) + pConta.TotalPrice;
                }
                else
                {
                    DataRow dr1 = dtAno.NewRow();
                    dr1["CATEGORIA"] = sCategoriaDescricao;
                    dr1[sMesIndex] = pConta.TotalPrice;
                    dtAno.Rows.Add(dr1);

                    for (int i = 0; i < dtAno.Rows.Count; i++)
                    {
                        dtAno.Rows[i]["INDEX"] = i;
                    }
                }
            }

            foreach (DataRow pLinha in dtAno.Rows)
            {
                ChartPointCollection pCollection = new ChartPointCollection();
                for (int i = 1; i < 13; i++)
                {
                    ChartPoint p = new ChartPoint();
                    p.Y = Double.Parse(pLinha[WichMonth(i)].ToString());
                    pCollection.Add(p);
                }

                ChartSeriesSettings c = new ChartSeriesSettings();
                c.Data = pCollection;
                c.Name = pLinha["CATEGORIA"].ToString();

                ColumnChart.Series.Add(c);
            }
        }
        protected void InitColumnsChart()
        {
            if (m_mChartStyle.ToString().Trim().Length == 0)
                return;
            else
            {
                if (m_mDataSource == null || m_mDataSource.Rows.Count == 0)
                {
                    return;
                }
                //移除之前设置
                DataChart.XAxis.RemoveRange(0, DataChart.XAxis.Count);
                DataChart.YAxis.RemoveRange(0, DataChart.YAxis.Count);
                DataChart.Series.RemoveRange(0, DataChart.Series.Count);
                //图表设置
                ChartXAxisSettings cxs = new ChartXAxisSettings();//实例化X轴
                ChartSeriesSettings css = new ChartSeriesSettings();//实例化数据集
                css.DataLabels.Enabled = true;
                css.DataLabels.Rotation = -90;
                css.DataLabels.Color = "#FFFFFF";
                css.DataLabels.Align = ChartHorizontalAlign.Right;
                css.DataLabels.Formatter = "formatSeriesLabel";//设置鼠标放在图形时显示的数据
                css.DataLabels.X = -3;
                css.DataLabels.Y = 10;
                switch (m_mChartStyle)
                {
                    case ChartType.Column: { css.Type = ChartType.Column; } break;
                    case ChartType.Pie: { css.Type = ChartType.Pie; } break;
                    default:
                        break;
                }
                foreach (DataRow dr in m_mDataSource.Rows)
                {

                    AxisCategory ac = new AxisCategory();
                    ac.Text = dr[m_mXAxis].ToString();
                    cxs.Categories.Add(ac);//添加X轴数据
                    ChartPoint cp = new ChartPoint();
                    cp.Y = Convert.ToDouble(dr[m_mChartPoint].ToString());
                    css.Data.Add(cp);//添加X轴数据对应的Y轴数据
                }

                ChartYAxisSettings cys = new ChartYAxisSettings();
                cxs.Title.Text = m_mXAxisText;
                cys.Title.Text = m_mYAxisText;
                DataChart.Title.Text = "各公司报文流量统计表";
                cys.Min = 0;
                DataChart.Legend.Enabled = false;//不显示图例
                DataChart.YAxis.Add(cys);
                DataChart.Series.Add(css);
                DataChart.XAxis.Add(cxs);
                upp_chart.Update();
            }
        }