almost works

almost works

vbierschwalevbierschwale Posts: 9Questions: 2Answers: 0

I found this example
https://datatables.net/blog/2020/highcharts-integration#Charting-with-Data-Processing
Works great, but it uses averaging, so if you look at the value for the year 2009 in my example, this should be a negative number.
https://guestworkervisas.com/oescalculate.php?oes=47-0000&submit4=Submit
How do I correct that?
Thank You,
Virgil

Answers

  • kthorngrenkthorngren Posts: 21,629Questions: 26Answers: 5,010

    This code is used to build the sums and remvoe extra characters like the $ and ,:

                    +table
                        .cell(indexes[i], 3)
                        .data()
                        .replace(/[^0-9.]/g, ''),
    

    It also removes the - for the negative number as it is only looking for characters 0 through 9 and .. Update both regex expressions to also include the dash (it needs escaped with the backslash. Something like this:

                    +table
                        .cell(indexes[i], 3)
                        .data()
                        .replace(/[^0-9.\-]/g, ''),
    

    Kevin

  • vbierschwalevbierschwale Posts: 9Questions: 2Answers: 0

    Thanks, I'm getting better with your product, but still have a long way to go.

  • vbierschwalevbierschwale Posts: 9Questions: 2Answers: 0

    That did take care of that portion of the problem, but the chart does not show the negative amount.
    It only shows the positive amounts.
    What should I look study to help me decipher this stuff.
    I'm a old school programmer, so I can figure out most, but I struggle on this.

  • vbierschwalevbierschwale Posts: 9Questions: 2Answers: 0

    ok, never mind, I figured it out, and thank you for your help

  • kthorngrenkthorngren Posts: 21,629Questions: 26Answers: 5,010

    Glad you got it working.

    Kevin

  • vbierschwalevbierschwale Posts: 9Questions: 2Answers: 0

    I'm trying to add in a second column.
    I have it added to the datatable

    How do I add a second bar?
    Been looking for examples, but it is hard to find them with datatables in the example code format.

    https://guestworkervisas.com/oescalculate.php?oes=15-0000&submit4=Submit

    The right column, in the top datatable.

  • kthorngrenkthorngren Posts: 21,629Questions: 26Answers: 5,010
    edited February 2

    I would start by looking at the Highcharts column chart docs. Look at the JSFiddle or Codepen example for the type of chart you want. Looks like you need an array of objects defining each series, from the example:

        series: [
            {
                name: 'Corn',
                data: [387749, 280000, 129000, 64300, 54000, 34300]
            },
            {
                name: 'Wheat',
                data: [45321, 140000, 10000, 140500, 19500, 113500]
            }
        ]
    

    Instead of a single object for the series, in example you have this:

       var series = {
            name: 'Overall',
            data: Object.values(salary),
        };
    

    You will need to create an array of columns more like this:

        series: [
            {
                name: 'Overall',
                data: Object.values(salary),
            },
            {
                name: 'Visa',
                data: Object.values(visas),
            }
        ]
    

    You could create a new function similar to getSalaries() to compile the visas column. To eliminat code duplication you could make a generic function and add an additional parameter defining each column to compile, for example function getColumnData(table, columns) {. columns would be an array of columns to iterate and compile.

    Kevin

  • vbierschwalevbierschwale Posts: 9Questions: 2Answers: 0

    thank you,
    virgil

Sign In or Register to comment.