使用 C# 查找 live 的区域部分

发布于 2024-11-26 04:38:15 字数 5460 浏览 0 评论 0原文

我已经这样做了,使用 mschart 控件为图表的一部分创建单击事件处理程序,图表如下

和这样的代码

private void targetChartmouse_Click(object sender, MouseEventArgs e)
{ 
  try
  {
    var pos = e.Location;
    var results = kpiChartControl.HitTest(pos.X, pos.Y, false, ChartElementType.DataPoint);
    foreach (var result in results)
    {
      if (result.ChartElementType == ChartElementType.DataPoint)
      { 
        //do something....
      }
    }        
  }
}

当我们单击图表(在图表的每个部分)时,它工作正常,但我只想在单击实时(绿色)时执行某些操作,而不是在每个部分上执行某些操作。是否可以找到实时区域(绿色)

是否可以使用c#?

我正在做winforms应用程序

修改代码

     public void targetChartmouse_Click(object sender, MouseEventArgs e)
   {
  Series statusseries = new Series();
  Series liveseries = null;
  Title title;
  string area;

  //Series totalserries;
  try
  {
    var pos = e.Location;
    var results = kpiChartControl.HitTest(pos.X, pos.Y, false, ChartElementType.DataPoint);
    foreach (var result in results)
    {
      if (result.ChartElementType == ChartElementType.DataPoint)
      {

          DataTable accepts = null;
          accepts = KPIData.livemembersmembershiptype(mf);

          DataTable membershiptypes = null;
          membershiptypes = KPIData.MembershipTotals(dtStartDate.Value, dtEndDate.Value, mf);

          area = "subchart";
          kpiChartControl.ChartAreas.Add(area);
          statusseries = kpiChartControl.Series.Add(area);
          statusseries.ChartArea = area;

          title = kpiChartControl.Titles.Add("Live Status  members  By MemberShip Type");
          title.DockedToChartArea = area;
          title.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
          title.Alignment = ContentAlignment.TopLeft;
          kpiChartControl.Titles.Add("").DockedToChartArea = area;
          kpiChartControl.Titles.Add("Live status membership types").DockedToChartArea = area;


          area = "";
          kpiChartControl.Titles.Add("").DockedToChartArea = area;




          foreach (Title titles in kpiChartControl.Titles)
          {
            titles.IsDockedInsideChartArea = false;
          }


          foreach (ChartArea chartArea in kpiChartControl.ChartAreas)
          {
            chartArea.Area3DStyle.Enable3D = true;
            chartArea.AxisX.LabelStyle.IsEndLabelVisible = true;
            //chartArea.AxisX.LabelStyle.IsEndLabelVisible = !overview;
          }

          if (area == "subchart")
          {
            foreach (Series chartSeries in kpiChartControl.Series)
            {
              chartSeries.ChartType = SeriesChartType.StackedColumn;
              chartSeries["ColumnDrawingStyle"] = "SoftEdge";
              chartSeries["LabelStyle"] = "Top";
              chartSeries.IsValueShownAsLabel = true;
              chartSeries.BackGradientStyle = GradientStyle.DiagonalLeft;
            }
          }
          else if (area == "subchart")
          {
            foreach (Series chartSeries in kpiChartControl.Series)
            {
              chartSeries.ChartType = SeriesChartType.Pie;

              //chartSeries["PieLabelStyle"] = "Outside";
              chartSeries["PieLabelStyle"] = "Inside";
              chartSeries["DoughnutRadius"] = "30";
              chartSeries["PieDrawingStyle"] = "SoftEdge";

              chartSeries.BackGradientStyle = GradientStyle.DiagonalLeft;

            }

          }

          foreach (Legend legend in kpiChartControl.Legends)
          {
            legend.Enabled = false;
          }

          if (membershiptypes == null)
          {
            statusseries.Points.Clear();
            statusseries.Points.AddXY("no status", 0);

          }
          if (accepts == null)
          {
            liveseries.Points.Clear();
            liveseries.Points.AddXY("no live", 0);

          }
          kpiChartControl.Series["subchart"].Points.DataBindXY(accepts.Rows, "mshipname", accepts.Rows, "count");
          kpiChartControl.Series[0].Points.DataBindXY(membershiptypes.Rows, "Status", membershiptypes.Rows, "Value");

        }

        foreach (Series chartSeries in kpiChartControl.Series)
        {
          foreach (DataPoint point in chartSeries.Points)
          {

            switch (point.AxisLabel)
            {
              case "Silver membership": point.Color = Color.Green; break;
              case "Gold Membership": point.Color = Color.Blue; break;
              //case "Refused": point.Color = Color.Red; break;
              case "Weekend Peak": point.Color = Color.Cyan; break;
              case "prspect": point.Color = Color.Indigo; break;

            }
            point.Label = string.Format("{0:0}", point.YValues[0]);
          }

        }

        foreach (Series chartSeries in kpiChartControl.Series)
        {
          foreach (DataPoint point in chartSeries.Points)
          {
            switch (point.AxisLabel)
            {
              case "New": point.Color = Color.Cyan; break;
              case "Live": point.Color = Color.Green; break;
              case "Defaulter": point.Color = Color.Red; break;
              case "Cancelled": point.Color = Color.Orange; break;
              case "Completed": point.Color = Color.Blue; break;
              case "Frozen": point.Color = Color.Violet; break;
            }

            point.Label = string.Format("{0:0} - {1}", point.YValues[0], point.AxisLabel);
          }
        }

    }
  }
  catch
  {
  }

}

