When developing an accessible online database for storing the results of calculations, there was an overwhelming desire to present information not only in tabular form, but also in the form of graphs. You can go in different ways, for example, to draw curves in PHP, but more correctly (in the sense of the UNIX-way) you will use an external program that already knows how to build graphs, such as Gnuplot .#!/usr/bin/gnuplot set terminal canvas set output "output.html" plot sin(x) with lines 
set terminal canvas enhanced mousing set output "output.html" set xlabel 'Time' set ylabel 'Energy' plot sin(4*x)/x with lines linewidth 2 
<script src="/usr/share/gnuplot/gnuplot/4.6/js/gnuplot_common.js"></script> set terminal canvas enhanced mousing jsdir 'js' 
<?php // : $path = $_GET['path']; // user-friendly , $fullpath = "/srv/calculations/".$path."/"; // $nSites = $_GET['nsites']; // - '' $fSite = 1; // '' if (isset($_POST["fSite"])) { $fSite = $_POST["fSite"]; } // echo '<a href=index.html>Back</a>'; echo '<h1>Plot Calculation Data</h1>'; echo '<form id="form_plots" method="post" action=plot_calc.php?path='.$path.'&nsites='.$nSites.'>'; echo ' <input id="plotProb" type="submit" name="plotProb" value="Prob" />'; echo ' <input id="plotEnergy" type="submit" name="plotEnergy" value="Energy" />'; // ... echo ' <label>Site number to plot</label>'; echo ' <input id="fSite" name="fSite" type="text" value='.$fSite.' />'; echo '</form>'; if (isset($_POST["plotProb"])) { // plotProb $input='./plot_calc.sh'.' '.'p '.$nSites.' '.$fullpath.' '.$fSite; echo "Probability plot for Site #".$fSite; } if (isset($_POST["plotEnergy"])) { // plotEnergy $input='./plot_calc.sh'.' '.'E '.$nSites.' '.$fullpath.' '.$fSite; echo "Energy plot for Site #".$fSite; } // ... $output = shell_exec($input); // echo $output; // echo '</body>'; echo '</html>'; ?> #!/bin/bash # : # 1 - # 2 - # 3 - # 4 - ( p) # -------------- # # E energy # p probaility # .... #------------------------------# # : TFILE="/tmp/$(basename $0).$$.gp" # gnuplot: echo "# Automatically generated Gnuplot script " > $TFILE echo "set terminal canvas enhanced mousing jsdir 'js'" >> $TFILE ### Probability ### if [ $1 == 'p' ] then echo "set xlabel 'Time'">>$TFILE echo "set ylabel 'Probability'">>$TFILE let icol=$4+1 echo "plot '$3prob.res' u 1:$icol wi li">>$TFILE fi # ... ### Energy ### if [ $1 == 'E' ] then let col=$4*2 let col1=$4*2+1 echo "set xlabel 'Time'">>$TFILE echo "set ylabel 'Energy'">>$TFILE echo "plot '$3Energ.res' u 1:$col:$col1 wi err">>$TFILE fi /usr/bin/gnuplot $TFILE chmod +x plot_calc.sh # Automatically generated Gnuplot script set terminal canvas enhanced mousing jsdir 'js' set xlabel 'Time' set ylabel 'Probability' plot '/srv/calculations/GoodCalc/prob.res' u 1:6 wi li 
crontab -e 0 */1 * * * rm -v /tmp/plot*.gp >> /var/log/rmplotgp.log Source: https://habr.com/ru/post/248383/
All Articles