Danton
Posts: 5
Joined: Fri Dec 03, 2021 5:02 pm

Custom Indicator - how to set type for new serie ?

Mon Dec 06, 2021 2:42 pm

Hello again,
I'm currently building an indicator, I would like to know how to set the type for the new series. So far I was able to make a working sample with this:

Code: Select all

Highcharts.seriesType(
    "customc",
    "sma",
    {
      name: "CustomC",
      params: {},
    },
    {
      getValues: function (series, params) {
        return this.module_function(series.xData, series.yData);
      },
      getMACD: module_function,
    }
  );
This example gives me the data I made and want with a line type, Is there a way to make it into a bar chart ? I tried to use 'column' instead than 'sma' but it didn't work. Also is there a way to place conditionals on some chart's fields ? for example set the colour of a bar based on the Y values, something like this [ colour: bar.value > 0 ? 'green' : 'red']

mateusz.b
Posts: 1069
Joined: Tue Jul 13, 2021 11:34 am

Re: Custom Indicator - how to set type for new serie ?

Tue Dec 07, 2021 1:05 pm

Hello Danton,

Thanks for contacting us with your question.

First of all, I would recommend reading thoroughly this article: https://www.highcharts.com/docs/stock/c ... indicators
This should give you general idea how to create custom indicator. If you have done it already then in the demo you will find an example of a custom column based indicator. Check the logic behind building such indicator and pay particular attention to data format.
Demo: https://jsfiddle.net/BlackLabel/3j6myau5/

When it comes to changing color conditionally I would suggest in the first place trying color axis: https://api.highcharts.com/highcharts/colorAxis
Another option would be to iterate over all points and update color conditionally. If you want to do that this way then let me know once your indicator is completed and I will show you how to do that.

Let me know if that was what you were looking for!
Regards!
Mateusz Bernacik
Highcharts Developer

Danton
Posts: 5
Joined: Fri Dec 03, 2021 5:02 pm

Re: Custom Indicator - how to set type for new serie ?

Wed Dec 08, 2021 9:30 am

I read that article ( about custom indicators ) and thanks to that I was able to build a functioning example with lines ( without the mistake with the name of the functions, I just realized ). The lack of documentation about the seriesType is a major issue for me, I was able to find its definition on another post in this forum, but I still can't wrap my head around some of its parameters , especially the second ( the series which you inherit from? what exactly do you inherit ? ) and the fourth ( a prototype method for the series ? ) . I was kinda hoping in some sort of an easy and fast solution for my problem, without going to such depth, just for changin a series type at least.
Besides I couldn't find much to some of this attributes in the API, only some references.

Code: Select all

drawGraph: Highcharts.noop,
crispCol: Highcharts.seriesTypes.column.prototype.crispCol,
drawPoints: Highcharts.seriesTypes.column.prototype.drawPoints,
getColumnMetrics: Highcharts.seriesTypes.column.prototype.getColumnMetrics,
translate: Highcharts.seriesTypes.column.prototype.translate
Anyway for the sake of simplicity I will move the computations on the server-side, and load a simple column chart with the data I need. Even though it would have been cool to move those computations on the browser.
For the colorAxis instead that is what I wanted, the dataClasses attribute should do the trick, allowing me to set the ranges that I want. Thanks.

mateusz.b
Posts: 1069
Joined: Tue Jul 13, 2021 11:34 am

Re: Custom Indicator - how to set type for new serie ?

Thu Dec 09, 2021 11:40 am

Hello Danton,

seriesType is depreceated, but we keep using it because of Internet Explorer and its users. Now we move more toward using registerSeriesType function which you can find here: https://github.com/highcharts/highchart ... #L105-L189

When it comes to the documentation and its current state here is related ticket: https://github.com/highcharts/highcharts/issues/15443
You can find there an answer for some of your questions along with fiddle examples. It would be great if you could reopen it and leave your feedback with some suggestions what we could improve and what is especially unclear about these methods. We would really appreciate such feedback.

Glad to hear color axis was what you were looking for.

Feel free to ask any further questions.
Regards!
Mateusz Bernacik
Highcharts Developer

Return to “Highcharts Stock”