Plotting Data Using XOJO Native Graphing Tools

I recently posted about this but was unclear so posting again for clarity. I want to use XOJOs native Desktop Chart tools to plot data. I have two lists, one of time values, and one of values of f(t). I want to plot points of the form (t,f(t)). Here is the code I have so far, which is not working at all, and I know will not work. I am not sure how to make each f(t) value correspond to a time value in XOJO.

Var GraphData() As Double
Var TimeData() As String

Var n as integer = ChartArray.LastIndex(2)
Var j as integer = GraphChoicePopupMenu.SelectedRowIndex

for i as integer = 0 to n
GraphData.add(ChartArray(j,i))
TimeData.Add(ChartArray(0,i).ToString)
next

MainGraphDataChart.Title = “Graph of” +GraphChoicePopupMenu.SelectedRowText
MainGraphDataChart.Mode = DesktopChart.modes.Line
MainGraphDataChart.GridColor = Color.Clear

Var ds As New ChartLinearDataset(GraphChoicePopupMenu.SelectedRowText, Color.red, True, GraphData)
ds.ChartType = ChartLinearDataset.ChartTypes.Line

MainGraphDataChart.AddDatasets ds

Can you find a chart similar of what you want searching in Google? or can you draw one up?
I’m not sure the native chart can handle what you want (because you posted on your other thread that you want to chart “will have over 600,000 elements”)

Maybe if you attach an example project instead of just code would help to understand better what you want to achieve :+1:

i think basically you have one x axis the time, and each datapoint have a value y?

data(x)=value
whereby each x have a datetime label in the chart

with a database/query you could select average,min,max,sum for a timespan.

What I’m not seeing here is:

MainGraphDataChart.AddLabels TimeData

I have a similar need. I think what he was getting at is how to plot a line graph when you have a time series consisting of unevenly spaced TIMES and the corresponding VALUES. For line charts Xojo seems to assume that all points are evenly spaced along the X axis. One workaround is to use a scatter plot so you can provide BOTH X and Y coordinates and then use the line style to connect the dots.

Look at DesktopChart.Modes.Scatter and add a line there. The Line chart is just for Categorical X axis. Scatter does true X Y charts and can use lines, symbols etc.

Here is a demonstration of the Chart control that I use for DAQ (Data Acquisition) on the Raspberry Pi with electronics.

SS1080Forum(1)_edit_0

The Xojo file has been zipped and is called: SS1080-ForumSeconds-Ver3.zip. This program dynamically shows the time that has elapsed with a random number generator creating data to show the user how this displays the data.

This is on Xojo 2026r2.1, written on Windows 11.

Is this what you were looking for to answer your original question?

SS1080-ForumSeconds-Ver3.zip (7.6 KB)