protected internal virtual void SearchForHotRegion() { object contextObjectNoLabel = Result.GetContextObjectNoLabel(); ChartElementType chartElementType = Result.GetChartElementType(); this.hotRegion = new HotRegion(); if (contextObjectNoLabel == null) { return; } HotRegionsList hotRegionsList = Chart.common.HotRegionsList; if (hotRegionsList.List.Count == 0) { ChartControl.HitTest(2, 2); } int num = hotRegionsList.List.Count - 1; HotRegion hotRegion; while (true) { if (num >= 0) { hotRegion = (HotRegion)hotRegionsList.List[num]; if (hotRegion.SelectedObject == contextObjectNoLabel && hotRegion.Type == chartElementType && hotRegion.Type == chartElementType) { break; } num--; continue; } return; } this.hotRegion = hotRegion; }
public EasyChartXPlotArea GetHitPlotArea(HitTestResult result) { ChartElementType hitObject = result.ChartElementType; ChartArea hitChartArea = result.ChartArea; if (null == hitChartArea || (hitObject != ChartElementType.PlottingArea && hitObject != ChartElementType.Gridlines && hitObject != ChartElementType.StripLines && hitObject != ChartElementType.DataPoint && hitObject != ChartElementType.Axis)) { return(null); } EasyChartXPlotArea hitPlotArea = null; if (ReferenceEquals(MainPlotArea.ChartArea, hitChartArea)) { hitPlotArea = MainPlotArea; } else { int plotAreaIndex = SplitPlotAreas.FindIndexByBaseChartArea(hitChartArea); if (plotAreaIndex >= 0 && plotAreaIndex < SplitPlotAreas.Count) { hitPlotArea = SplitPlotAreas[plotAreaIndex]; } } return(hitPlotArea); }
internal bool IsElementClickable(object element, ChartElementType chartElementType) { if (element != null) { HotRegionsList hotRegionsList = Chart.common.HotRegionsList; if (hotRegionsList.List.Count == 0) { ChartControl.HitTest(2, 2); } foreach (HotRegion item in hotRegionsList.List) { ChartElementType type = item.Type; if (type == ChartElementType.DataPointLabel) { if (element is Series && string.Compare(item.SeriesName, ((Series)element).Name, StringComparison.Ordinal) == 0 && item.Type == chartElementType) { return(true); } } else if (item.SelectedObject == element && item.Type == chartElementType) { return(true); } } } return(false); }
internal bool IsChartElementSelected(ChartElementType elementType, object chartObject, object chartSubObject) { if (HitTestResult != null && HitTestResult.ChartElementType == elementType && HitTestResult.Object == chartObject && HitTestResult.SubObject == chartSubObject) { return(true); } return(false); }
/// <summary> /// Object constructor. /// </summary> /// <param name="value">Value to be formatted.</param> /// <param name="format">Format string.</param> /// <param name="valueType">Value type..</param> /// <param name="localizedValue">Localized value.</param> /// <param name="senderTag">Chart element object tag.</param> /// <param name="elementType">Chart element type.</param> internal FormatNumberEventArgs(double value, string format, ChartValueType valueType, string localizedValue, object senderTag, ChartElementType elementType) { _value = value; _format = format; _valueType = valueType; LocalizedValue = localizedValue; _senderTag = senderTag; _elementType = elementType; }
private void Chart_MouseDown(object sender, MouseEventArgs e) { // Ignore everything but left clicks if (e.Button != MouseButtons.Left) { return; } DataPoint point; Series series = Chart.Series[0]; // Determine where the user has clicked HitTestResult[] results = Chart.HitTest(e.X, e.Y, false, new ChartElementType[] { ChartElementType.DataPoint, ChartElementType.AxisLabels, ChartElementType.ScrollBarLargeDecrement, ChartElementType.ScrollBarLargeIncrement, ChartElementType.ScrollBarSmallDecrement, ChartElementType.ScrollBarSmallIncrement, ChartElementType.ScrollBarThumbTracker }); // If the user clicked on a scrollbar, don't do anything else ChartElementType[] scrollBarTypes = new ChartElementType[] { ChartElementType.ScrollBarLargeDecrement, ChartElementType.ScrollBarLargeIncrement, ChartElementType.ScrollBarSmallDecrement, ChartElementType.ScrollBarSmallIncrement, ChartElementType.ScrollBarThumbTracker }; if (!results.Any(r => scrollBarTypes.Contains(r.ChartElementType))) { HitTestResult dataPoint = results.FirstOrDefault(r => r.ChartElementType == ChartElementType.DataPoint); HitTestResult axisLabel = results.FirstOrDefault(r => r.ChartElementType == ChartElementType.AxisLabels); if (dataPoint != null) { point = Chart.Series[0].Points[dataPoint.PointIndex]; OnDataPointClick(point); } else if (axisLabel != null) { CustomLabel label = (CustomLabel)axisLabel.Object; for (int i = 0; i < series.Points.Count; i++) { if (label.Text == series.Points[i].AxisLabel) { point = series.Points[i]; OnDataPointClick(point); } } } } }
/// <summary> /// Initializes chart element accessibility object with specified title. /// </summary> /// <param name="chartAccessibleObject">Chart accessibility object.</param> /// <param name="chartAccessibleParentObject">The chart accessible parent object.</param> /// <param name="chartChildObject">Chart child object.</param> /// <param name="chartChildObjectType">Chart child object type.</param> /// <param name="name">Chart child object name.</param> /// <param name="objectValue">Chart child object value.</param> /// <param name="role">Chart child object role.</param> public ChartChildAccessibleObject( ChartAccessibleObject chartAccessibleObject, AccessibleObject chartAccessibleParentObject, object chartChildObject, ChartElementType chartChildObjectType, string name, string objectValue, AccessibleRole role) { this.chartAccessibleObject = chartAccessibleObject; this.chartAccessibleParentObject = chartAccessibleParentObject; this.chartChildObject = chartChildObject; this.chartChildObjectType = chartChildObjectType; this.name = name; this.role = role; this.objectValue = objectValue; }
internal void AddHotRegion(RectangleF rectArea, object selectedObject, ChartElementType type, bool relativeCoordinates, bool insertAtBeginning) { if ((ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions) { HotRegion hotRegion = new HotRegion(); hotRegion.BoundingRectangle = rectArea; hotRegion.RelativeCoordinates = relativeCoordinates; hotRegion.Type = type; hotRegion.SelectedObject = selectedObject; if (insertAtBeginning) { regionList.Insert(regionList.Count - 1, hotRegion); } else { regionList.Add(hotRegion); } } }
/// <summary> /// Initializes chart element accessibility object with specified title. /// </summary> /// <param name="chartAccessibleObject">Chart accessibility object.</param> /// <param name="chartAccessibleParentObject">The chart accessible parent object.</param> /// <param name="chartChildObject">Chart child object.</param> /// <param name="chartChildObjectType">Chart child object type.</param> /// <param name="name">Chart child object name.</param> /// <param name="objectValue">Chart child object value.</param> /// <param name="role">Chart child object role.</param> /// <param name="seriesName">Chart series name.</param> /// <param name="pointIndex">Chart data point index.</param> public ChartChildAccessibleObject( ChartAccessibleObject chartAccessibleObject, AccessibleObject chartAccessibleParentObject, object chartChildObject, ChartElementType chartChildObjectType, string name, string objectValue, AccessibleRole role, string seriesName, int pointIndex) { this.chartAccessibleObject = chartAccessibleObject; this.chartAccessibleParentObject = chartAccessibleParentObject; this.chartChildObject = chartChildObject; this.chartChildObjectType = chartChildObjectType; this.name = name; this.role = role; this.objectValue = objectValue; this.seriesName = seriesName; this.dataPointIndex = pointIndex; }
internal bool SelectChartElement(ChartElementType elementType, object chartObject, object chartSubObject) { if (ChartControl != null) { string seriesName = string.Empty; int result = 0; if ((elementType == ChartElementType.DataPoint || elementType == ChartElementType.DataPointLabel) && !(chartObject is Series) && !(chartObject is DataPoint)) { return(false); } DataPoint dataPoint = null; if (chartObject is Series) { seriesName = (chartObject as Series).Name; if (chartSubObject is DataPoint && (chartSubObject as DataPoint).series != null) { dataPoint = (chartSubObject as DataPoint); seriesName = dataPoint.series.Name; result = dataPoint.series.Points.IndexOf(dataPoint); } } else if (chartObject is DataPoint && (chartObject as DataPoint).series != null) { dataPoint = (chartObject as DataPoint); seriesName = dataPoint.series.Name; result = dataPoint.series.Points.IndexOf(dataPoint); } if (result == -1 && dataPoint != null && dataPoint.IsAttributeSet("OriginalPointIndex")) { int.TryParse(dataPoint["OriginalPointIndex"], NumberStyles.Integer, CultureInfo.InvariantCulture, out result); } if (result == -1) { return(false); } HitTestResult = ChartControl.GetHitTestResult(seriesName, result, elementType, chartObject); return(true); } return(false); }
public bool SelectChartElement(ChartElementType elementType, object chartObject, object chartSubObject) { if (this.ChartControl != null) { string seriesName = string.Empty; int num = 0; if ((elementType == ChartElementType.DataPoint || elementType == ChartElementType.DataPointLabel) && !(chartObject is Series) && !(chartObject is DataPoint)) { return(false); } DataPoint dataPoint = null; if (chartObject is Series) { seriesName = (chartObject as Series).Name; if (chartSubObject is DataPoint && (chartSubObject as DataPoint).series != null) { dataPoint = (chartSubObject as DataPoint); seriesName = dataPoint.series.Name; num = dataPoint.series.Points.IndexOf(dataPoint); } } else if (chartObject is DataPoint && (chartObject as DataPoint).series != null) { dataPoint = (chartObject as DataPoint); seriesName = dataPoint.series.Name; num = dataPoint.series.Points.IndexOf(dataPoint); } if (num == -1 && dataPoint != null && dataPoint.IsAttributeSet("OriginalPointIndex")) { int.TryParse(((DataPointAttributes)dataPoint)["OriginalPointIndex"], NumberStyles.Integer, (IFormatProvider)CultureInfo.InvariantCulture, out num); } if (num == -1) { return(false); } this.HitTestResult = this.ChartControl.GetHitTestResult(seriesName, num, elementType, chartObject); return(true); } return(false); }
/// <summary> /// Converts value to string using specified format. /// </summary> /// <param name="chart">Reference to the chart object.</param> /// <param name="obj">Reference to the object being formatted.</param> /// <param name="objTag">Additional object tag.</param> /// <param name="value">Value converted to string.</param> /// <param name="format">Format string.</param> /// <param name="valueType">Value type.</param> /// <param name="elementType">Chart element type being formatted.</param> public static string FormatValue( ChartService chart, object obj, object objTag, double value, string format, ChartValueType valueType, ChartElementType elementType) { format ??= string.Empty; string convertionFormat = format; string result = ""; // Make sure value index is part of the format if (convertionFormat != null && convertionFormat.Length > 0) { int bracketIndex = convertionFormat.IndexOf('{', 0); if (bracketIndex >= 0) { while (bracketIndex >= 0) { // If format is not followed by the value index if (!convertionFormat[bracketIndex..].StartsWith("{0:", StringComparison.Ordinal))
private void chartCtrl_MouseMove(object sender, MouseEventArgs e) { switch (lastHitElementType) { case ChartElementType.DataPointLabel: chartCtrl.Series["MainData"].Points[lastHitPointIdx].LabelForeColor = Color.Black; break; case ChartElementType.DataPoint: chartCtrl.Series["MainData"].Points[lastHitPointIdx].MarkerStyle = MarkerStyle.None; break; } HitTestResult result = chartCtrl.HitTest(e.X, e.Y); switch (result.ChartElementType) { case ChartElementType.DataPointLabel: chartCtrl.Series["MainData"].Points[result.PointIndex].LabelForeColor = Color.Red; lastHitPointIdx = result.PointIndex; lastHitElementType = ChartElementType.DataPointLabel; break; case ChartElementType.DataPoint: if (h_Main.ParseInst.isPeak(result.PointIndex)) { chartCtrl.Series["MainData"].Points[result.PointIndex].MarkerStyle = MarkerStyle.Cross; lastHitPointIdx = result.PointIndex; lastHitElementType = ChartElementType.DataPoint; } break; default: lastHitPointIdx = -1; lastHitElementType = ChartElementType.Nothing; break; } }
internal ChartElementType GetChartElementType() { ChartElementType result = ChartElementType.Nothing; switch (ElementType) { case ContextElementTypes.ChartArea: result = ChartElementType.PlottingArea; break; case ContextElementTypes.Series: result = ChartElementType.DataPoint; break; case ContextElementTypes.Axis: result = ChartElementType.Axis; break; case ContextElementTypes.AxisLabel: result = ChartElementType.Axis; break; case ContextElementTypes.Title: result = ChartElementType.Title; break; case ContextElementTypes.Annotation: result = ChartElementType.Annotation; break; case ContextElementTypes.Legend: result = ChartElementType.LegendArea; break; } return(result); }
/// <summary> /// Gets chart child element bounds position in screen coordinates /// </summary> /// <param name="chartElement">Chart child element.</param> /// <param name="chartElementType">Chart child element type.</param> /// <param name="seriesName">Series name.</param> /// <param name="pointIndex">Series data point index.</param> /// <returns>Element boundary in screen coordinates.</returns> public Rectangle GetChildBounds(object chartElement, ChartElementType chartElementType, string seriesName, int pointIndex) { // Make sure we have a valid reference on the chart control Rectangle result = Rectangle.Empty; if (this._chart != null && this._chart.chartPicture != null && this._chart.chartPicture.Common != null && this._chart.chartPicture.Common.HotRegionsList != null) { // Execute chart hit test to initialize list of chart element positions if (this._chart.chartPicture.Common.HotRegionsList.List == null || this._chart.chartPicture.Common.HotRegionsList.List.Count == 0) { this._chart.HitTest(0, 0); } // Find specified chart element in the list foreach (HotRegion hotRegion in this._chart.chartPicture.Common.HotRegionsList.List) { if (hotRegion.Type == chartElementType) { // Determine if region should be processed bool processRegion = false; if (chartElementType == ChartElementType.DataPoint || chartElementType == ChartElementType.DataPointLabel) { // In case of data point and data point label their series name and label should match if (hotRegion.SeriesName == seriesName && hotRegion.PointIndex == pointIndex) { processRegion = true; } } else if (hotRegion.SelectedObject == chartElement || hotRegion.SelectedSubObject == chartElement) { processRegion = true; } if (processRegion) { RectangleF bounds = hotRegion.BoundingRectangle; // Conver chart relative coordinates to chart absolute (pixel) coordinates if (hotRegion.RelativeCoordinates) { RectangleF absolute = RectangleF.Empty; absolute.X = bounds.X * (this._chart.Width - 1) / 100F; absolute.Y = bounds.Y * (this._chart.Height - 1) / 100F; absolute.Width = bounds.Width * (this._chart.Width - 1) / 100F; absolute.Height = bounds.Height * (this._chart.Height - 1) / 100F; bounds = absolute; } // Check if chart should be scaled Rectangle rect = Rectangle.Round(bounds); if (this._chartScale.X != 1f || this._chartScale.Y != 1f) { SizeF rectSize = rect.Size; rect.X = (int)(rect.X * this._chartScale.X); rect.Y = (int)(rect.Y * this._chartScale.Y); rectSize.Width *= this._chartScale.X; rectSize.Height *= this._chartScale.Y; rect.Size = Size.Round(rectSize); } // Convert to screen coordinates if (!this.ChartScreenPosition.IsEmpty) { rect.Offset(this.ChartScreenPosition); } else { rect = this._chart.RectangleToScreen(rect); } // If elementd is not gridlines just return the rectangle if (chartElementType != ChartElementType.Gridlines) { return(rect); } // For gridlines continue accumulation all gridlines positions if (result.IsEmpty) { result = rect; } else { result = Rectangle.Union(result, rect); } } } } } return(result); }
public bool IsChildSelected(object chartChildElement, ChartElementType chartElementType) { // TODO: Not Implemented. Requires Selection Manager code changes. Remove CodeAnalysis.SuppressMessageAttributes return(false); }
public void SelectChild(object chartChildElement, ChartElementType chartElementType, AccessibleSelection selection) { // TODO: Not Implemented. Requires Selection Manager code changes. Remove CodeAnalysis.SuppressMessageAttributes }
public AccessibleObject NavigateFromChild(object chartChildElement, ChartElementType chartElementType, AccessibleNavigation direction) { // TODO: Not Implemented. Requires Selection Manager code changes. Remove CodeAnalysis.SuppressMessageAttributes return(null); }
public static string FormatValue(Chart chart, object obj, double value, string format, ChartValueTypes valueType, ChartElementType elementType) { string text = format; string text2 = ""; if (chart != null && chart.FormatNumberHandler != null) { int elementId = 0; if (obj is DataPoint) { elementId = ((DataPoint)obj).ElementId; } text2 = chart.FormatNumberHandler(obj, value, format, valueType, elementId, elementType); if (text2.Length > 0) { return(text2); } } if (text != null && text.Length > 0) { int num = text.IndexOf('{', 0); if (num >= 0) { while (num >= 0) { if (!text.Substring(num).StartsWith("{0:", StringComparison.Ordinal)) { if (num >= 1 && text.Substring(num - 1, 1) == "{") { continue; } text = text.Insert(num + 1, "0:"); } num = text.IndexOf('{', num + 1); } } else { text = "{0:" + text + "}"; } } switch (valueType) { case ChartValueTypes.DateTime: case ChartValueTypes.Date: case ChartValueTypes.DateTimeOffset: if (text.Length == 0) { text = "{0:d}"; if (valueType == ChartValueTypes.DateTimeOffset) { text += " +0"; } } text2 = string.Format(CultureInfo.CurrentCulture, text, DateTime.FromOADate(value)); break; case ChartValueTypes.Time: if (text.Length == 0) { text = "{0:t}"; } text2 = string.Format(CultureInfo.CurrentCulture, text, DateTime.FromOADate(value)); break; default: { bool flag = false; if (text.Length == 0) { text = "{0:G}"; } try { text2 = string.Format(CultureInfo.CurrentCulture, text, value); } catch (Exception) { flag = true; } if (flag) { flag = false; try { text2 = string.Format(CultureInfo.CurrentCulture, text, (long)value); } catch (Exception) { flag = true; } } if (flag) { return(format); } break; } } return(text2); }
public HitTestResult HitTest (int x, int y, ChartElementType requestedElement) { throw new NotImplementedException (); }
internal void AddHotRegion(RectangleF rectArea, object selectedObject, ChartElementType type, bool relativeCoordinates) { AddHotRegion(rectArea, selectedObject, type, relativeCoordinates, insertAtBeginning: false); }
internal void AddHotRegion(GraphicsPath path, bool relativePath, ChartGraphics graph, ChartElementType type, object selectedObject) { if ((ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions) { HotRegion hotRegion = new HotRegion(); hotRegion.SelectedObject = selectedObject; hotRegion.Type = type; hotRegion.Path = path; hotRegion.BoundingRectangle = path.GetBounds(); hotRegion.RelativeCoordinates = relativePath; regionList.Add(hotRegion); } }
/// <summary> /// Determines whether the chart element type is in scope of a mouse click event. /// </summary> /// <param name="chartElementType">The chart element type</param> /// <returns>bool</returns> public bool Mouse_IsOnChartElement(ChartElementType chartElementType) { return(chartElementType.zIn(ChartElementType.DataPointLabel, ChartElementType.DataPoint, ChartElementType.LegendItem)); }
internal void CheckHotRegions(int x, int y, ChartElementType requestedElement, bool ignoreTransparent, out string series, out int point, out ChartElementType type, out object obj, out object subObj) { obj = null; subObj = null; point = 0; series = ""; type = ChartElementType.Nothing; RectangleF rectangleF = new RectangleF(x - 1, y - 1, 2f, 2f); float x2 = common.graph.GetRelativePoint(new PointF(x, y)).X; float y2 = common.graph.GetRelativePoint(new PointF(x, y)).Y; RectangleF relativeRectangle = common.graph.GetRelativeRectangle(rectangleF); bool flag = false; int num = regionList.Count - 1; HotRegion hotRegion; while (true) { if (num < 0) { return; } hotRegion = (HotRegion)regionList[num]; float x3; float y3; RectangleF rect; if (hotRegion.RelativeCoordinates) { x3 = x2; y3 = y2; rect = relativeRectangle; } else { x3 = x; y3 = y; rect = rectangleF; } if (requestedElement == ChartElementType.Nothing || requestedElement == hotRegion.Type) { flag = false; if (hotRegion.SeriesName.Length > 0 && (common == null || common.Chart.Series.GetIndex(hotRegion.SeriesName) < 0 || hotRegion.PointIndex >= common.Chart.Series[hotRegion.SeriesName].Points.Count)) { if (!common.Chart.IsDesignMode()) { goto IL_0290; } if (common.Chart.Series.GetIndex(hotRegion.SeriesName) > -1 && hotRegion.PointIndex > -1) { flag = true; } } if ((!ignoreTransparent || !IsElementTransparent(hotRegion)) && hotRegion.BoundingRectangle.IntersectsWith(rect)) { bool flag2 = false; if (hotRegion.Path != null) { GraphicsPathIterator graphicsPathIterator = new GraphicsPathIterator(hotRegion.Path); if (graphicsPathIterator.SubpathCount > 1) { GraphicsPath graphicsPath = new GraphicsPath(); while (graphicsPathIterator.NextMarker(graphicsPath) > 0 && !flag2) { if (graphicsPath.IsVisible(x3, y3)) { flag2 = true; } graphicsPath.Reset(); } } else if (hotRegion.Path.IsVisible(x3, y3)) { flag2 = true; } } else { flag2 = true; } if (flag2) { break; } } } goto IL_0290; IL_0290: num--; } if (flag) { series = hotRegion.SeriesName; point = -1; obj = common.Chart.Series[hotRegion.SeriesName]; type = ChartElementType.Nothing; } else { series = hotRegion.SeriesName; point = hotRegion.PointIndex; obj = hotRegion.SelectedObject; subObj = hotRegion.SelectedSubObject; type = hotRegion.Type; } }
internal void AddHotRegion(ChartGraphics graph, RectangleF rectArea, string toolTip, string hRef, string mapAreaAttributes, object selectedObject, object selectedSubObject, ChartElementType type, string series) { if ((ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps && common.ChartPicture.MapEnabled && (toolTip.Length > 0 || hRef.Length > 0 || mapAreaAttributes.Length > 0)) { common.ChartPicture.MapAreas.Add(toolTip, hRef, mapAreaAttributes, rectArea, ((IMapAreaAttributes)selectedObject).Tag); } if ((ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions) { HotRegion hotRegion = new HotRegion(); hotRegion.BoundingRectangle = rectArea; hotRegion.RelativeCoordinates = true; hotRegion.Type = type; hotRegion.SelectedObject = selectedObject; hotRegion.SelectedSubObject = selectedSubObject; if (series != null && series != string.Empty) { hotRegion.SeriesName = series; } regionList.Add(hotRegion); } }
internal void AddHotRegion(ChartGraphics graph, GraphicsPath path, bool relativePath, string toolTip, string hRef, string mapAreaAttributes, object selectedObject, ChartElementType type) { if ((ProcessChartMode & ProcessMode.ImageMaps) == ProcessMode.ImageMaps && common.ChartPicture.MapEnabled && (toolTip.Length > 0 || hRef.Length > 0 || mapAreaAttributes.Length > 0)) { common.ChartPicture.MapAreas.Insert(0, toolTip, hRef, mapAreaAttributes, path, !relativePath, graph); } if ((ProcessChartMode & ProcessMode.HotRegions) == ProcessMode.HotRegions) { HotRegion hotRegion = new HotRegion(); hotRegion.Type = type; hotRegion.Path = path; hotRegion.SelectedObject = selectedObject; hotRegion.BoundingRectangle = path.GetBounds(); hotRegion.RelativeCoordinates = relativePath; regionList.Add(hotRegion); } }
public void draw(MouseEventArgs e) { if (!isDrawing) { return; } //get location on chart var pos = e.Location; //exit if click is not in chart data area ChartElementType cet = ChartHandler.chart.HitTest(pos.X, pos.Y).ChartElementType; switch (cet) { //valid input areas case ChartElementType.Gridlines: case ChartElementType.DataPoint: case ChartElementType.PlottingArea: break; default: return; } var x = ChartHandler.chart.ChartAreas[0].AxisX.PixelPositionToValue(pos.X); //x value is number of bars counting from the right of the graph var y = ChartHandler.chart.ChartAreas[0].AxisY.PixelPositionToValue(pos.Y); //y value translates on to graph directly (no changes necessary) //get closes data point's x value var index = Convert.ToInt32(Math.Round(x)); if (index < 0 || index >= ChartHandler.chart.Series[0].Points.Count) { return; //pevents clicks just inside chart making invalid indices; } var pointIndex = ChartHandler.chart.Series[0].Points[index].XValue; //save raw coordinates used for ghost line before real line is drawn firstPointRawX = (float)e.X; firstPointRawY = (float)e.Y; if (!haveFirstPoint) { firstPointX = pointIndex; firstPointY = y; haveFirstPoint = true; } else { addLine(firstPointX + 1, firstPointY, pointIndex + 1, y); haveFirstPoint = false; //holding shift continues drawing if (Control.ModifierKeys == Keys.Shift) { draw(e); } } }
/// <summary> /// Converts value to string using specified format. /// </summary> /// <param name="chart">Reference to the chart object.</param> /// <param name="obj">Reference to the object being formatted.</param> /// <param name="objTag">Additional object tag.</param> /// <param name="value">Value converted to string.</param> /// <param name="format">Format string.</param> /// <param name="valueType">Value type.</param> /// <param name="elementType">Chart element type being formatted.</param> public static string FormatValue( Chart chart, object obj, object objTag, double value, string format, ChartValueType valueType, ChartElementType elementType) { format = format ?? String.Empty; string convertionFormat = format; string result = ""; // Make sure value index is part of the format if (convertionFormat != null && convertionFormat.Length > 0) { int bracketIndex = convertionFormat.IndexOf('{', 0); if (bracketIndex >= 0) { while (bracketIndex >= 0) { // If format is not followed by the value index if (!convertionFormat.Substring(bracketIndex).StartsWith("{0:", StringComparison.Ordinal)) { // Check charcter prior to the bracket if (bracketIndex >= 1 && convertionFormat.Substring(bracketIndex - 1, 1) == "{") { continue; } else { // Insert value index in format convertionFormat = convertionFormat.Insert(bracketIndex + 1, "0:"); } } bracketIndex = convertionFormat.IndexOf('{', bracketIndex + 1); } } else { convertionFormat = "{0:" + convertionFormat + "}"; } } // Date/time formating if (valueType == ChartValueType.DateTime || valueType == ChartValueType.DateTimeOffset || valueType == ChartValueType.Date) { // Set default format if (convertionFormat.Length == 0) { convertionFormat = "{0:d}"; if (valueType == ChartValueType.DateTimeOffset) { convertionFormat += " +0"; } } // Convert date to string result = String.Format(CultureInfo.CurrentCulture, convertionFormat, DateTime.FromOADate(value)); } else if (valueType == ChartValueType.Time) { // Set default format if (convertionFormat.Length == 0) { convertionFormat = "{0:t}"; } // Convert date to string result = String.Format(CultureInfo.CurrentCulture, convertionFormat, DateTime.FromOADate(value)); } else { bool failedFlag = false; // Set default format if (convertionFormat.Length == 0) { convertionFormat = "{0:G}"; } try { // Numeric value formatting result = String.Format(CultureInfo.CurrentCulture, convertionFormat, value); } catch (FormatException) { failedFlag = true; } // If numeric formatting failed try to format using decimal number if (failedFlag) { failedFlag = false; try { // Decimal value formatting result = String.Format(CultureInfo.CurrentCulture, convertionFormat, (long)value); } catch (ArgumentNullException) { failedFlag = true; } catch (FormatException) { failedFlag = true; } } // Return format string as result (literal) if all formatting methods failed if (failedFlag) { result = format; } } // For the Reporting Services chart a special number formatting // handler may be set and used for all formatting needs. if (chart != null) { // Call number formatter FormatNumberEventArgs eventArguments = new FormatNumberEventArgs(value, format, valueType, result, objTag, elementType); chart.CallOnFormatNumber(obj, eventArguments); result = eventArguments.LocalizedValue; } return(result); }
public HitTestResult HitTest(int x, int y, ChartElementType requestedElement) { throw new NotImplementedException(); }
public void AddHotRegion(RectangleF rectArea, object selectedObject, ChartElementType type, bool relativeCoordinates) { this.AddHotRegion(rectArea, selectedObject, type, relativeCoordinates, false); }