答案1
使用 PGFPlots 可以相对轻松地实现这一点。我编写了一个小宏,其调用方式如下:
\bulletgauge[title={\bfseries{\large Revenue}\\1000 USD}]{275}{260}{300,250,150}
创建这个:
可选参数可用于将常规 PGFPlots 选项传递给axis
内部使用的环境。
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots, pgfplotstable}
\definecolor{ylgnbu1}{RGB}{237, 248, 177}
\definecolor{ylgnbu2}{RGB}{127, 205, 187}
\definecolor{ylgnbu3}{RGB}{44, 127, 184}
\pgfplotscreateplotcyclelist{bullet}{
{fill=ylgnbu1, draw=none},
{fill=ylgnbu2, draw=none},
{fill=ylgnbu3, draw=none},
}
\pgfplotstableread[col sep=semicolon]{
Label; Sublabel; Measure; CompMeasure; Range1; Range2; Range3
Revenue 2005 YTD; USD; 260; 255;150;250;300
}\datatable
\newcommand{\bulletgauge}[4][]{
\begin{tikzpicture}
\begin{axis}[
y=1.5ex,
xtick pos=left,
ytick=\empty,
xmin=0, xmax=300,
enlarge y limits={abs=0ex},
tick align=outside,
axis on top,
every axis title/.style={
at={(rel axis cs:0,0.5)},
anchor=east,
align=right,
xshift=-1em
},
#1
]
\pgfplotsinvokeforeach{#4}{
\pgfplotsset{cycle list name=bullet}
\addplot +[xbar, bar width=3ex] coordinates {(##1,0)};
}
\addplot [fill=black, xbar, bar width=1ex] coordinates {(#2,0)};
\addplot [mark=|, mark options={very thick}, mark size=1.25ex] coordinates {(#3,0)};
\end{axis}
\end{tikzpicture}
}
\begin{document}
\bulletgauge[title={\bfseries{\large Revenue}\\1000 USD}]{275}{260}{300,250,150}
\end{document}