使用 C# 查找 live 的区域部分
我已经这样做了,使用 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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能有效:
This might work:
也许您可以使用 [
result.PointIndex
(http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization) 获取DatePoint
。 Charting.hittestresult.pointindex.aspx) 和结果.Series
。Maybe you can acquire the
DatePoint
using [result.PointIndex
(http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.hittestresult.pointindex.aspx) andresult.Series
.