Although sketch recognition has been studied for dozens of years, the recognition of two dimensional online documents is still a challenging problem of pattern recognition. This paper deals with this problem depending on the logical structure of the sketch and a graph grammar. The recognition process consists of three stages. First, we use the dynamic programming to group the stroke sequence into stroke combinations. Then, we get the candidate symbols from a classifier of the Random Forest algorithm. Finally, a graph grammar is used to describe the logical structure of the flowchart. This method has been applied to flowcharts of a freely available database. Although 23.2% of the candidate symbols are misclassified, we still achieve an average accuracy of 70.4%, which demonstrate the effectiveness and efficiency of our approach.