Apple Intelligence now features Image Playground, Genmoji, Writing Tools enhancements, seamless support for ChatGPT, and visual intelligence.

Apple Intelligence has also begun language expansion with localized English support for Australia, Canada, Ireland, New Zealand, South Africa, and the U.K. Learn more >

You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

AppleScript numbers charts

I have written a script that updates a table with a row of two columns, the date in column 1 and a number in column 2.


I have a line chart next to it I’m trying to update the new data into the chart through the script.

i can’t seem to find anything on the web that gets me in the right direction.


can it be done and how

Posted on Mar 10, 2020 12:38 PM

Reply
4 replies

Mar 10, 2020 8:41 PM in response to Jon Lopiano

Can you post a screenshot of your chart where you have clicked on it and Edit Data References? Also, perhaps, your AppleScript?


For example, here is a screenshot from the 'Charting Basics' template at File > New in your menu:



Note that the chart there is set up to automatically accommodate new rows in the data table.


That works fine with a simple AppleScript like this:


tell front document of application "Numbers"
	tell active sheet
		tell table 1 to set newRow to add row below last row
		tell newRow
			set value of cell 1 to 100
			set value of cell 2 to 80
		end tell
	end tell
end tell



Giving this result (which includes the new data point):




If you substitute dates into the first column in the table you should get a similar result. Note that although this is 2D Scatter plot you can easily add connecting lines between the data points if you want, so it looks something like this:



The AppleScript I used here was the same as above except that I used the line


			set value of cell 1 to "2020-01-11"



SG



Mar 11, 2020 5:23 AM in response to SGIII

I tried reworking the script a bit for structure (thought it might help) but with the changes I made it is still not working as expected. I still will create a row and add the data two them, but the Count column which is where it gets the data for the graph isn't updated to the graph. Here is what I got for scripting and an pic of the graph (I ran the script then took a screen shot to visulaize the problem


tell application "Numbers"

tell document 1's sheet 2's table 1

set newrow to add row below last row

tell newrow

set the value of cell 1 to datetext

set the value of cell 2 to keywordCount

end tell

--add row below last row

--tell last row

--set the value of the first cell to datetext

--set the value of the last cell to keywordCount

--end tell

---set dataset to (the value of cells of column "B")

--group by "row"

end tell

end tell

Thanks

Mar 11, 2020 7:59 AM in response to Jon Lopiano

I got the expected result here after running the script:




Before inserting a chart did you first select ALL the cells (A1:B2) in the table? That way, when you add rows to the table (either manually or via script) the chart will reference the entire columns including the new rows.


BTW, if your dates are always evenly spaced then you can use a "category" chart (2D Line) like the one in your last post. If your dates are unevenly spaced, though, you might consider using a 2D Scatter instead (as in the 'Charting Basics' template in the screenshot of my previous post). If you decide on a 2D Scatter then you need to make sure the first column is NOT a Header Column.


SG


Mar 10, 2020 6:00 PM in response to Jon Lopiano

Hi Jon,


I'm assuming the script is working properly, and is not the issue here.


Numbers charts take their data from a specified set of cells. To get the new data onto the chart, you need to expand that range to include the cells containing the new data cells.


You can avoid the need to change the range every time you enter a new date-number pair by including several extra and empty) rows.


The chart will expand to include these data points, but won't show any values until there is data entered in a row.


BTW: A "line chart" is a Category chart. Each entered date is treated as a Category, not as a number or quasi-numeric value.

Data for March 1, March 2, March 7, March 9 and March 10 will be evenly spaced. If the time between samples is significant, consider using an XY scatter chart, with dates on the x axis and number values on the Y axis, and using straight line connections between data points. The X location of the data points will then be spaced according to the number of days between each entry.using the list above, the left-right spacing would look like this (Ignore the date labels, as Numbers would use calculated dates evenly spread in time and evenly spaced along the axis):


    x         x                                                     x                     x           x

Mar 1, Mar 2,                                            Mar 7,             Mar 9, Mar 10


And the slope of the lines connecting those data points would be a more precise representation of 'change over time.


Regards,

Barry

AppleScript numbers charts

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.