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, 2022 in Database by Edureka
• 13,690 points
2,050 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, 2022 by gaurav
• 23,260 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, 2022 in Database by Edureka
• 13,690 points
2,396 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, 2022 in Database by Edureka
• 13,690 points
715 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, 2022 in Database by gaurav
• 23,260 points
446 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,370 points
2,317 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
1,833 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
4,365 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
26,265 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, 2022 in Database by gaurav
• 23,260 points
836 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, 2022 in Database by gaurav
• 23,260 points
5,231 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP