locked
How to insert image in chart RRS feed

  • Question

  • Hello everyone I am using MSCHART I want insert image on 0 point I have 3 Axis x,x1,y Please help me to do this... I have shown image to get better understand.. please tell me any property to do this.... immediately
    Friday, February 6, 2015 10:52 AM

Answers

  • Is this what you want?

    Imports System.Windows.Forms.DataVisualization.Charting
    
    Public Class Form5
    
        Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Chart1.Series.Clear()
    
            With Chart1.ChartAreas(0)
                .AxisX.Interval = 2
                .AxisX.MajorGrid.LineColor = Color.LightGray
                .AxisX.Minimum = 0
                .AxisX.Maximum = 10
                .AxisX.Title = "X Axis"
    
                .AxisY.Interval = 2
                .AxisY.Minimum = -10
                .AxisY.Maximum = 10
                .AxisY.Title = "Y Axis"
    
                Chart1.Series.Clear()
                Chart1.Series.Add("")
    
                With Chart1.Series(0)
                    .IsVisibleInLegend = False                   'dont show series legent upper right
                    'create the chart data
                    For m = 1 To 9
                        .Points.AddXY(m, m)
                    Next
                End With
            End With
        End Sub
    
        Private Sub Chart1_PostPaint(sender As Object, e As ChartPaintEventArgs) Handles Chart1.PostPaint
            'get the control coords of 0, 0
            Dim x As Single = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.X, 0))
            Dim y As Single = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.Y, 0))
    
            'convert to model
            Dim point1 As PointF = New Point(x, y)
            point1 = e.ChartGraphics.GetAbsolutePoint(point1)
    
            'draw the bitmap
            Dim bmp As Bitmap = New Bitmap("c:\bitmaps\monkey1.gif")
            Dim destRect As Rectangle = New Rectangle(point1.X, point1.Y - 100, 100, 100)
            Dim sourceRect As Rectangle = New Rectangle(0, 0, bmp.Width, bmp.Height)
            e.ChartGraphics.Graphics.DrawImage(bmp, destRect, sourceRect, GraphicsUnit.Pixel)
        End Sub
    End Class


    • Proposed as answer by Youjun Tang Monday, February 9, 2015 5:25 AM
    • Marked as answer by Youjun Tang Friday, February 13, 2015 9:14 AM
    Friday, February 6, 2015 5:15 PM

All replies

  • Is the image supposed to have chart lines drawn over it?

    La vida loca

    Friday, February 6, 2015 3:29 PM
  • Is this what you want?

    Imports System.Windows.Forms.DataVisualization.Charting
    
    Public Class Form5
    
        Private Sub Form5_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Chart1.Series.Clear()
    
            With Chart1.ChartAreas(0)
                .AxisX.Interval = 2
                .AxisX.MajorGrid.LineColor = Color.LightGray
                .AxisX.Minimum = 0
                .AxisX.Maximum = 10
                .AxisX.Title = "X Axis"
    
                .AxisY.Interval = 2
                .AxisY.Minimum = -10
                .AxisY.Maximum = 10
                .AxisY.Title = "Y Axis"
    
                Chart1.Series.Clear()
                Chart1.Series.Add("")
    
                With Chart1.Series(0)
                    .IsVisibleInLegend = False                   'dont show series legent upper right
                    'create the chart data
                    For m = 1 To 9
                        .Points.AddXY(m, m)
                    Next
                End With
            End With
        End Sub
    
        Private Sub Chart1_PostPaint(sender As Object, e As ChartPaintEventArgs) Handles Chart1.PostPaint
            'get the control coords of 0, 0
            Dim x As Single = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.X, 0))
            Dim y As Single = CSng(e.ChartGraphics.GetPositionFromAxis(Chart1.ChartAreas(0).Name, AxisName.Y, 0))
    
            'convert to model
            Dim point1 As PointF = New Point(x, y)
            point1 = e.ChartGraphics.GetAbsolutePoint(point1)
    
            'draw the bitmap
            Dim bmp As Bitmap = New Bitmap("c:\bitmaps\monkey1.gif")
            Dim destRect As Rectangle = New Rectangle(point1.X, point1.Y - 100, 100, 100)
            Dim sourceRect As Rectangle = New Rectangle(0, 0, bmp.Width, bmp.Height)
            e.ChartGraphics.Graphics.DrawImage(bmp, destRect, sourceRect, GraphicsUnit.Pixel)
        End Sub
    End Class


    • Proposed as answer by Youjun Tang Monday, February 9, 2015 5:25 AM
    • Marked as answer by Youjun Tang Friday, February 13, 2015 9:14 AM
    Friday, February 6, 2015 5:15 PM
  • thank u tommytwotrain...
    Tuesday, February 10, 2015 5:23 AM