I used a LineChart because Trendlines only work on Scatter Charts, Bar Charts, Column Charts, and Line Charts.
Sorry, I should have explained that in my answer. I also don't have PHP installed so what I did was use a query to open the CSV file after I rewrote the dates. The complete code I used is at https://brisray.com/test/jose.htm (which is where the screenshot came from) and the CSV file is at https://brisray.com/test/jose.csv <https://brisray.com/test/jose.csv> On Monday, May 1, 2023 at 2:12:51 AM UTC-4 José Vicente Zahonero wrote: > Hi, I have tried changing the format of the dates to 'yyyy-MM-dd' in the > csv and I have added the code you have indicated but it doesn't show me any > average line in the graph. > [image: Captura_001.png] > > El lunes, 1 de mayo de 2023 a las 1:41:03 UTC+2, Ray Thomas escribió: > >> The quickest way is to add a trendline to the graph. Add this something >> like this under your series statements in the options secion: >> >> trendlines: { >> 0:{type: 'linear', color: 'yellow', visibleInLegend: true, >> lineWidth:2}, >> 1:{type: 'linear', color: 'yellow', visibleInLegend: true, >> lineWidth:2}, >> 2:{type: 'linear', color: 'yellow', visibleInLegend: true, >> lineWidth:2}, >> 3:{type: 'linear', color: 'yellow', visibleInLegend: true, >> lineWidth:2} >> }, >> >> Trendlines do not work on discrete data such as strings, so you have to >> change your CSV file to the preferred date format which for a CSV file is >> yyyy-MM-dd or do it in the datatable. The trendline help is at >> https://developers.google.com/chart/interactive/docs/gallery/trendlines >> >> [image: jose-trendlines.jpg] >> >> Trendlines are not averages, so if you really need those you need to >> create new columns in the datatable and calculate them yourself. The >> example in the ComboChart help at >> https://developers.google.com/chart/interactive/docs/gallery/combochart >> uses the averages of the row data but you need it for the column data. So >> you'll need 4 new columns, one for each of the current columns, and each of >> the new columns will contain all the same number, the column averages. >> >> Another method of getting the averages is to use the aggregation method. >> The help for that is at >> https://developers.google.com/chart/interactive/docs/reference#data-manipulation-methods. >> >> Because that depends on grouping the data, you are going to need a new >> column containing a single value in all the rows so they can be grouped >> together. How to use this properly has come up fairly often so there are >> examples on Stack Overflow. Here are some: >> >> >> https://stackoverflow.com/questions/58417507/how-to-draw-an-average-column-in-google-charts-bar-chart >> >> https://stackoverflow.com/questions/50004379/draw-a-line-to-show-the-average-distribution-in-google-scatter-plot >> >> https://stackoverflow.com/questions/35918308/average-line-for-current-data-in-a-google-combochart >> >> I don't know who WhiteHat is, but they certainly know their way around >> the API. >> >> On Saturday, April 29, 2023 at 3:59:39 AM UTC-4 José Vicente Zahonero >> wrote: >> >>> Hi, I have an area chart in which I represent some values taken from a >>> csv file. I would like to be able to add the averages corresponding to each >>> column to the graph, can you help me? >>> My code is in the attached file. Thanks for you help. >>> >> -- You received this message because you are subscribed to the Google Groups "Google Visualization API" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/34116f22-c34c-439e-871c-0acc0bc3f8cfn%40googlegroups.com.