【问题标题】:How to pass different calculated values to asp column chart label?如何将不同的计算值传递给asp柱形图标签?
【发布时间】:2019-08-11 05:05:24
【问题描述】:

我有两个整数值 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();

因此,从上面的代码中,它将循环的最后一个值重复到图表的每一列。如何将单个计算传递给标签?提前谢谢...

【问题讨论】:

    标签: c# mysql asp.net charts


    【解决方案1】:

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

    而不是这行代码:

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

    试试这个

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

    【讨论】:

    • 太棒了!您还可以访问 Series 集合中的 .LabelAngle、.LabelToolTip 和 .LabelUrl 属性。也尝试一下!
    猜你喜欢
    • 1970-01-01
    • 2014-10-28
    • 2011-12-02
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    相关资源
    最近更新 更多