| java.lang.Object de.progra.charting.model.FunctionPlotter
FunctionPlotter | public class FunctionPlotter (Code) | | This class can be used to create a ChartDataModel from a mathematical
function. A Python interpreter implemented in Java is called to calculate
the function values. Therefore, I didn't need to implement a parsing
algorithm. Of course, you need to know the Python syntax for mathematical
functions. The quadratical function 5x2-3x+4 e.g.
would be written as 5*x**2-3*x+4 . Please note, that it takes
approx. 1 s to plot a quadratical function like this computing 2000 single
values.
author: mueller version: 1.0 |
createChartDataModelInstance | public static DefaultChartDataModel createChartDataModelInstance(double lowrange, double highrange, int amount, String function, String[] rows)(Code) | | This method creates a new ChartDataModel from the computed
function data. In order to compute the needed values, a Python script is
created using the provided parameters and is executed afterwards:
String pyfile = "" +
"AMOUNT = "+amount+"\n"+
"columns = []\n"+
"model = []\n"+
"lowrange = "+lowrange+"\n"+
"highrange = "+highrange+"\n"+
"for i in range(AMOUNT) :\n"+
" x = lowrange + i * (float(abs(highrange - lowrange)) / AMOUNT)\n"+
" columns.append(x)\n"+
" model.append("+function+")\n";
interp.exec(pyfile);
Finally the values are extracted via the PythonInterpreter:
pymodel[0] = (double[])interp.get("model", double[].class);
pycolumns = (double[])interp.get("columns", double[].class);
Parameters: lowrange - the lower x-value to begin from Parameters: highrange - the highest x-value to reach Parameters: amount - the amount of values that should be computed (2000 isa good value for smooth curves) Parameters: function - the mathematical function in Python notation Parameters: rows - the array with the DataSet title throws: IllegalArgumentException - if the function contains more than one variable. |
createChartDataModelInstance | public static DefaultChartDataModel createChartDataModelInstance(double lowrange, double hirange, int amount, String function)(Code) | | This method creates a new ChartDataModel from the computed
function data. This implementation automatically uses the function
as DataSet title.
Parameters: lowrange - the lower x-value to begin from Parameters: hirange - the highest x-value to reach Parameters: amount - the amount of values that should be computed (2000 isa good value for smooth curves) Parameters: function - the mathematical function in Python notation |
|
|