Linear wireless sensor networks (LWSNs) are a specialized topology of wireless sensor networks (WSNs) widely used for environmental monitoring. Traditional WSNs rely on batteries for energy supply, limiting their performance due to battery capacity constraints, while renewable energy harvesting technology is an effective approach to alleviating the battery capacity bottleneck. However, the stochastic nature of renewable energy makes designing an efficient energy management scheme for network performance improvement a compelling research problem. In this paper, we investigate the problem of maximizing throughput over a finite-horizon time period for an energy harvesting-based linear wireless sensor network (EH-LWSN). The solution to the original problem is very complex, and this complexity mainly arises from two factors. First, the optimal energy allocation scheme has temporal coupling, i.e., the current optimal strategy relies on the energy harvested in the future. Second, the optimal energy allocation scheme has spatial coupling, i.e., the current optimal strategy of any node relies on the available energy of other nodes in the network. To address these challenges, we propose an iterative energy allocation algorithm for EH-LWSN. Firstly, we theoretically prove the optimality of the algorithm and analyze the time complexity of the algorithm. Next, we design the corresponding distributed version and consider the case of estimating the energy harvest. Finally, through experiments using a real-world renewable energy dataset, the results show that the proposed algorithm outperforms the other two heuristics energy allocation schemes in terms of network throughput.