Hi,
I am trying to zoom user selected portion of chart.
user can draw rectangle or square by dragging mouse mouse.
startPosition : Mouse Down
End Position : Mouse Up or MouseMove
i draw rectangle from startPosition to End Position in FillSceneGraph event.
basically on MouseMove event i store EndPosition as current mouse location and call InvalidateLayers function on chart.
In FillSceneGraph event i draw rectangle from startPosition to EndPosition and add it to SceneGraph.
Every thing works fine except the delay in displaying rectangle.
is there any way to avoid the delay..or is FillSceneGraph is right place to add primitives on mousemove event.
as mousemove event is called for every few milliseconds ..
Thanks,
Kk
I am confused by what kalvagadda said.
According the information, it seems that the "Zoom By Area" (use left mouse to draw a rectangle to zoom in) feature is available already.
However, as far as I know, the feature has not been implemented. what we only have is using Alt + mouse scroll button in order to zoom in/out 3D charts. In order to zoom in/out 2D charts you should enable axis' scroll.
Please paste some code for example if you know how to zoom by area.
Anybody who knows something related can clarify this.
thanks
"click and drag" zooming is not a feature of our winchart. The only way to implement this feature is to use a combination of MouseDown, MouseUp and FillSceneGraph events. The mouse events will help you determine the size of the rectangular zooming region. FillSceneGraph can be used to calculate the scaling factor for the chart axes. I'm not sure if someone has successfully implemented this in the past.
No, the feature request page is still the same. I made an attempt to write a code sample. It's not exactly perfect, but hopefully will prove useful.
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Windows.Forms;using Infragistics.UltraChart.Core.Primitives;using Infragistics.UltraChart.Data;using Infragistics.UltraChart.Core.Layers;using Infragistics.UltraChart.Resources.Appearance;using Infragistics.UltraChart.Shared.Styles;using Infragistics.UltraChart.Core;using Infragistics.UltraChart.Resources;namespace WindowsFormsApplication1{public partial class Form1 : Form{ public Form1() { InitializeComponent(); }
Point startPoint, endPoint;bool mouseDown = false;bool valid = true;double scaleX, scrollX, scaleY, scrollY;bool updateChartScale = true;
private void ultraChart1_FillSceneGraph(object sender, Infragistics.UltraChart.Shared.Events.FillSceneGraphEventArgs e){ valid = true; if (e.Grid.Count == 0) return; IAdvanceAxis xAxis = (IAdvanceAxis)e.Grid["X"]; IAdvanceAxis yAxis = (IAdvanceAxis)e.Grid["Y"]; int width = Math.Abs(endPoint.X - startPoint.X); int height = Math.Abs(endPoint.Y - startPoint.Y); Box box = new Box(startPoint, width, height);
if (box.rect.Left < xAxis.MapMinimum || box.rect.Top < yAxis.MapMaximum || box.rect.Right > xAxis.MapMaximum || box.rect.Bottom > yAxis.MapMinimum) { valid = false; return; }
if (valid) { if (mouseDown) { e.SceneGraph.Add(box); }
else if (updateChartScale) { updateChartScale = false; double offsetX = (e.ChartCore.GridLayerBounds.Width / xAxis.Scale - e.ChartCore.GridLayerBounds.Width) * xAxis.Scroll; double offsetY = (e.ChartCore.GridLayerBounds.Height / yAxis.Scale - e.ChartCore.GridLayerBounds.Height) * yAxis.Scroll; scaleX = xAxis.Scale * box.rect.Width / e.ChartCore.GridLayerBounds.Width; scaleY = yAxis.Scale * box.rect.Height / e.ChartCore.GridLayerBounds.Height; scrollX = (box.rect.X - xAxis.MapMinimum + offsetX) / (e.ChartCore.GridLayerBounds.Width / xAxis.Scale - box.rect.Width); scrollY = (yAxis.MapMinimum - box.rect.Bottom + offsetY) / (e.ChartCore.GridLayerBounds.Height / yAxis.Scale - box.rect.Height); BeginInvoke(new MethodInvoker(SetChartAxes)); } }}
private void Form1_Load(object sender, EventArgs e){ ultraChart1.Data.DataSource = DemoTable.Table(); ultraChart1.Axis.X.ScrollScale.Visible = true; ultraChart1.Axis.Y.ScrollScale.Visible = true;}
private void ultraChart1_MouseDown(object sender, MouseEventArgs e){ startPoint = e.Location; mouseDown = true;}
private void ultraChart1_MouseUp(object sender, MouseEventArgs e){ mouseDown = false; updateChartScale = true; ultraChart1.InvalidateLayers();}
private void ultraChart1_MouseMove(object sender, MouseEventArgs e){ if (mouseDown) { endPoint = e.Location; ultraChart1.InvalidateLayers(); }}
private void SetChartAxes(){ ultraChart1.Axis.X.ScrollScale.Scale = scaleX; ultraChart1.Axis.Y.ScrollScale.Scale = scaleY; ultraChart1.Axis.X.ScrollScale.Scroll = scrollX; ultraChart1.Axis.Y.ScrollScale.Scroll = scrollY;}}}
Very Good article,after zooming,is there any way to undo my latest change..
Sure, you can store the scrolling and scaling variables in some temporary location. Then, when you need to undo the zooming/scrolling set the axis scrollscale scroll and zoom to those stored variables.
Thnx fr the reply.If we drag the region where data is there,it is working great,and tht is the ultimate.
Suppose if I select an empty region,there also it is zooming..and tht time we will see empty chart only.
Is there any way to prevent the user to select that empty region.
And one more thing,if I click on any data column..then also it is getting zoomed.But i dont want to zoom tht in click.Because Iam doing drill down in tht click,and it is getting effected.
Is there any way to prevent zooming in the click of data column.
Iam very curios like how it will work....:):)
You cannot prevent zooming into a region with no data points. There's no way to tell if there are shapes drawn inside a particular rectangle, but you can do something to prevent zooming in when you just have a mouse click.
For this you can change the conditions of when the selection rectangle is valid. For example, you can force the rectangle to be at least 5x5 pixels:if the box's width and height are less than 5 set valid to false, and you shouldn't see the click problem.
You can use OuterBound property of the chart layer to get the bounds rectangle instead of GridLayerBounds:Rectangle bounds = ultraChart1.CompositeChart.ChartLayers[0].ChartLayer.OuterBound;Also, when using a composite chart, remember to get the right Grid to avoid the axes being null:ChartLayer layer = ultraChart1.CompositeChart.ChartLayers[0].ChartLayer;IAdvanceAxis xAxis = (IAdvanceAxis)layer.Grid[0];IAdvanceAxis yAxis = (IAdvanceAxis)layer.Grid[1];
Hi, I tried to use it in an CompositeChart, but the calculation of scaleX and scaleY goes always wrong because the GridLayerBounds.Width and the GridLayerBounds.Height are always zero. I added a snippet:
try 1:
scaleX = xAxis.Scale * box.rect.Width / e.ChartCore.GridLayerBounds.Width; scaleY = yAxis.Scale * box.rect.Height / e.ChartCore.GridLayerBounds.Height;
try2:
offsetX = (this.ultraChart.CompositeChart.ChartLayers[0].ChartLayer.ChartCore.GridLayerBounds.Width / xAxis.Scale - this.ultraChart.CompositeChart.ChartLayers[0].ChartLayer.ChartCore.GridLayerBounds.Width) * xAxis.Scroll; offsetY = (this.ultraChart.CompositeChart.ChartLayers[0].ChartLayer.ChartCore.GridLayerBounds.Height / yAxis.Scale - this.ultraChart.CompositeChart.ChartLayers[0].ChartLayer.ChartCore.GridLayerBounds.Height) * yAxis.Scroll;
Does anybody know how it will work?
oh,thts great ...thnx fr ur immediate reply.