public void CreateLine()
{
//YearNameSeries.v
FarPoint.Web.Chart.LabelArea label = new FarPoint.Web.Chart.LabelArea();
label.Text = "项目完成趋势图";
label.Location = new System.Drawing.PointF(0.5f, 0.06f);
label.AlignmentX = 0.5f;
label.AlignmentY = 0.0f;
FarPoint.Web.Chart.LegendArea legend = new FarPoint.Web.Chart.LegendArea();
legend.Location = new System.Drawing.PointF(0.95f, 0.5f);
legend.AlignmentX = 1f;
legend.AlignmentY = 0.5f;
legend.Padding = new PaddingF(10f, 5f, 10f, 5f);
FarPoint.Web.Chart.XYPlotArea plotArea = new FarPoint.Web.Chart.XYPlotArea();
//设置显示单位为 10%
plotArea.Location = new System.Drawing.PointF(0.2f, 0.2f);
plotArea.Size = new System.Drawing.SizeF(0.6f, 0.6f);
ValueAxis yAxis = plotArea.YAxes[0];
yAxis.LabelNumberFormat = "0%";
// Y刻度自定义
yAxis.AutoMajorUnit = false;
yAxis.AutoMinorUnit = false;
yAxis.AutoMaximum = false;
yAxis.AutoMinimum = false;
// Y刻度单位
yAxis.MajorUnit = 0.1;
yAxis.MinorUnit = 0.02;
yAxis.Maximum = 1;
yAxis.Minimum = 0.0;
ValueAxis xAxis = plotArea.XAxes[0];
xAxis.AutoMajorUnit = false;
xAxis.AutoMinorUnit = false;
xAxis.AutoMaximum = false;
xAxis.AutoMinimum = false;
xAxis.MajorGridVisible = false;
xAxis.MajorUnit = 1;
xAxis.MinorUnit = 0.2;
xAxis.Maximum = 12;
xAxis.Minimum = 1;
XYLineSeries xyLineSeries = null;
XYLineSeries xyLineSeriesPlan = null;
int _top = 25;
IList<PP_ProjectPlanModel> rates = null;
IList<PP_ProjectPlanModel> items = new List<PP_ProjectPlanModel>();
if (_id == 0)
{
items = PP_ProjectPlanService.Instance.ReadToDataReader(false, Global.AppUrl, new PP_ProjectPlanQuery() { Year = _year.ConvertTo<int>(), ProjectName = _projectname, ImplementationSite = "", Month = 0, ProjectPlanCharger = "", Status = "" });
}
else
{
items.Add(PP_ProjectPlanService.Instance.GetModel(_id.ConvertTo<int>()));
}
foreach (PP_ProjectPlanModel proModel in items)
{
xyLineSeries = new XYLineSeries();
xyLineSeriesPlan = new XYLineSeries();
if (proModel.PlanStartDate != null && proModel.PlanCompletionDate != null)
{
DataTable dt = new DataTable("Plan");
DataRow dr = default(System.Data.DataRow);
dt.Columns.Add("计划时间");
dt.Columns.Add("完成度");
DateTime planstartDate = DateTime.Now;
DateTime plancompleDate = DateTime.Now;
planstartDate = proModel.PlanStartDate.ConvertTo<DateTime>();
plancompleDate = proModel.PlanCompletionDate.ConvertTo<DateTime>();
dr = dt.NewRow();
dr[0] = planstartDate.Month;
dr[1] = 0;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = plancompleDate.Month;
dr[1] = 1;
dt.Rows.Add(dr);
xyLineSeriesPlan.XValues.DataSource = dt;
xyLineSeriesPlan.XValues.DataField = dt.Columns[0].ColumnName;
xyLineSeriesPlan.YValues.DataSource = dt;
xyLineSeriesPlan.YValues.DataField = dt.Columns[1].ColumnName;
xyLineSeriesPlan.YAxisId = 0;
xyLineSeriesPlan.XAxisId = 0;
plotArea.Series.Add(xyLineSeriesPlan);
}
if (proModel.ActualStartDate != null && proModel.ActualCompletionDate != null)
{
DataTable dt2 = new DataTable("Actual");
DataRow dr2 = default(System.Data.DataRow);
dt2.Columns.Add("计划时间");
dt2.Columns.Add("完成度");
DateTime actualstartDate = DateTime.Now;
DateTime actualcompleDate = DateTime.Now;
actualstartDate = proModel.ActualStartDate.ConvertTo<DateTime>();
actualcompleDate = proModel.ActualCompletionDate.ConvertTo<DateTime>();
dr2 = dt2.NewRow();
dr2[0] = actualstartDate.Month;
dr2[1] = 0;
dt2.Rows.Add(dr2);
dr2 = dt2.NewRow();
dr2[0] = actualcompleDate.Month;
dr2[1] = 1;
dt2.Rows.Add(dr2);
xyLineSeries.XValues.DataSource = dt2;
xyLineSeries.XValues.DataField = dt2.Columns[0].ColumnName;
xyLineSeries.YValues.DataSource = dt2;
xyLineSeries.YValues.DataField = dt2.Columns[1].ColumnName;
xyLineSeries.YAxisId = 0;
xyLineSeries.XAxisId = 0;
plotArea.Series.Add(xyLineSeries);
}
_top = _top + 30;
}
xyLineSeriesPlan.SeriesName = "计划完成";
xyLineSeries.SeriesName = "实际完成";
FarPoint.Web.Chart.ChartModel model = new FarPoint.Web.Chart.ChartModel();
model.LabelAreas.Add(label);
model.LegendAreas.Add(legend);
model.PlotAreas.Add(plotArea);
SpreadChart chart = new SpreadChart();
chart.Model = model;
chart.Left = 5;
chart.Top = _top;
chart.Height = 380;
chart.Width = 760;
if (fpSpreads.ActiveSheetView.Charts.Count != 0)
{
fpSpreads.ActiveSheetView.Charts.RemoveAt(0);
}
fpSpreads.ActiveSheetView.Charts.Add(chart);
}
|
-
|