Often encounter situations where you are given a few points and asked to find patterns or the like. Polynomial functions are a very important modeling tool. Using any number of points, you can fit a polynomial function. By using the polynomial function to derive the function values of other points, and then drawing the function curve, this is the most basic principle, very simple!
- First, Fit through points to obtain the functional relationship of the fitted polynomial (a JavaScript method), during the fitting process, record the intermediate generated two-dimensional array, used for subsequent calculation of chart values;
- Second, Convert the obtained set relationship into the expression of the polynomial function, such as x*x*x + a*x*x + b*x +c;
- Third, Calculate the maximum and minimum values of x among the given fitting points, calculate the gap = max - min, and then take the range (min - 0.3 * gap, max + 0.3 * gap) as the x-axis range for drawing the chart;
- Fourth, Set the number of chart drawing points to 1000, then take 1000 equidistant x values in the range (min - 0.3 * gap, max + 0.3 * gap), calculate the corresponding y values through the function, and then get x_data_array, y_data_array;
- Fifth, With 1000 data points for x and y axes, you can use echarts to draw the function, line chart smooth curve, and then see the polynomial function curve;
For the source code of echarts, please click here .