1
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Web.UI.DataVisualization.Charting;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
namespace Web.Controls
|
||||
{
|
||||
@@ -485,6 +487,166 @@ namespace Web.Controls
|
||||
Controls.Add(chart1);
|
||||
}
|
||||
|
||||
public void CreateChart1(Model.DataSourceChart dataSourceChart)
|
||||
{
|
||||
int totalDataCount = 0;
|
||||
if (dataSourceChart.DataSourceTeams != null && dataSourceChart.DataSourceTeams.Count > 0)
|
||||
{
|
||||
var firstTeam = dataSourceChart.DataSourceTeams.FirstOrDefault(t => t.DataPointName != "累计");
|
||||
if (firstTeam != null)
|
||||
totalDataCount = firstTeam.DataSourcePoints.Count;
|
||||
}
|
||||
|
||||
// 每个标签分配 70px 宽度(可微调:60-80 之间)
|
||||
int autoChartWidth = totalDataCount * 45;
|
||||
|
||||
Chart chart1 = new Chart
|
||||
{
|
||||
ID = "chart1",
|
||||
BackColor = Color.WhiteSmoke,
|
||||
ImageLocation = "~/Images/ChartPic_#SEQ(300,3)",
|
||||
BorderlineDashStyle = ChartDashStyle.Solid,
|
||||
Palette = ChartColorPalette.BrightPastel,
|
||||
BackSecondaryColor = Color.White,
|
||||
BackGradientStyle = GradientStyle.TopBottom,
|
||||
BorderWidth = 2,
|
||||
BorderColor = Color.FromArgb(26, 59, 105),
|
||||
ImageType = ChartImageType.Png,
|
||||
|
||||
Width = dataSourceChart.Width > autoChartWidth ? dataSourceChart.Width : autoChartWidth,
|
||||
Height = dataSourceChart.Height
|
||||
};
|
||||
|
||||
Title title = new Title
|
||||
{
|
||||
Text = dataSourceChart.Title,
|
||||
ShadowColor = Color.FromArgb(32, 0, 0, 0),
|
||||
Font = new Font("Trebuchet MS", 10F, FontStyle.Bold),
|
||||
ShadowOffset = 3,
|
||||
ForeColor = Color.FromArgb(26, 59, 105)
|
||||
};
|
||||
chart1.Titles.Add(title);
|
||||
|
||||
Legend legend = new Legend
|
||||
{
|
||||
Name = dataSourceChart.Title,
|
||||
TextWrapThreshold = 1,
|
||||
Docking = Docking.Top,
|
||||
Alignment = StringAlignment.Center,
|
||||
BackColor = Color.Transparent,
|
||||
Font = new Font(new FontFamily("Trebuchet MS"), 8),
|
||||
LegendStyle = LegendStyle.Row,
|
||||
IsEquallySpacedItems = true,
|
||||
IsTextAutoFit = false
|
||||
};
|
||||
chart1.Legends.Add(legend);
|
||||
|
||||
ChartArea chartArea = new ChartArea
|
||||
{
|
||||
Name = dataSourceChart.Title,
|
||||
BackColor = Color.Transparent
|
||||
};
|
||||
|
||||
chartArea.AxisX.IsLabelAutoFit = false;
|
||||
chartArea.AxisY.IsLabelAutoFit = false;
|
||||
chartArea.AxisX.Interval = 1; // 每个点都显示标签
|
||||
chartArea.AxisX.LabelStyle.Angle = 45; // 倾斜45°
|
||||
chartArea.AxisX.LabelStyle.Font = new Font("Verdana,Arial,Helvetica,sans-serif", 8F);
|
||||
chartArea.AxisY.LabelStyle.Font = new Font("Verdana,Arial,Helvetica,sans-serif", 8F);
|
||||
|
||||
// 线条样式
|
||||
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);
|
||||
|
||||
chart1.ChartAreas.Add(chartArea);
|
||||
|
||||
|
||||
Panel scrollPanel = new Panel();
|
||||
scrollPanel.Style.Add("width", "100%"); // 父容器自适应
|
||||
scrollPanel.Style.Add("overflow-x", "auto"); // 横向滚动条
|
||||
scrollPanel.Style.Add("overflow-y", "hidden");
|
||||
scrollPanel.Style.Add("margin-bottom", "10px");
|
||||
scrollPanel.Controls.Add(chart1);
|
||||
|
||||
|
||||
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 = true;
|
||||
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 + "#PERCENT{P1}";
|
||||
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 = true;
|
||||
chart1.Series[dataSourceTeam.DataPointName].BorderWidth = 2;
|
||||
chart1.Series[dataSourceTeam.DataPointName]["DrawingStyle"] = "Cylinder";
|
||||
|
||||
foreach (Model.DataSourcePoint dataSourcePoint in dataSourceTeam.DataSourcePoints)
|
||||
{
|
||||
chart1.Series[dataSourceTeam.DataPointName].Points.AddXY(dataSourcePoint.PointText,
|
||||
dataSourcePoint.PointValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Controls.Add(scrollPanel);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user