MS 甘特图 2 轴

MS Gantt Chart 2 Axis

我有这样的甘特图。我想显示 AxisX2 的值是我为它准备的公式的百分比。我在展示 AxisX2 并为其设置系列时遇到了挑战。

这是我截取的甘特图click here。 我希望多一个像 this 这样的轴。 请帮忙,谢谢。

下面是渲染该图表的一些基本函数

 public void setUpGantt(Chart chart)
    {
       chart.Series.Clear();
        Series s = chart.Series.Add("sszs");

        s.ChartType = SeriesChartType.RangeBar;
        s.YValueType = ChartValueType.DateTime;
        s.ResetIsVisibleInLegend () ;
        s.IsVisibleInLegend = true;

        Axis ax = chart.ChartAreas[0].AxisX;
        Axis ay = chart.ChartAreas[0].AxisY;
        ax.MajorGrid.Enabled = false;
  
     
        ay.IntervalType = DateTimeIntervalType.Minutes;
        ay.Interval = 60;
        ay.LabelStyle.Format = "HH:mm";

      ay.Minimum = 0;
      ay.Maximum = 0.2;
        limitGantt(chart, "0:00", "24:00");
        s.ToolTip = "#VALY1{HH:mm}~#VALY2{HH:mm}";
    }
 public void limitGantt(Chart chart, string start, string end)
    {
        Axis ax = chart.ChartAreas[0].AxisX;
        Axis ay = chart.ChartAreas[0].AxisY;
        ay.Minimum = fromTimeString(start).ToOADate();  
        ay.Maximum = fromTimeString(end).ToOADate();  
    }
DateTime fromTimeString(string time)
        {
            var p = time.Split(':');
            int sec = p.Length == 3 ? Convert.ToInt16(p[2]) : 0;
            TimeSpan t = new TimeSpan(Convert.ToInt16(p[0]), Convert.ToInt16(p[1]), sec);
            return DateTime.Today.Add(t);
        }
public void addGanttTask(Series s, string start, string end, Color c, int slot, string [] array)
        {
            DateTime start_ = fromTimeString(start);
            DateTime end_ = fromTimeString(end);
            int pt = s.Points.AddXY(slot, start_, end_);
            s.Points[pt].Color = c;
            s.IsVisibleInLegend = true;

            if (array != null)
            {
                for (int i = 0; i < array.Length; i++)
                {
                    if (slot == i + 1)
                    { s.Points[pt].AxisLabel = array[i];
                        
                    }
                }
            }

        }

Taw 的评论

 public void setUpGantt(Chart chart)
    {
       chart.Series.Clear();
        Series s = chart.Series.Add("sszs");

        s.ChartType = SeriesChartType.RangeBar;
        s.YValueType = ChartValueType.DateTime;
        s.ResetIsVisibleInLegend () ;
        s.IsVisibleInLegend = true;

        Axis ax = chart.ChartAreas[0].AxisX;
        Axis ay = chart.ChartAreas[0].AxisY;
        ax.MajorGrid.Enabled = false;
  
 Axis ax2 = chart.ChartAreas[0].AxisX2; 
                ax2.Enabled = AxisEnabled.True;
                ax2.Maximum = 100; 
                ax2.MajorGrid.Enabled = false;

        ay.IntervalType = DateTimeIntervalType.Minutes;
        ay.Interval = 60;
        ay.LabelStyle.Format = "HH:mm";

      ay.Minimum = 0;
      ay.Maximum = 0.2;
        limitGantt(chart, "0:00", "24:00");
        s.ToolTip = "#VALY1{HH:mm}~#VALY2{HH:mm}";
    }

我想要百分比 = 绿色 Time/Total 时间(从 00: 00 到当前时间)示例

感谢TaW 的建议。它对我有用。 我post在这里分享给想知道的人

 public void setUpGantt(Chart chart)
{
   chart.Series.Clear();
    Series s = chart.Series.Add("sszs");

    s.ChartType = SeriesChartType.RangeBar;
    s.YValueType = ChartValueType.DateTime;
    s.ResetIsVisibleInLegend () ;
    s.IsVisibleInLegend = true;

    Axis ax = chart.ChartAreas[0].AxisX;
    Axis ay = chart.ChartAreas[0].AxisY;
    ax.MajorGrid.Enabled = false;
  
      Axis ax2 = chart.ChartAreas[0].AxisX2; 
       ax2.Enabled = AxisEnabled.True;
       ax2.MajorGrid.Enabled = true;
       ax2.CustomLabels.Clear();// clear previous value when switch another data
        for (int i = 0; i < 12; i++)
        {
            CustomLabel cl = new CustomLabel();
            cl.FromPosition = i+0.5;   
            cl.ToPosition = i+1.5;  
            cl.Text = i+" %";   // example value to show on CustomLabel
            ax2.CustomLabels.Add(cl);
        }

    ay.IntervalType = DateTimeIntervalType.Minutes;
    ay.Interval = 60;
    ay.LabelStyle.Format = "HH:mm";

  ay.Minimum = 0;
  ay.Maximum = 0.2;
    limitGantt(chart, "0:00", "24:00");
    s.ToolTip = "#VALY1{HH:mm}~#VALY2{HH:mm}";
}

使用 CustomLabel 显示多一个轴的主脚本

Axis ax2 = chart.ChartAreas[0].AxisX2; 
           ax2.Enabled = AxisEnabled.True;
           ax2.MajorGrid.Enabled = true;
           ax2.CustomLabels.Clear();// clear previous value when switch another data
            for (int i = 0; i < 12; i++)
            {
                CustomLabel cl = new CustomLabel();
                cl.FromPosition = i+0.5;   
                cl.ToPosition = i+1.5;  
                cl.Text = i+" %";   // example value to show on CustomLabel
                ax2.CustomLabels.Add(cl);
            }