# \[vtk.js\] vtkLookupTable.setNumberOfTableValues is not a function

**URL:** https://discourse.vtk.org/t/vtk-js-vtklookuptable-setnumberoftablevalues-is-not-a-function/11453
**Category:** Support
**Tags:** vtkjs
**Created:** [May 15, 2023, 8:26am UTC](https://discourse.vtk.org/t/vtk-js-vtklookuptable-setnumberoftablevalues-is-not-a-function/11453 "2023-05-15T08:26:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [May 15, 2023, 8:26am UTC](https://discourse.vtk.org/t/vtk-js-vtklookuptable-setnumberoftablevalues-is-not-a-function/11453/1 "2023-05-15T08:26:54Z")

</div>

Hello

I’m trying to build a custom LUT, but I can’t translate one example from python/c++ to javascript. My code fails at the line vtkLookupTable.setNumberOfTableValues(256) saying that it is not a function.

What is wrong here?

```auto
    function buildLookupTable(){
        // Same colors as for 2D
        const grad = ["#FFFAFA", "#FFEDD6", "#FFE1B2", "#FFD58E", "#FFC96B",
        "#FFBD47", "#FFB123", "#FFA500", "#FF8D00", "#FF7500", "#FF5E00", 
        "#FF4600", "#FF2F00", "#FF1700", "#FF0000"];
        // Build the color transfer function
        let ctransfer = vtk.Rendering.Core.vtkColorTransferFunction.newInstance();
        for (i = 0; i < grad.length; i++) {
            let color = hexToRgbA(grad[i]);
            ctransfer.addRGBPoint(i, ...color);
        }
        ctransfer.build();
        // Build the lookup table with 256 colors and 1/5 transparent
        let numberOfColors = 256;
        let lut = vtk.Common.Core.vtkLookupTable.newInstance();
        lut.setNumberOfTableValues(numberOfColors);
        for (i = 0; i < numberOfColors; i++) {
            let rgb = ctransfer.getColor( ((i * grad.length)/numberOfColors ) );
            lut.setTableValue(i, rgb[0],rgb[1],rgb[1], Math.min(1, i*5/numberOfColors));
        }
        lut.setNanColor(1,0,1,0);
        lut.build();
        return lut;
    }

```

Best regards  
Alex

---

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [May 15, 2023, 9:49am UTC](https://discourse.vtk.org/t/vtk-js-vtklookuptable-setnumberoftablevalues-is-not-a-function/11453/2 "2023-05-15T09:49:34Z")

</div>

> [@Alex\_Vergara](#):
>
> `lut.setTableValue`

This is harder than I thought: setTableValue is also not a function!!

Is there a way to build a LookupTable in vtk.js??

---

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alex_vergara/32/7082_2.png) [@Alex\_Vergara](https://discourse.vtk.org/u/Alex_Vergara)
#### Post date: [May 15, 2023, 12:09pm UTC](https://discourse.vtk.org/t/vtk-js-vtklookuptable-setnumberoftablevalues-is-not-a-function/11453/3 "2023-05-15T12:09:18Z")

</div>

I found a way, although it is really odd and not as I expect the api to work

Final working example:

```auto
// grad is an array of string hex colors
function buildLookupTable(grad){
        // Build the color transfer function
        let ctransfer = vtk.Rendering.Core.vtkColorTransferFunction.newInstance();
        for (i = 0; i < grad.length; i++) {
            let rgb = hexToRgbA(grad[i]);
            ctransfer.addRGBPoint(i, rgb[0], rgb[1], rgb[2]); // There is no way to add alpha here
        }
        ctransfer.build();
        // Build the lookup table
        let lut = vtk.Common.Core.vtkLookupTable.newInstance();
        let numberOfColors = lut.getNumberOfColors(); // Default 256 colors
        // Build the color table (returns as Float32Array)
        let colorArray = ctransfer.getUint8Table(0,numberOfColors-1,numberOfColors,true); // true adds space for alpha channel
        for (i = 0; i < numberOfColors/5; i++) { // 1/5 transparent with increased opacity
            colorArray[i * 4 + 3] = i*5;
        }
        // Convert to vtkDataArray
        let colorTable = vtk.Common.Core.vtkDataArray.newInstance({
            name: "Color Data Array",
            values: colorArray,
            numberOfComponents: 4 // 4 components R, G, B, A
        }); 
        // Assign the table and build the lut
        lut.setTable(colorTable);
        lut.build();
        return lut;
    }

```
