Question

I have written code which plot graph. Now I need to add trendline to that graph. When i tried it. It gives below error.

Traceback (most recent call last):
  File "C:\Users\jmp655972\Desktop\Python\test_1.py", line 87, in <module>
    trend.DisplayEquation = True
AttributeError: 'instancemethod' object has no attribute 'DisplayEquation'

Code:

worksheets = workbook.Sheets(1) chart= worksheets.Shapes.AddChart(72) print (chart)      
worksheets.ChartObjects(1).Chart.HasTitle = True                                                                                           worksheets.ChartObjects(1).Chart.ChartTitle.Text = "Testing Samples" 
trend =worksheets.ChartObjects(1).Chart.SeriesCollection(1).Trendlines().Add
trend.DisplayEquation = True
Was it helpful?

Solution

I'm going to make my comment an answer because it solved the problem. That way, it can help any future visitors to this page.

You need to invoke Add by placing () after it:

trend =worksheets.ChartObjects(1).Chart.SeriesCollection(1).Trendlines().Add()
#                                                                     here--^

Now, trend points to what it should, namely the return value of the Add method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top