Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing type for transform regression. #35

Open
y0nd0 opened this issue Apr 3, 2021 · 25 comments
Open

Missing type for transform regression. #35

y0nd0 opened this issue Apr 3, 2021 · 25 comments

Comments

@y0nd0
Copy link

y0nd0 commented Apr 3, 2021

How to use transform regression in echarts (ngx-echarts) TypeScript? Missing type?

import * as echarts from 'echarts';
import * as ecStat from 'echarts-stat';
echarts.registerTransform(ecStat.transform.regression);

image

ecStat.d.ts

// node_modules\echarts-stat\src\ecStat.d.ts

declare namespace EChartsStat {
  type InputData = Array<Array<number>>;
  type OutputData = Array<Array<number>>;

  interface HistogramBins {
    bins: Array<HistogramBinsBin>;
    data: OutputData;
    customData: OutputData;
  }
  interface HistogramBinsBin {
    x0: number;
    x1: number;
    sample: Array<number>;
  }
  function histogram(
    data: Array<number>,
    binMethod: 'squareRoot' | 'scott' | 'freedmanDiaconis' | 'sturges'
  ): HistogramBins;

  namespace clustering {
    interface Result {
      centroids: OutputData;
      clusterAssment: OutputData;
      pointsInCluster: OutputData;
    }
    function hierarchicalKMeans(
      data: InputData,
      clusterNumer: number,
      stepByStep: boolean
    ): Result;
    function kMeans(data: InputData, clusterNumer: number): Result;
  }

  interface RegressionResult {
    points: OutputData;
    expression: string;
    gradient: number;
    intercept: number;
  }
  function regression(
    regreMethod: 'linear' | 'exponential' | 'logarithmic' | 'polynomial',
    data: InputData,
    order: number
  ): RegressionResult;

  namespace statistics {
    function deviation(data: Array<number>): number;
    function sampleVariance(data: Array<number>): number;
    function quantile(data: Array<number>, p: number): number;
    function max(data: Array<number>): number;
    function mean(data: Array<number>): number;
    function median(data: Array<number>): number;
    function min(data: Array<number>): number;
    function sum(data: Array<number>): number;
  }
}

declare module 'echarts-stat' {
  export = EChartsStat;
}

Goal: https://echarts.apache.org/examples/en/editor.html?c=scatter-linear-regression

{
    "echarts": "^5.0.2",
    "echarts-stat": "^1.2.0",
    "ngx-echarts": "^6.0.1",
}
@GreedyPirate
Copy link

same issue, @100pah Is there a solution? @y0nd0 have you solved the problem?

@dvago
Copy link

dvago commented Jun 15, 2021

@y0nd0 @GreedyPirate this way works for me:

import { transform } from 'echarts-stat'

echarts.registerTransform(transform.regression)

which is even better 'cause you don't need to import the whole ecStat package if you are going to use just one transformation.

@nico-campa
Copy link

same issue, there is no 'transform' available from echarts-stat package

my packages versions :
"echarts": "^5.2.0",
"echarts-stat": "^1.2.0",
"ngx-echarts": "^7.0.1",

anyone solved the problem ?

@coader
Copy link

coader commented Oct 11, 2021

any news? the same problem

@CDFO2
Copy link

CDFO2 commented Oct 11, 2021

same issue, any suggestions please

@CDFO2
Copy link

CDFO2 commented Oct 11, 2021

@y0nd0 @GreedyPirate this way works for me:

import { transform } from 'echarts-stat'

echarts.registerTransform(transform.regression)

which is even better 'cause you don't need to import the whole ecStat package if you are going to use just one transformation.

there is no 'transform' available from echarts-stat package.
Which version do you use please? @dvago

@dvago
Copy link

dvago commented Oct 11, 2021

@CDFO2

"echarts": "^5.1.2",
"echarts-stat": "^1.2.0",

@CDFO2
Copy link

CDFO2 commented Oct 11, 2021

@dvago
I'm having below versions.

    "echarts": "^5.2.1",
    "echarts-stat": "^1.2.0",

I've tried downgrading echarts to 5.1.2, but then its giving following error.

Property 'registerTransform' does not exist on type 'typeof echarts'

@dvago
Copy link

dvago commented Oct 11, 2021

@CDFO2 are you importing the library as:

