开发者

find the region part of live using c#

开发者 https://www.devze.com 2023-03-23 11:17 出处:网络
I have done like this for creating click event handler for one part of the chart using mschart control, the chart is like this

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

find the region part of live using c#

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, "Stat开发者_开发百科us", 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
  {
  }

}


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?");
      }
    }
  }  
}


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") {
    // ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号