我有两个整数值ta和thc,我正在为这两个值进行百分比计算,并将这些值传递给每列上的asp图表标签,如下面的代码所示。
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();