Hi Experts
I m using syncfusion tool to draw my charts. I also need to get the value of the chart on its mouse position. For that I use the function
chartControl1.ChartArea.GetValueByPoint(e.Point);
Which gives me the value of the chart according to its mouse position. But its gives value only corresponding to the primary Y axis. I need to get that value in accordance with the secondary axis. It that possible? plz help me how can I get that.
|
private void ChartControl1_MouseUp(object sender, MouseEventArgs e)
{
//This gives the corresponding X and Y coordinates of the mouse point.
Point mousePoint = new Point(e.X, e.Y);
//The GetValueByPoint method returns the X and Y values of the PrimaryYAxis calculated from the mousepoint.
ChartPoint PrimaryAxis = chartControl1.ChartArea.GetValueByPoint(new Point(e.X, e.Y));
//The GetRealValue method returns the X and Y values of the corresponding axis value calculated from the mousepoint.
var secondaryAxisvalue = this.chartControl1.Series[1].ActualYAxis.GetRealValue(mousePoint);
} |
Thank you so much Yuvaraj.
There is one more question.
I implemented the movement of a point on the chart knowing the position of the mouse if the right mouse button is clamped, since the left button is responsible for scaling the chart.
this.chartControl1.EnableXZooming = true;
this.chartControl1.EnableYZooming = true;
this.chartControl1.ResetOnDoubleClick = true;
The question is whether it is possible to create the same area as when scaling but of a different color and when you click on the right mouse button and start moving the entire series of points that fell into this new area.
Now I'm moving the point:
private bool isMouse = false;
private ChartRegion currentRegion = null;
private void chartControl1_ChartRegionMouseMove(object sender, ChartRegionMouseEventArgs e)
{
if (isMouse)
{
if (e.Region.SeriesIndex == 0)
{
double pointY = Math.Round(chartControl1.Series[0].ActualYAxis.GetRealValue(e.Point), 1);
int pointX = int.Parse(Math.Round(chartControl1.Series[0].ActualXAxis.GetRealValue(e.Point)).ToString());
if (pointY < 0.5)
pointY = 0;
chartControl1.Series[0].Points[pointX].YValues[0] = pointY;
}
if (e.Region.SeriesIndex == 1)
{
double pointY = Math.Round(chartControl1.Series[1].ActualYAxis.GetRealValue(e.Point), 1);
int pointX = int.Parse(Math.Round(chartControl1.Series[1].ActualXAxis.GetRealValue(e.Point)).ToString());
if (pointY < 0.5)
pointY = 0;
chartControl1.Series[1].Points[pointX].YValues[0] = pointY;
}
chartControl1.Redraw(true);
}
}
private void chartControl1_ChartRegionMouseDown(object sender, ChartRegionMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (e.Region.IsChartPoint)
{
currentRegion = e.Region;
isMouse = true;
chartControl1.Series.BeginUpdate();
}
}
}
private void chartControl1_ChartRegionMouseUp(object sender, ChartRegionMouseEventArgs e)
{
if (isMouse)
{
chartControl1.Series.EndUpdate();
isMouse = false;
}
}
|
private void ChartControl1_ChartRegionMouseUp(object sender, ChartRegionMouseEventArgs e)
{
if (isMouse)
{
ChartPoint start = chartControl1.ChartArea.GetValueByPoint(startPoint);
ChartPoint end = chartControl1.ChartArea.GetValueByPoint(e.Point);
var minY = start.YValues[0] < end.YValues[0] ? start.YValues[0] : end.YValues[0];
var maxY = start.YValues[0] > end.YValues[0] ? start.YValues[0] : end.YValues[0];
List <Model> dataCollection = new List<Model>();
foreach (var data in this.viewModel.Data)
{
if (data.XValue > start.X && data.XValue < end.X && data.YValue > minY && data.YValue < maxY)
{
dataCollection.Add(data);
}
}
ChartSeries series = new ChartSeries();
series.Style.Interior = new BrushInfo(Color.Black);
ChartDataBindModel dataSeriesModel = new ChartDataBindModel(dataCollection);
dataSeriesModel.XName = "XValue";
dataSeriesModel.YNames = new string[] { "YValue" };
series.SeriesModel = dataSeriesModel;
series.Type = ChartSeriesType.Line;
this.chartControl1.Series.Add(series);
chartControl1.Series.EndUpdate();
isMouse = false;
}
}
|
Thanks for your decision, but I wanted a slightly different result. Now clicking on the left mouse button creates a blue area for scaling ("Figure 1"), I want to press the right button and hold it also draw an area of a different color such as red, so that the user can see what he is choosing.
And as for the movement of points, it is now implemented so that when I press the right mouse button on the point and drag the mouse cursor up or down the point on the chart moves behind the cursor (I attached the code earlier).
And to move a group of points, the new area that the user creates with the right mouse button captures a group of points (I drew an example of the area captures three points "Figure 2") as soon as the user releases the mouse button the area stops drawing and all the points that have been selected begin to rise or fall along the Y axis following the mouse cursor until the user once presses the right mouse button again to finish changing the position of the group of points.
|
Panel panel1; private void InitializeComponent()
{
. . .
this. panel1 = new System.Windows.Forms.Panel();
}
private void ChartControl1_ChartRegionMouseDown(object sender, ChartRegionMouseEventArgs e) {
if (e.Button == MouseButtons.Right)
{
. . .
panel1.BackColor = Color.FromArgb(125, 255, 0, 0);
this.panel1.Location = e.Point;
this.panel1.Size = new Size(0, 0);
this.chartControl1.Controls.Add(panel1);
}
}
private void ChartControl1_ChartRegionMouseMove(object sender, ChartRegionMouseEventArgs e)
{
if (isMouse)
{
this.panel1.Size = new Size(e.Point.X - startPoint.X, e.Point.Y - startPoint.Y);
}
}
private void ChartControl1_ChartRegionMouseUp(object sender, ChartRegionMouseEventArgs e)
{
if (isMouse)
{
. . .
chartControl1.Series.EndUpdate();
this.chartControl1.Controls.Remove(panel1);
isMouse = false;
}
} |
Thanks for your solution, it helped me, but why doesn't the panel create if I pull from the bottom corner to the top.
Thanks for your work, you helped me a lot. ;)