我在我的 winform 中使用 MSCharts 来显示一些图表。我设置了图表,以便用户可以缩放:
chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;
我还使用 MouseDown 事件和 Call Hit 测试方法在图表中向下钻取并显示其他图表信息。:
private void chart1_MouseDown(object sender, MouseEventArgs e)
{
//***** Call Hit Test Method
HitTestResult result = chart1.HitTest(e.X, e.Y);
if (result.ChartElementType == ChartElementType.DataPoint || result.ChartElementType == ChartElementType.DataPointLabel)
{
//*************************Goes into the Pie Chart - Dept
int z = result.PointIndex;
result.Series.XValueType = ChartValueType.DateTime;
DateTime x = DateTime.FromOADate(result.Series.Points[z].XValue);
string name = result.Series.Name.ToString();
name = name + "(" + x.ToShortDateString() + ")";
if (funChartExists(name) == false)
{
subMakeNewPieSeries(result.Series.Name.ToString(), x, name);
}
chart1.ChartAreas["Pie"].Visible = true;
chart1.ChartAreas["Task"].Visible = false;
chart1.ChartAreas["Default"].Visible = false;
chart1.Series[name].Enabled = true;
chart1.Legends[0].Enabled = false;
chart1.ChartAreas["Default"].RecalculateAxesScale();
}
chart1.Invalidate();
}
我还有一个将图表重置为第一个视图的按钮:
private void cmbReset_Click(object sender, EventArgs e)
{
chart1.ChartAreas["Pie"].Visible = false;
chart1.ChartAreas["Task"].Visible = false;
chart1.ChartAreas["Default"].Visible = true;
chart1.Legends[0].Enabled = true;
for (int x = 0; x < chart1.Series.Count; x++)
{
if (chart1.Series[x].ChartArea == "Pie" || chart1.Series[x].ChartArea == "Task")
{
chart1.Series[x].Enabled = false;
}
}
chart1.ChartAreas["Default"].RecalculateAxesScale();
chart1.Invalidate();
}
我的问题是当我返回主图表(使用重置按钮)时,图表保留了第一次向下钻取的鼠标点击,并等待第二次点击(或鼠标向上)放大。所以当你移动鼠标它正在拖动一个深灰色的背景选择,等待第二个缩放点。
有没有办法重置鼠标选择缩放值,或者在我进行命中测试时将其关闭,然后在重置后重新打开?