我想从图中删除指示的特定三条垂直线,除了最后一行。
public void ProcessRequest(HttpContext context)
{
try
{
string Identification = context.Request.QueryString["identification"].ToString().Trim();
DateTime BaseDate = Convert.ToDateTime(context.Request.QueryString["baseDate"]);
Guid? UserId = Guid.Parse(context.Request.QueryString["userId"]);
Guid CustomerGuid = Guid.Parse(context.Request.QueryString["customerGuid"]);
RootDataOperations root = new RootDataOperations();
int FedID = root.GetFedIDByCustomerGuid(CustomerGuid);
Chart Chart1 = new Chart();
ChartArea chartArea = new ChartArea("ChartArea1");
Chart1.ChartAreas.Add("ChartArea1");
int width = 600, height = 500;
Chart1.Width = width;
Chart1.Height = height;
Chart1.ChartAreas[0].AxisX.IsLabelAutoFit = true;
Chart1.ChartAreas[0].AxisX.LabelAutoFitMinFontSize = 10;
Chart1.ChartAreas[0].AxisX.LabelAutoFitMaxFontSize = 10;
DataTable table = new DataTable();
DataOperations data = new DataOperations(FedID, Guid.Empty);
List<UserQuarterlyTopPerformerComparison> userQuarterlyTopPerformerComparison = new List<UserQuarterlyTopPerformerComparison>();
userQuarterlyTopPerformerComparison = data.GetUserQuarterlyTopPerformerComparison(Identification, UserId.Value, BaseDate);
DataTable dt = ToDataTable<UserQuarterlyTopPerformerComparison>(userQuarterlyTopPerformerComparison);
if (dt.Rows.Count > 0)
{
Legend legend = new Legend();
legend.Docking = Docking.Top;
legend.Alignment = StringAlignment.Center;
legend.IsTextAutoFit = false;
Chart1.Legends.Add(legend);
Chart1.Legends[0].Enabled = true;
var IEtable = (dt as System.ComponentModel.IListSource).GetList();
Chart1.DataBindTable(userQuarterlyTopPerformerComparison, "Quarter");
//string userName = dt.Rows[0]["CUNAME"].ToString() + " (Current User)";
Guid currentuser = UserId.Value;
string userName = data.GetUserByID(currentuser).Name1 + " (Current User)";
string cuname = string.Empty;
int i = 0;
Dictionary<string, Color> dictionary = new Dictionary<string, Color>();
dictionary.Add(userName, System.Drawing.Color.DimGray);
List<DataRow> distinctUsers = dt.DefaultView.ToTable(true, "TU1NAME", "TU2NAME", "TU3NAME").AsEnumerable().Distinct().ToList();
int count = 0;
foreach (DataRow dr in distinctUsers)
{
Color colour = System.Drawing.Color.White;
int drCount = 0;
foreach (object oObject in dr.ItemArray)
{
if (dr[drCount].ToString() != "" && !dictionary.ContainsKey(dr[drCount].ToString()))
{
if (count == 0)
{
colour = System.Drawing.Color.Green;
}
if (count == 1)
{
colour = System.Drawing.Color.Red;
}
if (count == 2)
{
colour = System.Drawing.Color.Purple;
}
if (count == 3)
{
colour = System.Drawing.Color.RoyalBlue;
}
if (count == 4)
{
colour = System.Drawing.Color.AliceBlue;
}
if (count == 5)
{
colour = System.Drawing.Color.Azure;
}
if (count == 6)
{
colour = System.Drawing.Color.Beige;
}
if (count == 7)
{
colour = System.Drawing.Color.Chocolate;
}
if (count == 8)
{
colour = System.Drawing.Color.Coral;
}
if (count == 9)
{
colour = System.Drawing.Color.Cyan;
}
if (count == 10)
{
colour = System.Drawing.Color.DarkKhaki;
}
if (count == 11)
{
colour = System.Drawing.Color.DarkOrange;
}
dictionary.Add(dr[drCount].ToString(), colour);
count++;
}
drCount++;
}
}
Legend legend1 = null;
foreach (string key in dictionary.Keys)
{
legend1 = new Legend();
legend1.Docking = Docking.Top;
legend1.Alignment = StringAlignment.Center;
legend1.IsTextAutoFit = false;
Chart1.Legends.Add(legend1);
Chart1.Legends[1].CustomItems.Add(new LegendItem(key, dictionary[key], ""));
}
foreach (Series series in Chart1.Series)
{
series.ChartType = SeriesChartType.Bar;
Chart1.Legends[0].Enabled = false;
}
if (distinctUsers.Count >= 1)
{
Chart1.Series[0].Points[0].Color = dictionary[userName];
Chart1.Series[0].Points[0].Label = userName;
if (dt.Rows[0]["TU1NAME"].ToString() != "")
{
Chart1.Series[1].Points[0].Color = dictionary[dt.Rows[0]["TU1NAME"].ToString()];
Chart1.Series[1].Points[0].Label = dt.Rows[0]["TU1NAME"].ToString()+" (Top 1)";
}
if (dt.Rows[0]["TU2NAME"].ToString() != "")
{
Chart1.Series[2].Points[0].Color = dictionary[dt.Rows[0]["TU2NAME"].ToString()];
Chart1.Series[2].Points[0].Label = dt.Rows[0]["TU2NAME"].ToString() + " (Top 2)";
}
if (dt.Rows[0]["TU3NAME"].ToString() != "")
{
Chart1.Series[3].Points[0].Color = dictionary[dt.Rows[0]["TU3NAME"].ToString()];
Chart1.Series[3].Points[0].Label = dt.Rows[0]["TU3NAME"].ToString() + " (Top 3)";
}
if (distinctUsers.Count >= 2)
{
Chart1.Series[0].Points[1].Color = dictionary[userName];
Chart1.Series[0].Points[1].Label = userName;
if (dt.Rows[1]["TU1NAME"].ToString() != "")
{
Chart1.Series[1].Points[1].Color = dictionary[dt.Rows[1]["TU1NAME"].ToString()];
Chart1.Series[1].Points[1].Label = dt.Rows[1]["TU1NAME"].ToString() + " (Top 1)";
}
if (dt.Rows[1]["TU2NAME"].ToString() != "")
{
Chart1.Series[2].Points[1].Color = dictionary[dt.Rows[1]["TU2NAME"].ToString()];
Chart1.Series[2].Points[1].Label = dt.Rows[1]["TU2NAME"].ToString() + " (Top 2)";
}
if (dt.Rows[1]["TU3NAME"].ToString() != "")
{
Chart1.Series[3].Points[1].Color = dictionary[dt.Rows[1]["TU3NAME"].ToString()];
Chart1.Series[3].Points[1].Label = dt.Rows[1]["TU3NAME"].ToString() + " (Top 3)";
}
if (distinctUsers.Count >= 3)
{
Chart1.Series[0].Points[2].Color = dictionary[userName];
Chart1.Series[0].Points[2].Label = userName;
if (dt.Rows[2]["TU1NAME"].ToString() != "")
{
Chart1.Series[1].Points[2].Color = dictionary[dt.Rows[2]["TU1NAME"].ToString()];
Chart1.Series[1].Points[2].Label = dt.Rows[2]["TU1NAME"].ToString() + " (Top 1)";
}
if (dt.Rows[2]["TU2NAME"].ToString() != "")
{
Chart1.Series[2].Points[2].Color = dictionary[dt.Rows[2]["TU2NAME"].ToString()];
Chart1.Series[2].Points[2].Label = dt.Rows[2]["TU2NAME"].ToString() + " (Top 2)";
}
if (dt.Rows[2]["TU3NAME"].ToString() != "")
{
Chart1.Series[3].Points[2].Color = dictionary[dt.Rows[2]["TU3NAME"].ToString()];
Chart1.Series[3].Points[2].Label = dt.Rows[2]["TU3NAME"].ToString() + " (Top 3)";
}
}
}
}
string fileLoacation = HttpContext.Current.Server.MapPath("Images") + "/test.png";
int counter = 1;
while (System.IO.File.Exists(fileLoacation))
{
fileLoacation = HttpContext.Current.Server.MapPath("Images") + "/test" + counter + ".png";
counter++;
}
Chart1.SaveImage(fileLoacation, ChartImageFormat.Png);
Image img = Image.FromFile(fileLoacation);
Image _img = new Bitmap(width, height, img.PixelFormat);
Graphics g = Graphics.FromImage(_img);
g.DrawImage(img, 0, 0, width, height);
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed;
g.Dispose();
img.Dispose();
MemoryStream str = new MemoryStream();
_img = _img.GetThumbnailImage(width, height, null, IntPtr.Zero);
_img.Save(str, System.Drawing.Imaging.ImageFormat.Png);
_img.Dispose();
str.WriteTo(context.Response.OutputStream);
str.Dispose();
str.Close();
System.IO.File.Delete(fileLoacation);
context.Response.ContentType = ".png";
//string strGridVal = string.Empty;
//strGridVal = "<table border=\"1\">";
//for (int i = 0; i < dt.Rows.Count; i++)
//{
// strGridVal += "<tr><td>" + dt.Rows[i][2].ToString()+ "</td></tr>";
//}
//strGridVal += "</table>";
//context.Response.ContentType = "text/html";
//context.Response.Write(strGridVal);
//context.Response.ContentType = dt.ToString();
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex);
}
finally
{
context.Response.End();
}
}
答案 0 :(得分:2)
网格线由MajorGrid
对象的MinorGrid
和Axis
属性控制。将Enabled
属性设置为false
以禁用它们。