2010-12-06 6 views
2

Ich habe eine Steuerung und es funktioniert super. Ich übergebe es einfach mal (im Millimeterformat) und dann Werte, die durchschnittliche Länge in der Zeit der Anfragen sind. Der folgende Code tut, was ich brauche - fast (fühlen Sie sich frei, es zu markieren, wenn ich über Bord bin, weil ich zu der Diagrammsteuerung neu bin).ASP.Net-Diagramm - Label mit zusätzlichen Daten, die im Diagramm nicht verwendet werden?

Meine Daten sind in Tabelle wie folgt aus:

Date by Hours 9:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00 18:00 
12/03/2010  8 43 53 55 33 46 51 60 50  9 
Friday  1.773 1.337 1.242 1.239 1.340 1.191 1.479 1.223 1.178 1.516 

gibt mir ein schönes Diagramm. Meine Frage ist, unter diesem Code:

List<double> yValues = new List<double>(); 
List<string> xValues = new List<string>(); 

// First and Last columns do not contain chartable data 
for (int i = 1; i < dtResults.Columns.Count - 1; i++) { 
    double d; 
    if (double.TryParse(dtResults.Rows[1][i].ToString(), out d)) 
     yValues.Add(d == 0 ? double.NaN : d); 
    else 
     yValues.Add(double.NaN); 
} // foreach of the Average Time Values the chart 

// foreach of the column names 
for (int i = 1; i < dtResults.Columns.Count - 1; i++) 
    xValues.Add(dtResults.Columns[i].ColumnName); 

this.Chart.Titles["Title1"].Text = string.Format(
    "Average Request Time In Seconds On {0:MM/dd/yyyy} Between {1:HH} and {2:HH} In {3}", 
    this.DateRange.BeginDate.Value, 
    this.ucsTimePicker.BeginTime, 
    this.ucsTimePicker.EndTime, 
    this.SelectedSourceEnvironmentName 
); 
this.Chart.Series["Series1"].Points.DataBindXY(xValues, yValues); 
this.Chart.Series["Series1"].ChartType = SeriesChartType.Line; 
this.Chart.Series["Series1"].IsValueShownAsLabel = true; 
this.Chart.Series["Series1"]["ShowMarkerLines"] = "true"; 
this.Chart.Series["Series1"].Label = "#VALY{0.000}"; // Make sure they have only 3 decimal places 

this.Chart.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = true; 
this.Chart.ChartAreas["ChartArea1"].AxisX.Title = "Hours of the Day"; 
this.Chart.ChartAreas["ChartArea1"].AxisY.Title = "Time in Seconds"; 

// Handle styling when there is a Zero or missing value 
this.Chart.Series["Series1"].EmptyPointStyle.Color = Color.Red; 
this.Chart.Series["Series1"].EmptyPointStyle.BorderWidth = 3; 
this.Chart.Series["Series1"].EmptyPointStyle.BorderDashStyle = ChartDashStyle.Dash; 
this.Chart.Series["Series1"].EmptyPointStyle.MarkerStyle = MarkerStyle.Diamond; 
this.Chart.Series["Series1"].EmptyPointStyle.MarkerColor = Color.Red; 
this.Chart.Series["Series1"].EmptyPointStyle.MarkerSize = 8; 
this.Chart.Series["Series1"].EmptyPointStyle.MarkerBorderColor = Color.Black; 
this.Chart.Series["Series1"]["EmptyPointValue"] = "Zero"; 

Es gibt zeigt Etiketten (die Dezimalzahlen in der Tabelle oben), aber was ich will zu tun haben das Label Auch zeigen die Gesamtzahl der Anfragen, die die zweite ist Datenzeile in der obigen Tabelle. Ich war in der Lage, die Werte zu der Tabelle mit dem Code hinzufügen unter:

for (int i = 1; i < dtResults.Columns.Count - 1; i++) { 
    int n; 
    if (int.TryParse(dtResults.Rows[0][i].ToString(), out n)) 
    this.Chart.Series["Series1"].Points.AddY(n); 
    else 
    this.Chart.Series["Series1"].Points.AddY(0); 
} // foreach of the Count of Request within the Hour values 

, die keine Anfälle zu werfen schienen, aber ich kann nicht die Werte mit der folgenden Einstellung zuzugreifen:

this.Chart.Series["Series1"].Label = "#VALY{0.000}\n#VALY2{0}"; 

