C# 如何将不同的计算值传递给asp柱形图标签?
我有两个整数值ta和thc,我正在计算这两个值的百分比,并将这些值传递给每列上的asp图表标签,如下面的代码所示C# 如何将不同的计算值传递给asp柱形图标签?,c#,mysql,asp.net,charts,C#,Mysql,Asp.net,Charts,我有两个整数值ta和thc,我正在计算这两个值的百分比,并将这些值传递给每列上的asp图表标签,如下面的代码所示 while (myread2.Read()) { while (myread.Read()) { string ta1 = myread["totalapplied"].ToString(); string thc1 = myread2["THC"].ToString(); Int32 ta =
while (myread2.Read())
{
while (myread.Read())
{
string ta1 = myread["totalapplied"].ToString();
string thc1 = myread2["THC"].ToString();
Int32 ta = Convert.ToInt32(ta1);
Int32 thc = Convert.ToInt32(thc1);
var calc = (((double)ta / (double)thc) * 100);
string percentCalc = Convert.ToString(String.Format("{0:0.00}", calc)); // I want to pass this value for each column for each read on the loop
lblcount.Text = myread["totalapplied"].ToString();
this.Chart1.Series["Series1"].Points.AddXY(myread["categ"], myread["totalapplied"]);
this.Chart1.Series["Series1"].Legend = "Leg";
Chart1.Series["Series1"].IsValueShownAsLabel = true;
Chart1.Series["Series1"].Label = percentCalc; //I need the calculated value here
Chart1.Series["Series1"].ToolTip = "Shift: #VALX \\nCount: #VALY";
Chart1.Legends.Clear();
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;
}
this.Chart1.Series["Series2"].Points.AddXY(myread2["date1"], myread2["THC"]);
this.Chart1.Series["Series2"].Legend = "Leg";
Chart1.Series["Series2"].IsValueShownAsLabel = true;
Chart1.Series["Series2"].Label = "100%";
Chart1.Series["Series2"].ToolTip = "Shift: #VALX \\nCount: #VALY";
Chart1.Legends.Clear();
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Enabled = false;
Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;
Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Angle = -45;
}
con.Close();
因此,从上面的代码中,它将循环的最后一个值重复到图表的每一列。如何将单个计算传递到标签?提前感谢…我想您需要的是为系列1的积分添加自定义标签。你能告诉我这是否有效吗 而不是这行代码:
Chart1.Series["Series1"].Label = percentCalc;
试试这个
Chart1.Series["Series1"].Points[Chart1.Series["Series1"].Points.Count-1].Label = percentCalc.ToString();
杰出的您还可以从Series集合中访问.LabelAngle、.LabelToolTip和.LabelUrl属性。也用这些做实验!