Okay
  Public Ticket #3570544
Trying to add a Trendline to my existing HighStock Chart
Closed

Comments

  • Shanda started the conversation

    I am trying to add a trendline series to an existing chart using the callback. But when I try to use the obj.options.series [], it replaces my existing series with only the new one. How can I add a new series without losing the ones that are there?

    https://api.highcharts.com/highstock/series.trendline

    function highStockChartCallback(obj) {
    //this takes the existing series and adds an ID to the series so I can add a treadline to it. This works as expected.

    if (obj.options.series && obj.options.series.length >= 2) {
        // Sanitize and update IDs for the first two series
        obj.options.series[0].id = obj.options.series[0].name.replace(/[^a-zA-Z0-9]/g, '');
        obj.options.series[1].id = obj.options.series[1].name.replace(/[^a-zA-Z0-9]/g, '');

    }

    //this doesn't work. It removes both series above and only adds this trendline. 

    obj.options.series = [
      {
        type: 'trendline',
        linkedTo: 'obj.options.series[0].id',
       
      }

    ];

    }

    wpDataChartsCallbacks[22] = highStockChartCallback;



  •  1,689
    Miloš replied

    Hi Shanda,

    Firstly, I would like to sincerely apologize for the delayed response as we have been experiencing an unusually high number of tickets. I am sorry that it has taken longer than usual to respond to your concern and your patience is highly appreciated.

    -

    I am sorry, but for this specific use-case, we did not try something like that yet, so i can't show you an exact example how you can achieve it.

    We will show you some other Custom Chart Callback examples, though, and I will do my best to provide as many details as possible that might be useful.


    Every chart engine has its own layout and its settings.

    We use free libraries for chart engines, and they are limited as to what we can change from within the plugin's UI.

    You can check out all the available chart engines and examples of wpDataCharts documentation here . 

    If the options you need are not in the chart creation wizard,  you can try to find a custom solution using chart callbacks.

    You can check our documentation about wpDataCharts callbacks

    • Every chart exposes several options that customize its look and feel. Charts usually support custom options appropriate to that visualization. wpDataChart callbacks allow adding options that are available in Google Charts APIHighcharts API, and Chart.js API
    • All necessary resources are available in charts engines API (depends on which one you use). Every engine has a different approach to chart settings. In wpDataChart callbacks, you have to adopt those settings to the wpDataChart object (you can take a look at examples for each engine in our documentation, and also in the Support help center). A huge number of examples for any area of programming can be found on stackoverflow.com (typing your problem in google and at the end add "site: stackoverflow.com" and Google will search only that website). Also, a lot of examples of charts, chart settings, and customization can be found on jsffidle.net (typing in google for example "line chart highcharts jsffidle")
    • Please note that using hooks or wpDataTable and wpDataChart callbacks requires a certain level of programming skills and included support refers only to advice.



    Kind Regards, 

    Miloš Jovanović
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables