Custom Function

The wijmo.chart.analytics module contains two classes that allow you to plot arbitrary functions without explicitly generating data points:

  1. YFunctionSeries: Series based on a function that provides Y values as a function of X values within a given range.
  2. ParametricFunctionSeries: Series based on functions that provides X and Y values as a function of domain values within a given range.
import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; import * as wjChart from '@grapecity/wijmo.chart'; import * as wjChartAnalytics from '@grapecity/wijmo.chart.analytics'; // document.readyState === 'complete' ? init() : window.onload = init; // function init() { // create the chart let theChart = new wjChart.FlexChart('#theChart'); // // create a YFunctionSeries and add it to the chart let yFun = new wjChartAnalytics.YFunctionSeries(); yFun.name = 'y = f(x)'; yFun.min = -10; yFun.max = 10; yFun.sampleCount = 300; yFun.func = (x) => Math.sin(4 * x) * Math.cos(3 * x); theChart.series.push(yFun); // // create a ParametricFunctionSeries and add it to the chart let pFun = new wjChartAnalytics.ParametricFunctionSeries(); pFun.name = 'x = f(t); y = g(t)'; pFun.min = 0; pFun.max = 2 * Math.PI; pFun.sampleCount = 1000; pFun.xFunc = (t) => 10 * Math.cos(5 * t); pFun.yFunc = (t) => Math.sin(6 * t); theChart.series.push(pFun); } <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Custom Function</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <div id="theChart"></div> </div> </body> </html> .wj-flexchart { height: 250px; margin: 10px 0; } body { margin-bottom: 24pt; } import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './styles.css'; // import { Component, enableProdMode, NgModule } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { BrowserModule } from '@angular/platform-browser'; import { WjChartModule } from '@grapecity/wijmo.angular2.chart'; import { WjChartAnalyticsModule } from '@grapecity/wijmo.angular2.chart.analytics'; // @Component({ selector: 'app-component', templateUrl: 'src/app.component.html' }) export class AppComponent { max = 2 * Math.PI; // yFunc(x: number) { return Math.sin(4 * x) * Math.cos(3 * x); } // paramXFunc(t: number) { return 10 * Math.cos(5 * t); } // paramYFunc(t: number) { return Math.sin(6 * t); } } // @NgModule({ imports: [WjChartModule, WjChartAnalyticsModule, BrowserModule], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } // enableProdMode(); // Bootstrap application with hash style navigation and global services. platformBrowserDynamic().bootstrapModule(AppModule); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexGrid Custom Function</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Polyfills --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.min.js"></script> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.js"></script> <script src="systemjs.config.js"></script> <script> // workaround to load 'rxjs/operators' from the rxjs bundle System.import('rxjs').then(function (m) { System.set(SystemJS.resolveSync('rxjs/operators'), System.newModule(m.operators)); System.import('./src/app.component'); }); </script> </head> <body> <app-component></app-component> </body> </html> <div class="container-fluid"> <wj-flex-chart> <wj-flex-chart-y-function-series name="y = f(x)" [min]="-10" [max]="10" [sampleCount]="300" [func]="yFunc"> </wj-flex-chart-y-function-series> <wj-flex-chart-parametric-function-series name="x = f(t); y = g(t)" [min]="0" [max]="max" [sampleCount]="1000" [xFunc]="paramXFunc" [yFunc]="paramYFunc"> </wj-flex-chart-parametric-function-series> </wj-flex-chart> </div> .wj-flexchart { height: 250px; margin: 10px 0; } body { margin-bottom: 24pt; } <template> <div class="container-fluid"> <wj-flex-chart> <wj-flex-chart-y-function-series name="y = f(x)" :min=-10 :max=10 :sampleCount=300 :func="yFunc"> </wj-flex-chart-y-function-series> <wj-flex-chart-parametric-function-series name="x = f(t); y = g(t)" :min=0 :max="max" :sampleCount=1000 :xFunc="paramXFunc" :yFunc="paramYFunc"> </wj-flex-chart-parametric-function-series> </wj-flex-chart> </div> </template> <script> import '@grapecity/wijmo.styles/wijmo.css'; import 'bootstrap.css'; import Vue from 'vue'; import '@grapecity/wijmo.vue2.chart'; import '@grapecity/wijmo.vue2.chart.analytics'; // new Vue({ el: '#app', data: { max: 2 * Math.PI }, methods: { yFunc(x) { return Math.sin(4 * x) * Math.cos(3 * x); }, paramXFunc(t) { return 10 * Math.cos(5 * t); }, paramYFunc(t) { return Math.sin(6 * t); } } }); </script> <style> .container-fluid .wj-flexchart { height: 250px; margin: 10px 0; } body { margin-bottom: 24pt; } </style> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>GrapeCity Wijmo FlexChart Custom Function</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app.vue'); </script> </head> <body> <div id="app"></div> </body> </html> import 'bootstrap.css'; import '@grapecity/wijmo.styles/wijmo.css'; import './app.css'; // import * as React from 'react'; import * as ReactDOM from 'react-dom'; // import * as wjChart from '@grapecity/wijmo.react.chart'; import * as wjChartAnalytics from '@grapecity/wijmo.react.chart.analytics'; // class App extends React.Component { constructor(props) { super(props); this.yFunc = (x) => { return Math.sin(4 * x) * Math.cos(3 * x); }; this.paramXFunc = (t) => { return 10 * Math.cos(5 * t); }; this.paramYFunc = (t) => { return Math.sin(6 * t); }; this.state = { max: 2 * Math.PI }; } render() { return <div className="container-fluid"> <wjChart.FlexChart> <wjChartAnalytics.FlexChartYFunctionSeries name="y = f(x)" min={-10} max={10} sampleCount={300} func={this.yFunc}> </wjChartAnalytics.FlexChartYFunctionSeries> <wjChartAnalytics.FlexChartParametricFunctionSeries name="x = f(t); y = g(t)" min={0} max={this.state.max} sampleCount={1000} xFunc={this.paramXFunc} yFunc={this.paramYFunc}> </wjChartAnalytics.FlexChartParametricFunctionSeries> </wjChart.FlexChart> </div>; } } ReactDOM.render(<App />, document.getElementById('app')); <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>AutoComplete</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div id="app"></div> </body> </html> .wj-flexchart { height: 250px; margin: 10px 0; } body { margin-bottom: 24pt; }