Excel VBA How to draw a line in a graph

0 votes

Please view this image to get my clearly question: enter image description here

Mar 23 in Database by Edureka
• 13,640 points
79 views

1 answer to this question.

0 votes

Sub MakeChart()

    Dim x(20) As Variant
    Dim y(20) As Variant
    Dim i     As Long
    
    For i = 0 To 20
        x(i) = i * 2
        y(i) = 2 * Sin(i / 5)
    Next
 
    Charts.Add
    
    With ActiveChart
        .ChartType = xlLineMarkers
        .HasTitle = True
        .ChartTitle.Text = "Plot from Array"
        
        With .Axes(xlCategory, xlPrimary)
            .HasTitle = True
            .AxisTitle.Characters.Text = "X"
        End With
        
        .SeriesCollection.NewSeries
        With .SeriesCollection(1)
            .XValues = x
            .Values = y
            .Trendlines.Add
            .Trendlines(1).DisplayEquation = True
            .Name = "Y"
        End With
    
    End With
    
End Sub
That draws a curve then fits a trend line to it.

If you replace the loop at the start of the code that populates the arrays with your code to get the data it should do what you want.
answered Mar 24 by gaurav
• 13,560 points

Related Questions In Database

0 votes
0 answers

How to loop in excel without VBA or macros?

Is it possible to iterate (loop) a ...READ MORE

Mar 30 in Database by Edureka
• 13,640 points
188 views
0 votes
1 answer

How to enter a series of numbers automatically in Excel

Excel, unlike other Microsoft Office programmes, does ...READ MORE

answered Apr 4 in Database by Edureka
• 13,640 points
25 views
0 votes
0 answers

How to split a string of text in excel based on a given word?

I have a list of combinations of ...READ MORE

Apr 4 in Database by gaurav
• 13,560 points
49 views
0 votes
1 answer

How to do a batch insert in MySQL

You can try out the following query: INSERT ...READ MORE

answered Sep 10, 2018 in Database by Sahiti
• 6,380 points
1,665 views
0 votes
1 answer

How to cache data in a MVC application?

Reference the System.Web dll in your model ...READ MORE

answered Oct 25, 2018 in Database by Frankie
• 9,830 points
951 views
0 votes
1 answer

How to display the queries executed by a particular user in MySQL?

From the version 5.1.7 onward, MySQL allows ...READ MORE

answered Mar 7, 2019 in Database by Mishti
• 480 points
1,580 views
0 votes
2 answers
0 votes
2 answers

How to select the nth row in a SQL database table?

SELECT * FROM ( SELECT ID, NAME, ROW_NUMBER() ...READ MORE

answered Apr 23, 2020 in Database by anand
• 140 points
16,250 views
0 votes
1 answer

Convert a number to a letter in C# for use in Microsoft Excel [duplicate]

If you are familiar with using formulas ...READ MORE

answered Feb 23 in Database by gaurav
• 13,560 points
44 views
0 votes
1 answer

How to sort dates from Oldest to Newest in Excel?

Drag down the column to select the ...READ MORE

answered Feb 23 in Database by gaurav
• 13,560 points
51 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP