答案1
像这样吗?
\documentclass[tikz,border=3,14159]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[mynode/.style={circle, draw, minimum width=1cm},node distance=2cm]
\newcommand{\progbar}[2]
{
\def\h{1}
\def\l{0.3}
\fill[red] ($(#1)-(0.5*\l,0)$) rectangle ++ (\l,#2*0.01*\h);
\draw ($(#1)-(0.5*\l,0)$) rectangle ++ (\l,\h);
\node[above] at ($(#1)+(0,\h)$) {#2\,\%};
}
\node[mynode] (1) {1};
\node[mynode,right of=1] (2) {2};
\draw[-stealth] (1)--(2);
\coordinate[left=1cm] (A) at (1.south);
\coordinate[right=1cm] (B) at (2.south);
\def\va{25} %<--------- define here the value for node 1
\progbar{A}{\va};
\pgfmathtruncatemacro\vb{100-\va}
\progbar{B}{\vb};
\end{tikzpicture}
\end{document}
编辑
如果您想以十进制形式查看数字(如果您谈论的是概率,这很有意义),则需要进行一些调整:
\documentclass[tikz,border=3,14159]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[mynode/.style={circle, draw, minimum width=1cm},node distance=2cm]
\newcommand{\progbar}[2]
{
\def\h{1}
\def\l{0.3}
\fill[red] ($(#1)-(0.5*\l,0)$) rectangle ++ (\l,#2*0.01*\h);
\draw ($(#1)-(0.5*\l,0)$) rectangle ++ (\l,\h);
\pgfkeys{/pgf/number format/.cd,fixed,precision=2}
\pgfmathparse{0.01*#2}\edef\storeresult{\pgfmathresult}%
\node[above] at ($(#1)+(0,\h)$) {\pgfmathprintnumber\storeresult};
}
\node[mynode] (1) {1};
\node[mynode,right of=1] (2) {2};
\draw[-stealth] (1)--(2);
\coordinate[left=1cm] (A) at (1.south);
\coordinate[right=1cm] (B) at (2.south);
\def\va{84} %<--------- define here the value for node 1
\progbar{A}{\va};
\pgfmathtruncatemacro\vb{100-\va}
\progbar{B}{\vb};
\end{tikzpicture}
\end{document}