Basf_TCC7/HJGL/FineUIPro.Web/Controls/ChartControl.ascx.cs

156 lines
7.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.DataVisualization.Charting;
using System.Drawing;
namespace FineUIPro.Web.Controls
{
public partial class ChartControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
/// <summary>
/// 创建Chart图形
/// </summary>
/// <param name="dataSourceChart">Chart类</param>
public void CreateChart(Model.DataSourceChart dataSourceChart)
{
Chart chart1 = new Chart();
chart1.ID = "chart1";
chart1.BackColor = Color.WhiteSmoke;
chart1.ImageLocation = "~/Images/ChartPic_#SEQ(300,3)";
chart1.BorderlineDashStyle = ChartDashStyle.Solid;
chart1.Palette = ChartColorPalette.BrightPastel;
chart1.BackSecondaryColor = Color.White;
chart1.BackGradientStyle = GradientStyle.TopBottom;
chart1.BorderWidth = 2;
chart1.BorderColor = Color.FromArgb(26, 59, 105);
chart1.ImageType = ChartImageType.Png;
chart1.Width = dataSourceChart.Width;
chart1.Height = dataSourceChart.Height;
Title title = new Title();
title.Text = BLL.Funs.GetSubStr(dataSourceChart.Title,30);
title.ToolTip = dataSourceChart.Title;
title.ShadowColor = Color.FromArgb(32, 0, 0, 0);
title.Font = new Font("Trebuchet MS", 10F, FontStyle.Bold);
title.ShadowOffset = 3;
title.ForeColor = Color.FromArgb(26, 59, 105);
chart1.Titles.Add(title);
Legend legend = new Legend();
legend.Name = dataSourceChart.Title;
legend.TextWrapThreshold = 1;
legend.Docking = Docking.Right;
legend.Alignment = StringAlignment.Center;
legend.BackColor = Color.Transparent;
legend.Font = new Font(new FontFamily("Trebuchet MS"), 8);
legend.LegendStyle = LegendStyle.Column;
legend.IsEquallySpacedItems = true;
legend.IsTextAutoFit = false;
chart1.Legends.Add(legend);
ChartArea chartArea = new ChartArea();
chartArea.Name = dataSourceChart.Title;
chartArea.BackColor = Color.Transparent;
chartArea.AxisX.IsLabelAutoFit = false;
chartArea.AxisY.IsLabelAutoFit = false;
chartArea.AxisX.LabelStyle.Font = new Font("Verdana,Arial,Helvetica,sans-serif", 8F, FontStyle.Regular);
chartArea.AxisY.LabelStyle.Font = new Font("Verdana,Arial,Helvetica,sans-serif", 8F, FontStyle.Regular);
chartArea.AxisY.LineColor = Color.FromArgb(64, 64, 64, 64);
chartArea.AxisX.LineColor = Color.FromArgb(64, 64, 64, 64);
chartArea.AxisY.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64);
chartArea.AxisX.MajorGrid.LineColor = Color.FromArgb(64, 64, 64, 64);
chartArea.AxisX.Interval = 1;
chartArea.Area3DStyle.Enable3D = dataSourceChart.IsNotEnable3D;
chart1.ChartAreas.Add(chartArea);
if (dataSourceChart.ChartType == SeriesChartType.Pie)
{
foreach (Model.DataSourceTeam dataSourceTeam in dataSourceChart.DataSourceTeams)
{
this.lblTotal.Text = "累计值为:";
if (dataSourceTeam.DataPointName == "累计")
{
foreach (Model.DataSourcePoint dataSourcePoint in dataSourceTeam.DataSourcePoints)
{
this.lblTotal.Text += (dataSourcePoint.PointText + "" + dataSourcePoint.PointValue + ",");
}
if (this.lblTotal.Text != "累计值为:")
{
this.lblTotal.Text = this.lblTotal.Text.Substring(0, this.lblTotal.Text.LastIndexOf(","));
}
}
else
{
this.lblTotal.Visible = false;
chart1.Series.Add(dataSourceTeam.DataPointName);
chart1.Series[dataSourceTeam.DataPointName].ChartType = dataSourceChart.ChartType;
chart1.Series[dataSourceTeam.DataPointName].Name = dataSourceTeam.DataPointName;
chart1.Series[dataSourceTeam.DataPointName].IsValueShownAsLabel = false;
chart1.Series[dataSourceTeam.DataPointName].BorderWidth = 2;
chart1.Series[dataSourceTeam.DataPointName].Label = "#PERCENT{P1}";
chart1.Series[dataSourceTeam.DataPointName]["DrawingStyle"] = "Cylinder";
int m = 0;
foreach (Model.DataSourcePoint dataSourcePoint in dataSourceTeam.DataSourcePoints)
{
chart1.Series[dataSourceTeam.DataPointName].Points.AddXY(dataSourcePoint.PointText, dataSourcePoint.PointValue);
chart1.Series[dataSourceTeam.DataPointName].Points[m].LegendText = dataSourcePoint.PointText;
chart1.Series[dataSourceTeam.DataPointName].Points[m].ToolTip = "#VALX,#VALY";
m++;
}
}
}
}
else
{
foreach (Model.DataSourceTeam dataSourceTeam in dataSourceChart.DataSourceTeams)
{
this.lblTotal.Text = "累计值为:";
if (dataSourceTeam.DataPointName == "累计")
{
foreach (Model.DataSourcePoint dataSourcePoint in dataSourceTeam.DataSourcePoints)
{
this.lblTotal.Text += (dataSourcePoint.PointText + "" + dataSourcePoint.PointValue + ",");
}
if (this.lblTotal.Text != "累计值为:")
{
this.lblTotal.Text = this.lblTotal.Text.Substring(0, this.lblTotal.Text.LastIndexOf(","));
}
}
else
{
this.lblTotal.Visible = false;
chart1.Series.Add(dataSourceTeam.DataPointName);
chart1.Series[dataSourceTeam.DataPointName].ChartType = dataSourceChart.ChartType;
chart1.Series[dataSourceTeam.DataPointName].Name = dataSourceTeam.DataPointName;
chart1.Series[dataSourceTeam.DataPointName].IsValueShownAsLabel = false;
chart1.Series[dataSourceTeam.DataPointName].BorderWidth = 2;
chart1.Series[dataSourceTeam.DataPointName]["DrawingStyle"] = "Cylinder";
chart1.Series[dataSourceTeam.DataPointName]["RadarDrawingStyle"] = "Line";//雷达图中的图形样式为折线图(默认是区域图)
int m = 0;
foreach (Model.DataSourcePoint dataSourcePoint in dataSourceTeam.DataSourcePoints)
{
chart1.Series[dataSourceTeam.DataPointName].Points.AddXY(dataSourcePoint.PointText, dataSourcePoint.PointValue);
chart1.Series[dataSourceTeam.DataPointName].Points[m].ToolTip = "#VALX,#VALY";
m++;
}
}
}
}
Controls.Add(chart1);
}
}
}