# Can I create a scalarbar if I\`ve used vtkUnsignedCharArray to color the polydata object?

**URL:** <https://discourse.vtk.org/t/can-i-create-a-scalarbar-if-i-ve-used-vtkunsignedchararray-to-color-the-polydata-object/14799>\
**Category:** Development\
**Created:** [November 1, 2024, 12:00am UTC](https://discourse.vtk.org/t/can-i-create-a-scalarbar-if-i-ve-used-vtkunsignedchararray-to-color-the-polydata-object/14799 "2024-11-01T00:00:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_Scatena](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rafael_scatena/32/7820_2.png) [@Rafael\_Scatena](https://discourse.vtk.org/u/Rafael_Scatena)\
**Post date:** [November 1, 2024, 12:00am UTC](https://discourse.vtk.org/t/can-i-create-a-scalarbar-if-i-ve-used-vtkunsignedchararray-to-color-the-polydata-object/14799/1 "2024-11-01T00:00:21Z")

</div>

Hello,

I was wondering if I still could use vtkscalarbaractor if I chose to color the dataset with vtkUnsignedCharArray.

Thank you,

Rafael S.

```
          vtkNew<vtkPolyLine> polyLine;
          polyLine->GetPointIds()->SetNumberOfIds(nodes.size());
          for (unsigned int i = 0; i < nodes.size()+1; i++)
          {polyLine->GetPointIds()->SetId(i, i);}

  
          // Create a cell array to store the lines in and add the lines to it.
          vtkNew<vtkCellArray> cells;
          cells->InsertNextCell(polyLine);
         
          // Create a polydata to store everything in.
          vtkNew<vtkPolyData> polyData_morton;

          // Add the points to the dataset.
          polyData_morton->SetPoints(morton_line_points);

          // Add the lines to the dataset.
          polyData_morton->SetLines(cells);
          
          vtkNew<vtkUnsignedCharArray> cellData;
          cellData->SetNumberOfComponents(3);
          cellData->SetNumberOfTuples(polyData_morton->GetNumberOfLines());

          vtkNew<vtkMinimalStandardRandomSequence> randomSequence;
          randomSequence->SetSeed(8775070);
          auto min_r = 64.0; auto max_r = 255.0;
          for (int i = 0; i < polyData_morton->GetNumberOfLines(); i++)
          {double rgb[3];
            for (auto j = 0; j < 3; ++j)
            {rgb[j] = randomSequence->GetRangeValue(min_r, max_r);randomSequence->Next();}
            cellData->InsertTuple(i, rgb);}              

          polyData_morton->GetCellData()->SetScalars(cellData);

          // Setup actor and mapper.
          vtkNew<vtkPolyDataMapper> mapper_morton;
          mapper_morton->SetInputData(polyData_morton);

          vtkNew<vtkActor> actor_morton;
          actor_morton->SetMapper(mapper_morton);
          actor_morton->GetProperty()->SetColor(colors->GetColor3d("Tomato").GetData());

            int scalarValue=1;

            vtkNew<vtkScalarBarActor> scalarBar;
            scalarBar->SetTitle("Bodies");
            scalarBar->SetNumberOfLabels(polyData_morton->GetNumberOfLines());
     	    scalarBar->SetLookupTable(lut);

```
