溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

第八章 圖形化報表

發(fā)布時間:2020-07-01 04:35:22 來源:網(wǎng)絡(luò) 閱讀:284 作者:彳亍的路人 欄目:編程語言

                       第八章  圖形化報表

1.Highcharts

2.水晶報表

3.jqchart

4.MSChart:

       例如:

           

//檢索重慶市月平均氣溫
string sql = @"select DATEPART (month,dtmMeasure) as 'Month',AVG (fltTemperature ) as 'AvgTemp' from TblTemperature
        where chvCityName ='重慶' group by DATEPART (month,dtmMeasure) order by Month desc";
DataSet ds = SqlHelper.Select(CommandType.Text, sql, null);
//設(shè)置圖表背景顏色
this.Chart1.BackColor = Color.LightPink;
//設(shè)置圖表邊框樣式
this.Chart1.BorderlineColor = Color.Green;
//邊框線寬度
this.Chart1.BorderlineWidth = 5;
//圖表邊框西安為細(xì)線
this.Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
//標(biāo)題
this.Chart1.Titles.Add("重慶市月平均氣溫走勢圖");
//設(shè)置圖表X,Y軸綁定的列
this.Chart1.Series[0].XValueMember = "Month";
this.Chart1.Series[0].YValueMembers = "AvgTemp";
//設(shè)置每個數(shù)據(jù)點標(biāo)簽上顯示的值為數(shù)據(jù)點的值
this.Chart1.Series[0].IsValueShownAsLabel = true;
//設(shè)置數(shù)據(jù)點標(biāo)簽的文本格式]
this.Chart1.Series[0].LabelFormat = "{0}℃";
//綁定數(shù)據(jù)源
this.Chart1.DataSource = ds;
this.Chart1.DataBind();


       //折線圖

//檢索重慶市月平均氣溫
string sql = @"select chvCityName, DATEPART (month,dtmMeasure) as 'Month',AVG (fltTemperature )
                as 'AvgTemp' from TblTemperature
                where chvCityName ='重慶' or chvCityName ='北京'
                group by chvCityName,DATEPART (month,dtmMeasure) order by Month desc";
DataSet ds = SqlHelper.Select(CommandType.Text, sql, null);
//為圖表添加2個序列
this.Chart1.Series.Clear();
this.Chart1.Series.Add("重慶");
this.Chart1.Series.Add("北京");
//設(shè)置每一個序列的圖表類型
this.Chart1.Series["重慶"].ChartType = SeriesChartType.Line;
this.Chart1.Series["北京"].ChartType = SeriesChartType.Line;
//設(shè)置圖表背景顏色
this.Chart1.BackColor = Color.Pink;
//設(shè)置圖表邊框樣式
this.Chart1.BorderlineColor = Color.Green;
//邊框線寬度
this.Chart1.BorderlineWidth = 5;
//圖表邊框西安為細(xì)線
this.Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
//標(biāo)題
this.Chart1.Titles.Add("中國城市月平均氣溫走勢圖");
//圖例
this.Chart1.Legends.Add("");
foreach (DataRow  row in ds.Tables [0].Rows )
{
    //定義數(shù)據(jù)點
    DataPoint point = new DataPoint(Convert.ToDouble(row["Month"]), Convert.ToDouble(row["AvgTemp"]));
    //設(shè)置每個數(shù)據(jù)點在X軸的標(biāo)簽文本
    point.AxisLabel = string.Format("{0}月", row["Month"]);
    //設(shè)置每個數(shù)據(jù)點的標(biāo)簽文本
    point.Label = string.Format("{0}℃", row["AvgTemp"]);
    //設(shè)置鼠標(biāo)懸浮至數(shù)據(jù)點的提示文本
    point.LabelToolTip = string.Format("{0}月平均氣溫:{1}攝氏度", row["Month"], row["AvgTemp"]);
    this.Chart1.Series[row["chvCityName"].ToString()].Points.Add(point);
}


       //餅圖

           

//檢索重慶市月平均氣溫
string sql = @"select (case
                    when intScore<60 then '不及格'
                    when intScore<80 then '及格'
                    when intScore<90 then '良'
                    when intScore<=100 then '優(yōu)秀' end) as Grade,
                    count(*) as 'Count' from scoreinfo
                    group by(case
                    when intScore<60 then '不及格'
                    when intScore<80 then '及格'
                    when intScore<90 then '良'
                    when intScore<=100 then '優(yōu)秀' end)";
