Plotting Data from two lists

Very simple question: I have two arrays, one which contains time values, and one that contains values of f(t). I want to use XOJO’s native graphing tools for this, could someone provide me with some code that would work. This is what I am doing now which is not working:

Var ds As New ChartLinearDataset(“Sales”, Color.Blue, True, GraphData)
Var ds1 As New ChartLinearDataset(“Sales”, Color.Blue, True, TimeData)
MainGraphDataChart.AddDataset(ds)
MainGraphDataChart.AddDataset(ds1)

One of the examples that comes with Xojo has this code:

Me.Title = "UK Pound to Dollar / Euro Exchange Rate Over the Years"
Me.Mode = DesktopChart.modes.Bar
Me.GridColor = Color.Clear

Var dollar() As Double = Array(1.65, 1.56, 1.49, 1.25, 1.33, 1.27, 1.30, 1.35, 1.32, 1.22)
Var euro() As Double = Array(1.21, 1.26, 1.42, 1.19, 1.14, 1.12, 1.17, 1.11, 1.19, 1.13)

Me.AddLabels Array("2013", "2014", "2015", "2016", "2017", "2018", "2019", "2020", "2021", "2022")

Var dsInflaction As New ChartLinearDataset("Dollar", Color.red, True, dollar)
Var dsTemp As New ChartLinearDataset("Euro", Color.blue, True, euro)
dsInflaction.ChartType = ChartLinearDataset.ChartTypes.Bar
dsTemp.ChartType = ChartLinearDataset.ChartTypes.Bar

Me.AddDatasets dsInflaction, dsTemp

Me could be MainGraphDataChart for you.

As your code is not the complete code, we don’t know if something that you didn’t post here is missing.

Thank you for the response, but I have not been able to completely solve my issue.
Here is the complete code:

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

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))
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

I know the above code won’t work but I am not sure how to fix it. GraphData and TimeData each will have over 600,000 elements, I want to plot points on the graph of the form (TimeData(i),GraphData(i)). Is there a way to make each point in graph data correspond to a time value and then plot this?

Thanks again.

I can imagine plotting this amount of data being slow, and you won’t be able to distinguish between 600000 and (as a guess) 600 plotted data points.

Once you get the graph working, maybe you could consider this.

Julen

2 Likes