I am trying to create a pie chart using GNUPLOT, I already created a chart, and I assigned a color to the legend using an array. This is the code, I used this question as a link
script.sh
set terminal pngcairo nocrop enhanced size 800,400 font "Siemens Sans,8"
set output 'output.png'
filename = 'source.dat'
rowi = 1
rowf = 2
set datafile separator ','
stats filename u 2 every ::rowi::rowf noout prefix "A"
rowf = (rowf-rowi > A_records - 1 ? A_records + rowi - 1 : rowf)
angle(x)=x*360/A_sum
percentage(x)=x*100/A_sum
centerX=0
centerY=0
radius=0.2
yposmin = 0.0
yposmax = 0.95*radius
xpos = 1.5*radius
ypos(i) = yposmax - i*(yposmax-yposmin)/(1.0*rowf-rowi)
set style fill solid 1
unset key
unset tics
unset border
set size ratio -1
set xrange [-radius:2*radius]
set yrange [-radius:radius]
pos = 0
colour = 0
colors = "blue red"
plot filename u (centerX):(centerY):(radius):(pos):(pos=pos+angle($2)):(colour=colour+1) every ::rowi::rowf w circle lc var,\
for [i=0:rowf-rowi] '+' u (xpos):(ypos(i)) w p pt 5 ps 4 lc rgb word(colors,i+1),\
for [i=0:rowf-rowi] filename u (xpos):(ypos(i)):(sprintf('%05.2f%% %s', percentage($2), stringcolumn(1))) every ::i+rowi::i+rowi w labels left offset 3,0
The source file for creating a pie chart is
source.dat
"Tipo","Valor"
"Periodo laboral",723
"Periodo no laboral",81
And when I run the script, I get a file output.pngthat looks like this
output.png

As you can see, the colors of the pie chart do not match the color of the legend. This is because I can easily set the color of the legend thanks to the index for, but to create a pie chart, I repeat through the sentence every, so I can not get the index. I also tried something like:
plot filename u (centerX):(centerY):(radius):(pos):(pos=pos+angle($2)):(colour=colour+1) every ::rowi::rowf w circle lc rgb(word(colors, colour)),\
but I have the following error:
"gnuplot/piechart.sh", 49: : 6 . xyerrorbars
? .
, . (colour=colour+1) plot,
plot filename u (centerX):(centerY):(radius):(pos):(pos=pos+angle($2)):(colour=colour+1) every ::rowi::rowf w circle lc rgb word(colors,colour+1),\
, -, , colours .