private void FlexChart1_MouseMove(object sender, MouseEventArgs e) { var hitTestInfo = flexChart1.HitTest(e.Location); if (hitTestInfo == null) { return; } if (hitTestInfo.Item != null && hitTestInfo.Distance <= MAX_DIST) { var item = hitTestInfo.Item as Country; var htmlTemplate = @"<p><b>Country: </b>{0} <br/> <b>Sales: </b>{1} <br/> <b>Expenses: </b>{2} </p>"; var htmlContent = String.Format(htmlTemplate, item.Name, item.Sales, item.Expenses); _stSuperTooltip.SetToolTip(flexChart1, htmlContent); } else { _stSuperTooltip.Hide(); } }
private void FlexChart1_MouseMove(object sender, MouseEventArgs e) { // Show information about chart element under mouse cursor var hitInfo = flexChart1.HitTest(e.Location); var result1 = new StringBuilder(); if (hitInfo != null) { result1.AppendLine(string.Format("Chart element:{0}", hitInfo.ChartElement)); if (hitInfo.Series != null) { result1.AppendLine(string.Format("Series name:{0}", hitInfo.Series.Name)); } if (hitInfo.PointIndex >= 0) { result1.AppendLine(string.Format("Point index={0:0}", hitInfo.PointIndex)); } _lInfo1.Text = result1.ToString(); var result2 = new StringBuilder(); if (hitInfo.Distance > 0) { result2.AppendLine(string.Format("Distance={0:0}", hitInfo.Distance)); } if (hitInfo.X != null) { result2.AppendLine(string.Format("X={0:0}", hitInfo.X)); } if (hitInfo.Y != null) { result2.AppendLine(string.Format("Y={0:p}", hitInfo.Y)); } _lInfo2.Text = result2.ToString(); } }
private void AddAnnotation(Point p, PointerRoutedEventArgs e) { _start = p; try { if (FlexChart.HitTest(_start).ChartElement == ChartElement.PlotArea) { _annotationToAdd = (AnnotationBase)Activator.CreateInstance(NewAnnotationType); _annotationToAdd.Attachment = Attachment; if (_annotationToAdd is Shape) { _annotationToAdd.SetValue(Shape.ContentProperty, NewAnnotationType.Name); } _annotationToAdd.Location = Helpers.CoordsToAnnoPoint(FlexChart, _annotationToAdd, _start); if (_annotationToAdd is Text) { var pt = e.GetCurrentPoint((Window.Current.Content as Frame).Content as MainPage).Position; var anno = this.HitTest(pt); if (anno == null) { ((Text)_annotationToAdd).Content = "New Text Annotation"; ShowContentEditor(_annotationToAdd, e.GetCurrentPoint((Window.Current.Content as Frame).Content as MainPage).Position); ContentEditor.Accept = () => { ApplyStyle(_annotationToAdd, true); this.Annotations.Add(_annotationToAdd); SelectedAnnotation = _annotationToAdd; }; ContentEditor.Reject = () => { _annotationToAdd = null; }; } return; } if (_annotationToAdd is Polygon) { var polygon = PolygonAddFunc(_start); polygon.Attachment = Attachment; for (int i = 0; i < polygon.Points.Count; i++) { polygon.Points[i] = Helpers.CoordsToAnnoPoint(FlexChart, polygon, polygon.Points[i]); } _annotationToAdd = polygon; } _drawing = true; //Start drawing on MouseMove _isDragging = false; ApplyStyle(_annotationToAdd); this.Annotations.Add(_annotationToAdd); SelectedAnnotation = _annotationToAdd; _flexChart.Invalidate(); } } catch (Exception ex) { throw new Exception(ex.Message); } }
private void MChart_ChartTapped(object sender, C1TappedEventArgs e) { C1Point point = e.GetPosition(mChart); ChartHitTestInfo info = mChart.HitTest(point); // display hitTestInfo for each touch event string displayText = string.Empty; if (info != null) { displayText = chartElement + (info.ChartElement == null ? chartElementNone : info.ChartElement.ToString()); if (info.Item != null) { displayText += "\n" + seriesName + info.Series.Name + "\n" + pointIndex + info.PointIndex; ChartPoint data = (ChartPoint)info.Item; displayText += "\nX : " + data.Count; if (info.Series.Name.Equals("sin(x)")) { displayText += " sin(x) : " + data.Sine; } else { displayText += " cos(x) : " + data.Cosine; } } } else { displayText = "Well, this is not happening.."; } mHitTestInfo.Text = displayText; }
private void FlexChart1_MouseDown(object sender, MouseEventArgs e) { var ht = flexChart1.HitTest(new Point(e.X, e.Y)); if (ht.Distance < 3 && ht.X != null && ht.Y != null) { _clickedItem = (UnitsCost)ht.Item; } }
private void OnMouseMove(object sender, MouseEventArgs e) { var ht = flexChart1.HitTest(e.Location); if (ht == null || ht.Series == null) { return; } flexChart1.ToolTip.Content = ht.Series.Name == "Cumulative %" ? "{y:P2}" : "{y}"; }
private void OnMouseMove(object sender, MouseEventArgs e) { var ht = FlexChart.HitTest(e.Location); if (ht != null) { HoverElement = ht.ChartElement; HoverSeries = ht.Distance <= 8 ? ht.Series as Series : null; hoverAxis = (Axis)ht.Axis; } }
private void _flexChart_PointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { var ms = stopwatch.ElapsedMilliseconds; stopwatch.Reset(); if (ms <= 100) { if (ContentEditor == null || SelectedAnnotation == null) { return; } //Show Annotation Editor if (HitTest(e.GetCurrentPoint(FlexChart).Position) == SelectedAnnotation && SelectedAnnotation.IsEditable()) { ShowContentEditor(this.SelectedAnnotation, e.GetCurrentPoint((Window.Current.Content as Frame).Content as MainPage).Position); } } else if (ms > 100) { HideContentEditor(); _drawing = false; var pos = e.GetCurrentPoint(FlexChart).Position; SelectedAnnotation = HitTest(pos); if (AllowMove && SelectedAnnotation != null && e.GetCurrentPoint((UIElement)sender).Properties.IsLeftButtonPressed) { _oldPoint = pos; _isDragging = true; //Start Dragging Windows.UI.Xaml.Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeAll, 1); } else { var ht = FlexChart.HitTest(e.GetCurrentPoint(FlexChart).Position); if (AllowAdd && e.GetCurrentPoint((UIElement)sender).Properties.IsLeftButtonPressed) { _start = pos; if (NewAnnotationType == typeof(Text)) { AddAnnotation(_start, e); FlexChart.Invalidate(); } } else { SelectedAnnotation = null; _flexChart.Invalidate(); } } } stopwatch.Start(); }
private void FlexChart1_MouseMove(object sender, MouseEventArgs e) { var hitInfo = flexChart1.HitTest(e.Location); if (hitInfo != null && hitInfo.Item != null && hitInfo.Distance <= MAX_DIST) { var item = hitInfo.Item as CountrySalesOrders; var subData = from order in item.Orders group order by order.Date.Year into newGroup orderby newGroup.Key select new { Date = newGroup.Key, Amount = newGroup.Sum(x => x.Amount) }; var chart = new FlexChart(); chart.DataSource = subData; chart.BindingX = "Date"; chart.Header.Content = "Yearly Values : " + item.Name; chart.Header.Style.Font = StyleInfo.AxisTitleFont; var series = new Series() { Binding = "Amount" }; series.Style.FillColor = ColorTranslator.FromHtml("#DA3E52"); chart.Series.Add(series); chart.DataLabel.Content = "{y}"; chart.DataLabel.Position = LabelPosition.Top; using (var ms = new MemoryStream()) { //Save the chart to C1SuperTooltip's Images collection chart.SaveImage(ms, ImageFormat.Png, 400, 300); var img = Image.FromStream(ms); var imageName = item.Name + ".png"; _c1SuperTooltip.Images.Add(imageName, img); } var html = "<img src='res://" + item.Name + ".png'/>"; _c1SuperTooltip.SetToolTip(flexChart1, html); } else { _c1SuperTooltip.Hide(); _c1SuperTooltip.Images.Clear(); } }
private void FlexChart1_MouseMove(object sender, MouseEventArgs e) { if (this.flexChart1.PlotRect.Contains(e.Location)) { var hitInfo = flexChart1.HitTest(e.Location, MeasureOption.X, 0); var data = _stockData[hitInfo.PointIndex]; _infoAnnotation.Content = string.Format("High = {0} \nLow = {1} \nOpen={2} \nClose={3} \nVolume={4}", data.High, data.Low, data.Open, data.Close, data.Volume); if (!annotationLayer.Annotations.Contains(_infoAnnotation)) { annotationLayer.Annotations.Add(_infoAnnotation); } } else { annotationLayer.Annotations.Remove(_infoAnnotation); } }
private void ChartMouseClick(object sender, MouseEventArgs e) { if (manager == null) { return; } if (isDrilling) { return; } else { isDrilling = true; } if (e.Button == MouseButtons.Right) { manager.DrillUp(); } else { var hitInfo = flexChart1.HitTest(new Point(e.X, e.Y)); if (hitInfo != null && hitInfo.Distance < 2) { _currentValue = hitInfo.X; var tooltip = flexChart1.ToolTip.Content; flexChart1.ToolTip.Content = "Please wait while the details are being fetched"; flexChart1.Cursor = Cursors.WaitCursor; IEnumerable <object> data = null; FetchDataAsync(manager.DrillDownLevel).ContinueWith(t => { data = t.Result; flexChart1.Enabled = true; flexChart1.Invoke(new Action(() => { flexChart1.ToolTip.Hide(flexChart1); flexChart1.ToolTip.Content = tooltip; flexChart1.Cursor = Cursors.Default; manager.DrillDown(data); })); }); } } }
private void LineMarker_PositionChanged(object sender, PositionChangedArgs e) { if (mChart != null) { var info = mChart.HitTest(new C1Point(e.Position.X, double.NaN)); int pointIndex = info.PointIndex; xLabel.Text = string.Format("{0:MM-dd}", info.X); for (int index = 0; index < mChart.Series.Count; index++) { var series = mChart.Series[index]; var value = series.GetValues(0)[pointIndex]; var fill = (int)((IChart)mChart).GetColor(index); string content = string.Format("{0} = {1}", series.SeriesName, string.Format("{0:f0}", value)); TextView yLabel = yLabels[index]; yLabel.Text = content; } } }
private void OnChartTapped(object sender, C1TappedEventArgs e) { var pt = e.GetPosition(chart); var info = chart.HitTest(pt); if (info != null) { pointIndexLabel.Text = string.Format(NSBundle.MainBundle.LocalizedString("Point Index", "Point Index") + "{0}", info.PointIndex); xyValuesLabel.Text = string.Format(NSBundle.MainBundle.LocalizedString("X Y Values", "X Y Values") + " X: {0}, Y: {1:F2}", info.X, info.Y); if (info.Series != null) { seriesLabel.Text = string.Format(NSBundle.MainBundle.LocalizedString("SeriesName", "SeriesName") + "{0}", info.Series.Name); } else { seriesLabel.Text = NSBundle.MainBundle.LocalizedString("SeriesName", "SeriesName"); } chartElementLabel.Text = string.Format(NSBundle.MainBundle.LocalizedString("Chart element", " Chart element") + "{0}", info.ChartElement.ToString()); } }
private void _flexChart_PointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) { if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse) { var p = e.GetCurrentPoint((UIElement)sender); if (!p.Properties.IsLeftButtonPressed) { if (HitTest(p.Position) != null) { Windows.UI.Xaml.Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Hand, 3); } else { Windows.UI.Xaml.Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.Arrow, 1); } return; } } if (AllowMove && SelectedAnnotation != null && _isDragging && _flexChart.PlotRect.Contains(e.GetCurrentPoint(FlexChart).Position)) { Windows.UI.Xaml.Window.Current.CoreWindow.PointerCursor = new Windows.UI.Core.CoreCursor(Windows.UI.Core.CoreCursorType.SizeAll, 1); _newPoint = e.GetCurrentPoint(FlexChart).Position; var diff = new Point { X = _newPoint.X - _oldPoint.X, Y = _newPoint.Y - _oldPoint.Y }; if (SelectedAnnotation is Line) { var line = SelectedAnnotation as Line; var start = Helpers.AnnoPointToCoords(_flexChart, line, line.Start); var end = Helpers.AnnoPointToCoords(_flexChart, line, line.End); start = start.OffSet(diff); end = end.OffSet(diff); line.Start = Helpers.CoordsToAnnoPoint(_flexChart, line, start); line.End = Helpers.CoordsToAnnoPoint(_flexChart, line, end); _flexChart.Invalidate(); } else if (SelectedAnnotation is Polygon) { var polygon = SelectedAnnotation as Polygon; for (int i = 0; i < polygon.Points.Count; i++) { var pt = Helpers.AnnoPointToCoords(_flexChart, polygon, polygon.Points[i]); pt = pt.OffSet(diff); polygon.Points[i] = Helpers.CoordsToAnnoPoint(_flexChart, polygon, pt); } } else { var location = Helpers.AnnoPointToCoords(_flexChart, SelectedAnnotation, SelectedAnnotation.Location); location = location.OffSet(diff); SelectedAnnotation.Location = Helpers.CoordsToAnnoPoint(_flexChart, SelectedAnnotation, location); _flexChart.Invalidate(); } _oldPoint = _newPoint; _flexChart.Invalidate(); return; } if (AllowAdd && _start != null && (FlexChart.HitTest(e.GetCurrentPoint(FlexChart).Position)).ChartElement == ChartElement.PlotArea) { if (_drawing) { UpdateAnnotation(e.GetCurrentPoint(FlexChart).Position); _flexChart.Invalidate(); } else { Size sz = new Size { Height = Math.Abs(_start.Y - (float)e.GetCurrentPoint(FlexChart).Position.Y), Width = Math.Abs(_start.X - (float)e.GetCurrentPoint(FlexChart).Position.X) }; Size threshold = new Size(2, 2); if (sz.Width > (float)threshold.Width && sz.Height > (float)threshold.Height && HitTest(_start) == null) { AddAnnotation(_start, e); _flexChart.Invalidate(); } } } }