Home Forums WinForms controls Xceed Chart for WinForms Chart pixel location within ChartControl

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #19246 |

    I need to be able to access the coordinates of the Chart within a ChartControl object. Do I have to do all the math myself, dealing with percentage-based margins and chart model dimensions, or can I access the pixel-based chart location and size somewhere?

    Imported from legacy forums. Posted by Paul (had 833 views)

    User (Old forums)
    Member
    Post count: 23064

    For anyone else in my situation, here’s the math that I used to get coordinates for the first chart within ChartControl1. Keep in mind this only works for NumericScale and LogarithmicScale axes, and FixedPageSize and no paging mode (i.e., using a zoom tool and not), since those are the different axis scale types and paging modes that I use in my solution, and will give you chart bounds within the chart control itself; you will need to translate those bounds by the chart control location if you want to deal with the mouse or other controls within those bounds.

     

    Dim x1 As Double, x2 As Double, y1 As Double, y2 As Double

    Dim v1 As New Vector, v2 As New Vector

    Dim tempV As Vector

    With ChartControl1.Charts(0)

    With .Axis(StandardAxis.PrimaryX)

    Select Case .Ruler.PagingMode

    Case RulerPagingMode.FixedPageSize

    x1 = .Ruler.CurrentPageBeginValue

    x2 = x1 + .Ruler.PageSize

    Case RulerPagingMode.None

    If .ScaleMode = AxisScaleMode.Numeric Then

    x1 = .NumericScale.Min

    x2 = .NumericScale.Max

    ElseIf .ScaleMode = AxisScaleMode.Logarithmic Then

    x1 = .LogarithmicScale.Min

    x2 = .LogarithmicScale.Max

    End If

    End Select

    End With

    With .Axis(StandardAxis.PrimaryY)

    Select Case .Ruler.PagingMode

    Case RulerPagingMode.FixedPageSize

    y1 = .Ruler.CurrentPageBeginValue

    y2 = y1 + .Ruler.PageSize

    Case RulerPagingMode.None

    If .ScaleMode = AxisScaleMode.Numeric Then

    y1 = .NumericScale.Min

    y2 = .NumericScale.Max

    ElseIf .ScaleMode = AxisScaleMode.Logarithmic Then

    y1 = .LogarithmicScale.Min

    y2 = .LogarithmicScale.Max

    End If

    End Select

    End With

    tempV = New Vector(.Axis(StandardAxis.PrimaryX).ConvertScaleToModelCoordinate(False, x1), _

    .Axis(StandardAxis.PrimaryY).ConvertScaleToModelCoordinate(False, y1), 0)

    .ConvertModelToViewportCoordinate(tempV, v1)

    tempV = New Vector(.Axis(StandardAxis.PrimaryX).ConvertScaleToModelCoordinate(False, x2), _

    .Axis(StandardAxis.PrimaryY).ConvertScaleToModelCoordinate(False, y2), 0)

    .ConvertModelToViewportCoordinate(tempV, v2)

    End With

    Dim chartBounds As New Rectangle(Math.Min(v1.x, v2.x), Math.Min(v1.y, v2.y), Math.Abs(v1.x – v2.x), Math.Abs(v1.y – v2.y))

    Imported from legacy forums. Posted by Paul (had 894 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.