【问题标题】:How to display multiple legend for range bar chart如何显示范围条形图的多个图例
【发布时间】:2020-08-12 05:06:16
【问题描述】:

我从How can I make a gannt chart with overlapping points in winforms学习 所以我尝试显示该图表的所有图例但它只显示了一个图例 请帮助如何做到这一点

 public Form1()
   {
    InitializeComponent();
    Chart chart2 = new Chart();
    chart2.ChartAreas.Add(new ChartArea());
    chart2.Dock= DockStyle.Top;
    this.Controls.Add(chart2);
    setUpGantt(chart2);
    Series s = chart2.Series[0];
    addGanttTask(s, "8:00", "17:00", Color.LimeGreen, 1);
    addGanttTask(s, "9:00", "9:20", Color.DarkSlateBlue, 1);
    addGanttTask(s, "11:00", "12:00", Color.DarkSlateBlue, 1);
    addGanttTask(s, "13:00", "13:20", Color.DarkSlateBlue, 1);
    s.SetCustomProperty("PixelPointWidth", "15");
    s.Points[0].AxisLabel = "Machine 1";
}
void setUpGantt(Chart chart)
{
   ...
}

void limitGantt(Chart chart, string start, string end)
{
   ...
}
DateTime fromTimeString(string time)
{
   ....
}
void addGanttTask(Series s, string start, string end, Color c, int slot)
{
   ....
}

【问题讨论】:

  • 您要添加的那些图例的标签应该是什么?因为如果我没记错的话,1 Legend 相当于 1 Series。
  • @tontonsevilla 我期待这些传说的每一个标签

标签: c# winforms mschart


【解决方案1】:

如果这是您想要的输出:

第 1 步:为您添加的每个甘特图任务创建一个系列。
第 2 步:确保您始终使用 First Series

int pt = chart.Series[0].Points.AddXY(slot, start_ , end_);
chart.Series[0].Points[pt].Color = c;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多