如何向 graphviz 图形节点添加颜色?

如何向 graphviz 图形节点添加颜色?

这是我当前拥有的图表的代码:

graph Budget {
    Country_Budget -- Profit_and_Loss_Account  [type=s];
    Country_Budget -- Balance_Sheet [type=s];
     Profit_and_Loss_Account -- Income [type=s];
     Profit_and_Loss_Account -- Expenditure [type=s];
     Income -- Revenue_Income [type=s];
     Income -- Capital_Income [type=s];
     Expenditure -- Revenue_Expenditure [type=s];
     Expenditure -- Capital_Expenditure [type=s]; 
     Balance_Sheet -- Assets [type=s]; 
     Balance_Sheet -- Liabilities [type=s];
}

这是使用 dotty 工具时的渲染 -

国家预算的粗略草图

虽然它提供了细节和结构,但有人知道如何让它变得更加丰富多彩吗?

在 Debian 上运行 graphviz 2.38.0-16。

答案1

你可以这样做:

graph Budget {
   subgraph tier1 {
      node [color="lightgreen",style="filled",group="tier1"]
      Country_Budget
   }
   
   subgraph tier2 {
      node [color="green",style="filled",group="tier2"]
      Profit_and_Loss_Account
      Balance_Sheet
   }
   
   subgraph tier3 {
      node [color="lightblue",style="filled",group="tier3"]
      Income
      Expenditure
      Assets
      Liabilities
   }
   
   subgraph tier4 {
      node [color="yellow",style="filled",group="tier4"]
      Revenue_Income
      Capital_Income
      Revenue_Expenditure
      Capital_Expenditure
   }
   
   Country_Budget -- {Profit_and_Loss_Account Balance_Sheet}
   Profit_and_Loss_Account -- {Income Expenditure}
   Income -- {Revenue_Income Capital_Income}
   Expenditure -- {Revenue_Expenditure Capital_Expenditure}
   Balance_Sheet -- {Assets Liabilities}
}

示例输出

相关内容