DataSet ds = SqlHelper1.Select(CommandType.Text, sql, null);
//為圖表添加序列
this.Chart1.Series.Clear();
this.Chart1.Series.Add("Score");
//設(shè)置序列的圖表類型
this.Chart1.Series["Score"].ChartType = SeriesChartType.Pie;
//設(shè)置背景顏色
this.Chart1.BackColor = Color.Pink;
//設(shè)置圖表邊框樣式
this.Chart1.BorderlineColor = Color.Purple;
this.Chart1.BorderlineWidth = 5;
this.Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
this.Chart1.Titles.Add("C#成績統(tǒng)計圖");
//文本顏色
this.Chart1.Series["Score"].LabelForeColor = Color.Gray;
//字體大小,樣式
this.Chart1.Series["Score"].Font = new Font("宋體", 14);
//計算總?cè)藬?shù)
int total = 0;
foreach (DataRow row in ds.Tables[0].Rows)
{
    total += Convert.ToInt32(row["Count"]);
}
foreach (DataRow row in ds.Tables[0].Rows)
{
    //定義數(shù)據(jù)點
    DataPoint point = new DataPoint();
    //總?cè)藬?shù)
    point.YValues = new double[] { Convert.ToDouble(row["Count"]) };
    //設(shè)置每一個數(shù)據(jù)點標(biāo)簽的文本值為百分比
    point.Label = string.Format("{0:f2}%", Convert.ToDouble(row["Count"]) / total * 100);
    //設(shè)置圖例
    this.Chart1.Legends.Add(row["Grade"].ToString());
    point.LegendText = row["Grade"].ToString();
    //將數(shù)據(jù)點添加到序列中
    this.Chart1.Series["Score"].Points.Add(point);
}
//將數(shù)據(jù)點標(biāo)簽顯示到圖示外側(cè)
Chart1.Series["Score"]["PieLabelStyle"] = "Outside";
//將第一個數(shù)據(jù)點展開
Chart1.Series["Score"].Points[0]["Exploded"] = "true";


       //柱狀圖

           

//檢索重慶市月平均氣溫
string sql = @"select (case
                    when intScore<60 then '不及格'
                    when intScore<80 then '及格'
                    when intScore<90 then '良'
                    when intScore<=100 then '優(yōu)秀' end) as Grade,
                    count(*) as 'Count' from scoreinfo
                    group by(case
                    when intScore<60 then '不及格'
                    when intScore<80 then '及格'
                    when intScore<90 then '良'
                    when intScore<=100 then '優(yōu)秀' end)";
DataSet ds = SqlHelper1.Select(CommandType.Text, sql, null);
//為圖表添加序列
this.Chart1.Series.Clear();
this.Chart1.Series.Add("Score");
//設(shè)置序列的圖表類型
this.Chart1.Series["Score"].ChartType = SeriesChartType.Column;
//設(shè)置背景顏色
this.Chart1.BackColor = Color.Pink;
//設(shè)置圖表邊框樣式
this.Chart1.BorderlineColor = Color.Purple;
this.Chart1.BorderlineWidth = 5;
this.Chart1.BorderlineDashStyle = ChartDashStyle.Solid;
this.Chart1.Titles.Add("C#成績統(tǒng)計圖");
//文本顏色
this.Chart1.Series["Score"].LabelForeColor = Color.Gray;
//字體大小,樣式
this.Chart1.Series["Score"].Font = new Font("宋體", 14);
//計算總?cè)藬?shù)
int total = 0;
foreach (DataRow row in ds.Tables[0].Rows)
{
    total += Convert.ToInt32(row["Count"]);
}
foreach (DataRow row in ds.Tables[0].Rows)
{
    //定義數(shù)據(jù)點
    DataPoint point = new DataPoint();
    //總?cè)藬?shù)
    point.YValues = new double[] { Convert.ToDouble(row["Count"]) };
    //設(shè)置每一個數(shù)據(jù)點標(biāo)簽的文本值為百分比
    point.Label = string.Format("{0}人", Convert.ToDouble(row["Count"]));
    point.AxisLabel = row["Grade"].ToString();
    //將數(shù)據(jù)點添加到序列中
    this.Chart1.Series["Score"].Points.Add(point);
    //設(shè)置數(shù)據(jù)點被點擊后的回發(fā)值,該值可以在Click事件的ImageMapEventArgs參數(shù)中獲取
    point.PostBackValue = string.Format("{0}|{1}", row["Grade"], row["Count"]);
}
//將數(shù)據(jù)點標(biāo)簽顯示到圖示外側(cè)
Chart1.Series["Score"]["PieLabelStyle"] = "Outside";
//將第一個數(shù)據(jù)點展開
Chart1.Series["Score"].Points[0]["Exploded"] = "true";


5.XtraReports

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI