如何将不同的计算值传递给ASP柱形图标签?

时间:2019-03-20 13:28:36

标签: 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 = 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 个答案:

答案 0 :(得分:1)

我认为您想要在系列1的要点上添加自定义标签。你能告诉我这是否有效吗?

代替以下代码:

Chart1.Series["Series1"].Label = percentCalc;

尝试一下

Chart1.Series["Series1"].Points[Chart1.Series["Series1"].Points.Count-1].Label = percentCalc.ToString();