I have done like this for creating click event handler for one part of the chart using mschart control, the chart is like this enter image description here

and the code like this

private void targetChartmouse_Click(object sender, MouseEventArgs e)
{ 
  try
  {
    var pos = e.Location;
    var results = kpiChartControl.HitTest(pos.X, pos.Y, false, ChartElementType.DataPoint);
    foreach (var result in results)
    {
      if (result.ChartElementType == ChartElementType.DataPoint)
      { 
        //do something....
      }
    }        
  }
}

It's working fine when we click on the chart (in every section of chart), but I want to do something only when we click on the live(green), not on every part. Is it possible to find the region of live(green)

Is it possible using c#?

I am doing winforms application

Modified Code

     public void targetChartmouse_Click(object sender, MouseEventArgs e)
   {
  Series statusseries = new Series();
  Series liveseries = null;
  Title title;
  string area;

  //Series totalserries;
  try
  {
    var pos = e.Location;
    var results = kpiChartControl.HitTest(pos.X, pos.Y, false, ChartElementType.DataPoint);
    foreach (var result in results)
    {
      if (result.ChartElementType == ChartElementType.DataPoint)
      {

          DataTable accepts = null;
          accepts = KPIData.livemembersmembershiptype(mf);

          DataTable membershiptypes = null;
          membershiptypes = KPIData.MembershipTotals(dtStartDate.Value, dtEndDate.Value, mf);

          area = "subchart";
          kpiChartControl.ChartAreas.Add(area);
          statusseries = kpiChartControl.Series.Add(area);
          statusseries.ChartArea = area;

          title = kpiChartControl.Titles.Add("Live Status  members  By MemberShip Type");
          title.DockedToChartArea = area;
          title.Font = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Bold);
          title.Alignment = ContentAlignment.TopLeft;
          kpiChartControl.Titles.Add("").DockedToChartArea = area;
          kpiChartControl.Titles.Add("Live status membership types").DockedToChartArea = area;


          area = "";
          kpiChartControl.Titles.Add("").DockedToChartArea = area;




          foreach (Title titles in kpiChartControl.Titles)
          {
            titles.IsDockedInsideChartArea = false;
          }


          foreach (ChartArea chartArea in kpiChartControl.ChartAreas)
          {
            chartArea.Area3DStyle.Enable3D = true;
            chartArea.AxisX.LabelStyle.IsEndLabelVisible = true;
            //chartArea.AxisX.LabelStyle.IsEndLabelVisible = !overview;
          }

          if (area == "subchart")
          {
            foreach (Series chartSeries in kpiChartControl.Series)
            {
              chartSeries.ChartType = SeriesChartType.StackedColumn;
              chartSeries["ColumnDrawingStyle"] = "SoftEdge";
              chartSeries["LabelStyle"] = "Top";
              chartSeries.IsValueShownAsLabel = true;
              chartSeries.BackGradientStyle = GradientStyle.DiagonalLeft;
            }
          }
          else if (area == "subchart")
          {
            foreach (Series chartSeries in kpiChartControl.Series)
            {
              chartSeries.ChartType = SeriesChartType.Pie;

              //chartSeries["PieLabelStyle"] = "Outside";
              chartSeries["PieLabelStyle"] = "Inside";
              chartSeries["DoughnutRadius"] = "30";
              chartSeries["PieDrawingStyle"] = "SoftEdge";

              chartSeries.BackGradientStyle = GradientStyle.DiagonalLeft;

            }

          }

          foreach (Legend legend in kpiChartControl.Legends)
          {
            legend.Enabled = false;
          }

          if (membershiptypes == null)
          {
            statusseries.Points.Clear();
            statusseries.Points.AddXY("no status", 0);

          }
          if (accepts == null)
          {
            liveseries.Points.Clear();
            liveseries.Points.AddXY("no live", 0);

          }
          kpiChartControl.Series["subchart"].Points.DataBindXY(accepts.Rows, "mshipname", accepts.Rows, "count");
          kpiChartControl.Series[0].Points.DataBindXY(membershiptypes.Rows, "Status", membershiptypes.Rows, "Value");

        }

        foreach (Series chartSeries in kpiChartControl.Series)
        {
          foreach (DataPoint point in chartSeries.Points)
          {

            switch (point.AxisLabel)
            {
              case "Silver membership": point.Color = Color.Green; break;
              case "Gold Membership": point.Color = Color.Blue; break;
              //case "Refused": point.Color = Color.Red; break;
              case "Weekend Peak": point.Color = Color.Cyan; break;
              case "prspect": point.Color = Color.Indigo; break;

            }
            point.Label = string.Format("{0:0}", point.YValues[0]);
          }

        }

        foreach (Series chartSeries in kpiChartControl.Series)
        {
          foreach (DataPoint point in chartSeries.Points)
          {
            switch (point.AxisLabel)
            {
              case "New": point.Color = Color.Cyan; break;
              case "Live": point.Color = Color.Green; break;
              case "Defaulter": point.Color = Color.Red; break;
              case "Cancelled": point.Color = Color.Orange; break;
              case "Completed": point.Color = Color.Blue; break;
              case "Frozen": point.Color = Color.Violet; break;
            }

            point.Label = string.Format("{0:0} - {1}", point.YValues[0], point.AxisLabel);
          }
        }

    }
  }
  catch
  {
  }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你的呼吸 2024-12-03 04:38:15

