I want to draw a tikzpicture pie chart look with legends look like this:
How do I do that ?
A Schrödinger's cat said, from the pgf-pie manual you can get pretty close to what you ask. Luckily for you I just happen to have done one yersterday.
\documentclass[tikz]{standalone}
\usepackage{pgf-pie}
\begin{document}
\begin{tikzpicture}[]
\pie[text=legend,sum=100,rotate=40,radius=2.5,
before number=\phantom,after number=,
] {
12/{5am -- 11am},
45/{11am -- 5pm},
36/{5pm -- 11pm},
6/{11pm -- 5am}
}
\path[fill=white,draw=black, thick] (0,0) circle (1.5);
\end{tikzpicture}
\end{document}
However, and I don't know why, I can't modify the lines to be of style draw=none not even when using some every path/.append style keys.
Relaxing in the time of Covid-19.
\documentclass[tikz,border=5mm]{standalone}
\usepackage[utf8]{vietnam}
\usepackage{amsmath,amssymb,amsthm}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\def\r{3}
\pgfmathsetmacro{\a}{12*360/100}
\fill[red!70] (0,0) circle(\r);
\fill[orange] (0,0)--(90:\r) arc(90:{90-\a}:\r)--cycle;
\pgfmathsetmacro{\b}{45*360/100}
\fill[lime!80!black] (0,0)--(90-\a:\r) arc(90-\a:{90-\a-\b}:\r)--cycle;
\pgfmathsetmacro{\c}{36*360/100}
\fill[cyan] (0,0)--(90-\a-\b:\r) arc(90-\a-\b:{90-\a-\b-\c}:\r)--cycle;
\fill[white] (0,0) circle(\r/2);
\path (current bounding box.north) node[above=5mm,font=\sffamily]
{Average Daily Activity};
\end{tikzpicture}
\begin{tikzpicture}[rect/.pic={\draw[#1,line width=3mm] (90:.25)--(-90:.25);}]
\matrix (m) [matrix of nodes,
row sep=-\pgflinewidth,
column sep=-\pgflinewidth,
nodes={minimum height=8mm,minimum width=3cm,anchor=center,font=\sffamily,text=black!80},
column 2/.style={nodes={text width=4mm,align=right}},
column 3/.style={nodes={minimum width=2cm,text width=10mm,align=right}},
row 1/.style={nodes={font=\bfseries\sffamily,text width=2cm,text=black,align=center}},
]{
Hours & \% & Total\\
5am - 11am&12&6.158\\
11am - 5pm&45&22.168\\
5pm - 11pm&36&18.015\\
11pm - 5am&6&3.078\\
};
\foreach \i/\icolor in {2/orange,3/lime!80!black,4/cyan,5/red!70}
\draw[gray]
(m-\i-1.north west)--(m-\i-3.north east)
(m-\i-1.west)+(0:.2) pic{rect=\icolor};
\draw[gray]
(m-5-1.south west)--(m-5-3.south east);
\end{tikzpicture}
\end{document}
The wheelchart package, which I wrote, can be used.
The legend is determined by the key legend. This is a tabular which is placed in a \node. The rows are determined by the key legend row. The result of all rows can be obtained with \WClegend.
\documentclass[border=6pt,dvipsnames]{standalone}
\usepackage{wheelchart}
\usepackage{tabularray}
\UseTblrLibrary{counter,siunitx}
\sisetup{group-separator={,},group-minimum-digits=4,text-series-to-math=true}
\begin{document}
\begin{tikzpicture}
\sffamily
\wheelchart[
data=,
legend row={\tikz\fill[\WCvarB] (0,0) rectangle (0.3,0.3); & \WCvarC & \WCvarD & \WCperc & \WCvarA},
legend={
\node[anchor=north] at (0,-2.5) {%
\begin{tblr}[expand=\WClegend]{
colspec={lrlrS[table-format=5.0]},
column{2}={rightsep=0pt},
cell{2-Z}{2}={appto={--}},
column{3}={leftsep=0pt},
row{1}={guard,font=\bfseries}
}
& \SetCell[c=2]{c} Hours & & \SetCell[c=1]{c} \unit{\percent} & Total\\\hline
\WClegend\hline
\end{tblr}%
};
},
radius={1}{2},
title=Average Daily Activity
]{%
6158/BurntOrange/5am/11am,
22168/SpringGreen/11am/5pm,
18015/Cerulean/5pm/11pm,
3078/Maroon/11pm/5am%
}
\end{tikzpicture}
\end{document}