I copy the code from Guide to draw charts (basic, pie, bar) from data and customize (just change the data value).
The bar width is too thin so the percentage overlap on each other.
So, I increase the bar width
Then 2 bar on the side of chart go outside (almost half)
How to fix that ?
Here is full source code that cause the problem (picture 2)
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\usetikzlibrary{matrix}
\usetikzlibrary{patterns}
\usepackage{pgfplots}
\title{draw_chart}
\author{Thien Thai}
\date{August 2017}
\begin{document}
\pgfplotstableread[row sep=\\,col sep=&]{
interval & carT & carD & carR \\
0--2 & 51.92 & 50.84 & 51.7 \\
2--5 & 51 & 50.53 & 50 \\
5--10 & 51.53 & 51.51 & 52.46 \\
}\mydata
\begin{tikzpicture}
\begin{axis}[
ybar,
bar width=0.7cm,
width=\textwidth,
height=.5\textwidth,
legend style={at={(0.5,1)},
anchor=north,legend columns=-1},
symbolic x coords={0--2,2--5,5--10},
xtick=data,
nodes near coords,
nodes near coords align={vertical},
ymin=49.5,ymax=53,
ylabel={},
]
\addplot table[x=interval,y=carT]{\mydata};
\addplot table[x=interval,y=carD]{\mydata};
\addplot table[x=interval,y=carR]{\mydata};
\legend{Trips, Distance, Energy}
\end{axis}
\end{tikzpicture}
\end{document}



enlarge x limits. Try e.g.enlarge x limits={abs=0.5}. – Torbjørn T. Aug 30 '17 at 14:48axisoptions, e.g. right afterylabel={},– Torbjørn T. Aug 30 '17 at 16:13bar width=.8cmandenlarge x limits={abs=2*\pgfplotbarwidth}. Additional remark: setcompatforpgfplots:\usepackage{pgfplots}directly followed by\pgfplotsset{compat=1.15}(1.15 is the current version) or\pgfplotsset{compat=newest}. – esdd Aug 30 '17 at 16:27