这可能有效:

try
{
  var pos = e.Location;
  var results = kpiChartControl.HitTest(pos.X, pos.Y, false, ChartElementType.DataPoint);
  foreach (var result in results)
  {
    if (result.ChartElementType == ChartElementType.DataPoint)
    {
      if (result.Series.Points[result.PointIndex].AxisLabel == "Live")
      {
        Console.WriteLine("success?");
      }
    }
  }  
}

This might work:

try
{
  var pos = e.Location;
  var results = kpiChartControl.HitTest(pos.X, pos.Y, false, ChartElementType.DataPoint);
  foreach (var result in results)
  {
    if (result.ChartElementType == ChartElementType.DataPoint)
    {
      if (result.Series.Points[result.PointIndex].AxisLabel == "Live")
      {
        Console.WriteLine("success?");
      }
    }
  }  
}
烟柳画桥 2024-12-03 04:38:15

也许您可以使用 [result.PointIndex(http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization) 获取 DatePoint。 Charting.hittestresult.pointindex.aspx) 和 结果.Series

if(result.Series.Points.Item[result.PointIndex].Label == "Live") {
    // ...
}

Maybe you can acquire the DatePoint using [result.PointIndex(http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.hittestresult.pointindex.aspx) and result.Series.

if(result.Series.Points.Item[result.PointIndex].Label == "Live") {
    // ...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文