Alles, was ich bekomme, ist der ursprüngliche Wert (1.773), der zweimal angezeigt wird.

Gibt es eine Möglichkeit, Daten zu einem Diagramm hinzuzufügen, das nur zu Kennzeichnungszwecken dient und dann darauf zugreift?

Antwort

1

Okay, nachdem keine Hilfe hier (was mich tatsächlich schockiert) Ich konnte es mit etwas Hilfe außerhalb dieser Website herausfinden. Im Wesentlichen, ich habe nicht die „extra“ Daten hinzufügen, aber ich habe, um jedes Etikett zu ändern im Gegensatz zu nur die generische Bezeichnung, die wie folgt aus:

this.Chart.Series["Series1"].Label = "#VALY{0.000}"; // Make sure they have only 3 decimal places  

Ich musste auch die folgende Zeile herausnehmen :

this.Chart.Series["Series1"].IsValueShownAsLabel = true; 

der Kürze halber So einfach, hier ist der gesamte Code geben mir die beiden Linien Etikett, wo die erste Linie zeigt den Mittelwert und die zweite Zeile (die die tatsächlichen Diagrammdaten ist), die die Zählung ist nicht in die Daten überhaupt.

List<double> yValues = new List<double>(); 
List<string> xValues = new List<string>(); 
List<int> zValues = new List<int>(); 

// First and Last columns do not contain chartable data 
for (int i = 1; i < dtResults.Columns.Count - 1; i++) { 
    double d; 
    if (double.TryParse(dtResults.Rows[1][i].ToString(), out d)) 
     yValues.Add(d == 0 ? double.NaN : d); 
    else 
     yValues.Add(double.NaN); 
} // foreach of the Average Time Values the chart 

// foreach of the column names 
for (int i = 1; i < dtResults.Columns.Count - 1; i++) 
    xValues.Add(dtResults.Columns[i].ColumnName); 

this.Chart.Titles["Title1"].Text = string.Format(
    "Average Request Time In Seconds On {0:MM/dd/yyyy} Between {1:HH} and {2:HH} In {3}", 
    this.DateRange.BeginDate.Value, 
    this.ucsTimePicker.BeginTime, 
    this.ucsTimePicker.EndTime, 
    this.SelectedSourceEnvironmentName 
); 
this.Chart.Series["Series1"].Points.DataBindXY(xValues, yValues); 

/// This loop will setup the point labels in a two line format where the first line displays 
/// the Average that the point is actually showing. The second line is data taken from the 
/// results table and is not a part of the chart at all but is useful information and is the 
/// Count of records in that time frame. 
/// In order for this to work, the Series property IsValueShownAsLabel needs to be NOT True. 
for (int i = 0; i < this.Chart.Series["Series1"].Points.Count; i++) { 
    int n = 0; 
    int.TryParse(dtResults.Rows[0][i + 1].ToString(), out n); 

    this.Chart.Series["Series1"].Points[i].Label = string.Format("Avg: #VALY{{0.000}}\nCount: {0}", n); 
} // foreach of the Count of Request within the Hour values 

this.Chart.Series["Series1"].ChartType = SeriesChartType.Line; 
this.Chart.Series["Series1"]["ShowMarkerLines"] = "true"; 
this.Chart.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = true; 
this.Chart.ChartAreas["ChartArea1"].AxisX.Title = "Hours of the Day"; 
this.Chart.ChartAreas["ChartArea1"].AxisY.Title = "Time in Seconds"; 

// Handle styling when there is a Zero or missing value 
this.Chart.Series["Series1"].EmptyPointStyle.Color = Color.Red; 
this.Chart.Series["Series1"].EmptyPointStyle.BorderWidth = 3; 
this.Chart.Series["Series1"].EmptyPointStyle.BorderDashStyle = ChartDashStyle.Dash; 
this.Chart.Series["Series1"].EmptyPointStyle.MarkerStyle = MarkerStyle.Diamond; 
this.Chart.Series["Series1"].EmptyPointStyle.MarkerColor = Color.Red; 
this.Chart.Series["Series1"].EmptyPointStyle.MarkerSize = 8; 
this.Chart.Series["Series1"].EmptyPointStyle.MarkerBorderColor = Color.Black; 
this.Chart.Series["Series1"]["EmptyPointValue"] = "Zero"; 
Verwandte Themen