The XY to Line tool:
Creates a new feature class containing geodetic line features... ...A
geodetic line is a curve on the surface of the earth. However, a
geodetic line feature is not stored as a parametric (true) curve in
the output, but as a densified polyline representing the path of the
geodetic line. If the length of a geodetic line is relatively short,
it may be represented by a straight line in the output. As the length
of the line increases, more vertices are used to represent the path.
So in short, it doesn't pay any attention to your existing lines or network. It simply draws a line from the start to the end. Even if you were to snap the points generated from your coordinate pairs to the network (because if GPS points it's unlikely they are - that's map-matching), the resulting lines won't necessarily follow those roads.
Network Analyst Approach
Lines between two points on a network (at least in Network Analyst) are called routes. In order to generate a route, you need three things - a network (the lines/edges/roads and junctions), origin points, and destination points. Creating a clean network for analysis can be time consuming if you don't already have one. From there you run a solver that generates the routes based on network criteria (speed limits, time to travel, length, etc.).
In your case each record of your data is a matched start and end point. They'd have to be split and converted to actual point features to be used as inputs. Then you'd have to run a solver to create the route lines, and because you have specifically matching points there's only two ways to do this (that I know of):
- Iteratively, using the simple route solver and running it over and over again for each start and end point sharing a common ID.
- All at once with the closest facility solver, which will generate routes from every start point to every end point (not one to one match; ten of each will generate 100 routes), which you then have to filter down by selecting only routes whose start and end point ID match. Note that the Origin Destination Cost Matrix solver does not generate lines that follow the network.
There are questions here that have more detailed answers to both approaches. With the routes generated, you could join them to your original table to get the speed attribute transferred and then symbolize on that.
Right now you have a bunch of points that may or may not fall right on the road network lines. You could snap them to the network first in hopes of improving the lines generated from them, or you could just generate the lines as you have and snap those to the network lines. And by snap I mean the Snap GP tool. Another option is the Align to Shape tool. Unfortunately I don't see many ArcGIS questions specific to map-matching.
If you're having trouble "matching to the graph or snapping to road", I would suggest a new question specifically focused on that topic, and explain in detail what steps you have tried, tools you have used, and what did or didn't work.
You could also use your start/end points to cut up your network lines, but you're looking at a lot of dissolving and merging and cleanup probably to get that to work. You could also look at using a Spatial Join between your lines and roads. Another method to consider would be linear referencing.
As a quick summary, sometimes things that sound simple up front are actually relatively complex problems. I don't know exactly how Google does it under the hood, but it's a network based display of data. By which I mean they start with the network lines, and then either using the existing edges of the network (which may be split at strategic points to create pseudo-nodes or just run from junction to junction) or linear referencing, they can assign current speeds to those segments from traffic sensors/data.
Based on the data you have and the progress you've been able to make so far, I think the simplest solution will be to explore snapping or matching up the line segments you've created to the road network data. Essentially you've done what you needed, you just need to clean the resulting linework up to match the roads.
A couple of related/similar questions where aligning lines/tracks to a network is a component of the question/solution (and be sure to explore the Linked or Related questions on the right side of the page when you look at a question):