# How to get a range / sub graph of a line chart on runtime?

Bar Code for WPF Forum

Posted 6 months ago by Nerd22
Version: 22.1.4 €: Oops, I accidently wrote this in the wrong forum. I'm sorry.

Hello there,

I'm using C#, .NET Framework 4.8 (WPF) and I would like to know how to get a sub graph or range of a given graph?

Let's say, I build a graph of 20 points, where:

X = {0,1,...,19}

Y = random numbers in a range of (-20,20)

The graph would start on {0,-12}, and continues with {1,13}, {2,9}, ..., {19,0}.

I would like to get a sub graph in the range between 5 and 15, where {5,2} might be the new start point and ends on {15,-6}.

That is my idea:

``````public List<Coordinates> GetSubGraph(int startPos, int endPos) {
List<Coordinates> subGraph = new List<Coordinates>();

for(int i = startPos; i < endPos; i++) {
Coordinates c = LineGraph.ElementAt(i);
}

return subGraph;
}``````

followed by:

``````// clear old graph
chartX.Series.Clear();

// this shall create the new graph
ItemsSource = ViewModel.GetSubGraph(5, 15)
});

//  refreshing
chartX.Refresh();``````

There're no errors on runtime, however, the graph won't be displayed as expexted.

I only see a "graph" from 5 to 15, where each Y point is fixed on 1.

What do I miss?

Thank you (:

[Modified 6 months ago]

Answer - Posted 6 months ago by Nerd22 I guess, I found the solution randomly.

``````private void HandleAreas(AreaSection section) {
//chartX.Series.Clear();                     //not needed
List<Coordinates> subGraph = ViewModel.GetSubGraph(5, 15);

//chartX = new XYChart();                    //nope
ItemsSource = subGraph,
XPath = "X",
YPath = "Y",
LineKind = XYSeriesLineKind.Spline
});

chartX.Refresh();
}``````

Now I'm able to display the expected sub graph. :o)

The latest build of this product (v23.1.0) was released 2 months ago, which was after the last post in this thread.