By James Ramage

The dollar rallied broadly on Tuesday, driven by a recent flurry of upbeat economic data in the U.S. that's bolstered some investors' confidence in the growth outlook.

The greenback soared to a nearly eight-year high against the Japanese yen, a one-month high against the euro and a six-week high against the Canadian dollar. The buck also rallied against many emerging-market currencies, hitting its highest level against the Brazilian real in nearly two months and against the Indonesian rupiah since mid-March.

The dollar's strength carried over from Friday, when inflation data for April underscored a pickup in growth and Federal Reserve Chairwoman Janet Yellen said the central bank was on track to raise short-term benchmark interest rates this year. Most U.S. financial markets were closed on Monday for the Memorial Day holiday, and currency trading was subdued.

On Tuesday, the release of data showing gains in business investment, the housing market and consumer confidence added fuel to the dollar's rally. Data from earlier in the year was also revised higher.

"As you get better data, you're getting more people thinking we'll see a recovery, which is good for the dollar," said Charles St-Arnaud, economist and currencies strategist for Nomura Securities.

Tuesday's sharp appreciation in the dollar is the latest big swing to ruffle foreign-exchange markets. An eight-month dollar rally sputtered in March when the Fed lowered its forecast for growth and benchmark interest rates in the coming years after the U.S. economy hit a soft patch. That sowed doubts among investors who were betting that the Fed would strike a tightening stance while other central banks pursued easing policies. Higher rates make a currency more attractive for investors.

The dollar's rise sent ripples through commodity markets. Prices of crude oil, gold, copper and grains tumbled on Tuesday, pushing the S&P GSCI down 2% to a four-week low.

The greenback rallied to its biggest one-day gain against the yen since Feb. 6, jumping to as high as JPY123.33, the highest level since July 2007.

Against the euro, the dollar appreciated as much as 1%, climbing to a one-month high of $1.0864. Some traders said worries that Greece would default on its debt were exerting downward pressure on the common currency.

The dollar's strength came against a selloff in U.S. stocks. Some market watchers said that reflected concerns about higher rates. "The data spooked investors a little bit," said James Hosker, director of equities strategy in the Americas at Societe Generale. "Equities investors don't want to see interest rates climbing too quickly."

Recent gains in the buck are unlikely to propel the dollar to the kinds of gains it saw in the second half of 2014 and the start of 2015, said Axel Merk, chief investment officer of Merk Investments, which has about $400 million under management. Traders are still trying to gauge whether the U.S. economy is on sound footing, so new data points bring on renewed volatility, Mr. Merk said.

"I'm not buying that we have this resurgence right now," he said. "I'm not sure the rally has too [much support]. Whenever the dollar surges, people jump on that story. And as the dollar weakens, people jump on that story, too.

"It won't be a clear shot upward here," Mr. Merk added. "I expect some back and forth in the dollar's move."

Many still expect the dollar to appreciate against other currencies, but hedge funds and other money managers have pared bullish bets in the past two months, according to the U.S. Commodity Futures Trading Commission. The net amount of investor funds making bets in the futures market that the dollar would strengthen declined 10% to $26 billion in the week ended May 19 from the previous week.

The Commerce Department on Tuesday reported disappointing durable-goods orders, but currency traders looked past the headline number to focus on a proxy for business investment, which rose for the second month in a row in April. Orders for nondefense capital goods, excluding aircraft, rose 1% in April, while the March reading was revised up to 1.5% from 0.1%.

New-home sales in April rose by a bigger-than-expected 6.8% from March to a seasonally adjusted annual rate of 517,000.

An index of U.S. consumer confidence rose more than expected in April, and March's reading was also revised upward.