It depends on what we mean by "graffiti." If we're just talking about writing on trains, you would probably say around 1920/1930. If we're talking about graffiti "art," then freight train writing started shortly after the advent of modern graffiti in 1965. It did start in the United States, which also happens to be where modern graffiti was invented, but freight writing really picked up in the 80s. I’m going to rely almost exclusively on essays from the Routelage Handbook of Graffiti and Street Art here, which is considered one of the most essential anthologies in the study of graffiti’s history, especially when it comes to trains.
If you’re curious about the earliest acts of vandalism related to trains, we have evidence going back to the 1920s and 30s that hobos (and in a few cases, railroad workers themselves) regularly wrote on, and in, railway cars. Often they’d write their nickname, the date, a short limerick, or a note about a certain location. This was often done with oil paint, but they’d carve into surfaces inside and outside of the train as well. Still, the emphasis was rarely on any artistic element. In John F. Lennon’s essay “Trains, Railroad Workers, and Illegal Riders,” he posits that a lot of ethnographic evidence points towards boredom as the main cause for the vandalism. A hobo is constantly travelling from location to location, and they’re going to end up with a lot of time on their hands while they’re riding the trains. There’s a plethora of “canvas space” in an empty train car, and with no other way to pass the time, it makes sense that many transients would scrawl on the wall of a freight car.
We do have artistic examples of railroad graffiti from people like Bozo Texino, but the emphasis on the aesthetic or artistic elements doesn’t come until the 60s and 70s. Even then, much of this “hobo art” is extremely rudimentary and it’s clear that impulse was mainly to “leave a mark,” and not on making art.
As far as artistic graffiti writing though, train painting (public transit, not freight) was popular from the beginning when artistic graffiti was taking off in the 70s. For one, most graffiti writers were young and lived in major cities, like New York or Chicago. As a result, they were riding a fair number of trains to begin with. There’s a second impulse here too—if you paint trains, your work literally travels. A graffiti writer working in their neighborhood may only become infamous in their surrounding area. If they paint a train though, writers in Queens could reasonably become familiar with writers from Brooklyn and vice versa. Painting trains was just a popular way for writers to expose people to their work, and this practice has been around since the beginning of modern graffifti writing. When it comes to freight trains, writers started seeking them out in large numbers in the 80s and 90s (there was big jump to freight trains in 1986—more on that later), and most of these artists came to specialize in freight cars. In “The History of Freight Train Graffiti in North America,” Robert Weide points out that “Not all graffiti writers participate in freight train graffiti…conversely, many who do participate in the freight train graffiti subculture commit themselves primarily to this particular graffiti medium” (36). There are a few reasons a graffiti writer may make the jump from street bombing (painting walls in a city) to freight painting. For one, it’s less stressful. If you go out and paint in a city, you have to watch out for cops, gang members, and other unpleasant denizens of the night. A freight yard is typically secluded, quiet, and much easier to navigate without being harassed. If a writer is more interested in painting intricate, complicated pieces, they’d probably be attracted to freights where they can take their time without having to run away from a perceived threat in the middle of their work. If you go to a railyard at night, the odds are high there you wouldn’t run into anyone (as a note, with cameras and security popping up in many urban railyards today, many writers now travel 10-20 miles outside of a city to paint freights). The other motivating factor is the knowledge that your work is going to travel all over the country. A graffiti artist working exclusively in Brooklyn is unlikely to be discovered by writers outside of Brooklyn, but a freight car can travel thousands and thousands of miles until it’s taken out of service. This holds an allure for many writers whose main goal is to become infamous among other artists in the subculture. The final key here is that freight car companies don’t generally paint over graffiti (although they will “stamp” a portion of the car if a graffiti writer covers the car’s identifying numbers, but even then, they wouldn’t cover the entire thing and your work would still be mostly legible). Union Pacific, for example, makes money by transporting goods, so it’s completely immaterial to them if a writer has painted over part of the car. They just have no reason to remove it. It also helps that freight cars happen to be fairly uniform and flat, which makes them quite easy to paint.
As a final note, in 1986, New York City really started cleaning up train graffiti. This is generally the year where we see a big jump in the number of freight painters. As Weide points out, “thanks to the implementation of a new kind of subway car in New York,” graffiti could be removed “with a quick chemical wash.” This is also the year a number of new security measures were implemented that made painting public transit cars extremely risky. Thus, Weide argues, “the golden age of subway graffiti had ended, but new subcultural niches blossomed in the graffiti subculture in North America as a result.” Some writers switched to drawing on stickers, others started painting more abandoned buildings, while one group moved over the freight train. As their work traveled all over the country, writers in other parts of the US took note and saw how much sense it would make to start painting freights.