import * as echarts from 'echarts'

Note: the above is bad practice but it's a work around.

@CDFO2
Copy link

CDFO2 commented Oct 11, 2021

@dvago
Yes, following exactly the same as mentioned here.

import * as echarts from 'echarts';

import ecStat from 'echarts-stat';

var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;
echarts.registerTransform(ecStat.transform.regression);

@dvago
Copy link

dvago commented Oct 12, 2021

@CDFO2 I would try with this and see what happens:

import * as echarts from 'echarts';
import { transform } from 'echarts-stat';

echarts.registerTransform(transform.regression);

var myChart = echarts.init(document.getElementById('main'));
var option; // whatever option you want to pass
myChart.setOption(option);

This sequence (importing the library, registering the transformation and init the chart) has been provided by one of the library maintainer a few months ago.

I'm not fully sure if this helps out 'cause the error says
"echarts doesn't contain the function registerTransform so you can't call it" (this method is not even documented within echarts website https://echarts.apache.org/en/api.html#echarts)

I've been raising a proposal and this guy opened an issue related to this registerTransform but it still open: #15124

@nflux-pyang
Copy link

Any update for the transform problem?

@davidcanonieto
Copy link

Come on guys! when are you going to fix this?

@maneetgoyal
Copy link

A fix would be really helpful!!

@maneetgoyal
Copy link

maneetgoyal commented Feb 17, 2022

Resorting to module augmentation till a fix is available:

import type { ExternalDataTransform } from "@manufac/echarts-simple-transform";

/**
 * Needed because of: https://github.com/ecomfe/echarts-stat/issues/35
 * Module augmentation: https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation
 */
declare module "echarts-stat" {
  let transform: {
    regression: ExternalDataTransform;
    histogram: ExternalDataTransform;
    clustering: ExternalDataTransform;
  };
}

Took some hints from #41 as well.

@tlianglstyle
Copy link

tlianglstyle commented Mar 8, 2022

temporary solution:
const ecStatLocal: any = ecStat; echarts.registerTransform(ecStatLocal.transform.regression);

or:#41

@macchif
Copy link

macchif commented Aug 29, 2022

I had the same issue and i found this solution:

I replaced
import ecStat from 'echarts-stat';
with
import * as ecStat from 'echarts-stat';

and
echarts.registerTransform(ecStat.transform.regression);
with
echarts.registerTransform(ecStat['transform'].regression);

in this way everything works as it should, but I have no idea of the reason why.

Anyway I hope it helps ;)

@hwebb
Copy link

hwebb commented Jan 14, 2023

The above doesn't work anymore because of TypeScript, you can try this instead:

import { registerTransform } from 'echarts';

import * as ecStat from 'echarts-stat';

registerTransform((ecStat as any).transform.regression);

@0aryan
Copy link

0aryan commented Feb 4, 2023

Found Another way of implementing in Angular

Run Register Transform inside lifecycle hook.


import * as echarts from 'echarts'
import * as ecStat from 'echarts-stat';


 ngOnInit () : void {
echarts.registerTransform((ecStat as any).transform.regression);
}

@echodis
Copy link

echodis commented Feb 4, 2023 via email

@dcantu96
Copy link

import { transform } from 'echarts-stat'

this should be the correct solution, the current solutions are not tree shakeable

@oleksandr-kupenko
Copy link

oleksandr-kupenko commented Sep 8, 2023

If you are interested in regression, you can use my script. I took and rewrote several files from the library and now I don’t need to install the entire library. This solved the problem with imports.
Most likely it will not work in strict typescript mode. But in normal mode everything works.

https://github.com/oleksandr-kupenko/echarts-stat-regression

@echodis
Copy link

echodis commented Sep 8, 2023 via email

@kraisorna
Copy link

temporary solution: const ecStatLocal: any = ecStat; echarts.registerTransform(ecStatLocal.transform.regression);

or:#41

this works. i imported the ecStat and change it to any type. and follow the rest.

import * as ecStat from 'echarts-stat';

const ecStatLocal: any = ecStat;
echarts.registerTransform(ecStatLocal.transform.histogram);

@yuexiliuli
Copy link

临时解决方案: const ecStatLocal: any = ecStat; echarts.registerTransform(ecStatLocal.transform.regression);

或:#41

It's useful,thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests