Data¶

Data types¶

Vizzu currently supports two types of data series: dimensions and measures. Dimensions slice the data cube Vizzu uses, whereas measures are values within the cube.

Dimensions are categorical series that can contain strings and numbers, but both will be treated as strings. Temporal data such as dates or timestamps should also be added as dimensions. Vizzu will draw the elements on the chart in the order they are provided in the data set by default. Thus we suggest adding temporal data in a sorted format from oldest to newest.

Measure in the current beta phase can only be numerical.

Adding data¶

There are multiple ways you can add data to Vizzu:

  • Specified by series - column after column if you think of a spreadsheet
  • Specified by records - row after row.
  • Data cube form

Elements with a missing value should contain the number zero. null, undefined and empty cells will result in an error. In case of dimensions, add '' as a value to have a category without a name.

In the first two cases, data has to be in first normal form. Here is an example of that:

Genres Types Popularity
Pop Hard 114
Rock Hard 96
Jazz Hard 78
Metal Hard 52
Pop Smooth 56
Rock Smooth 36
Jazz Smooth 174
Metal Smooth 121
Pop Experimental 127
Rock Experimental 83
Jazz Experimental 94
Metal Experimental 58

In the type parameter, you can set if a series is a dimension or a measure. Adding the type parameter is optional. If omitted, Vizzu will automatically select the type depending on the first element of the values array using the typeof operator. If all items are numbers, it will be declared as a measure, in any other case, a dimension.

Data specified by series:

In [1]:
from ipyvizzu import Chart, Data, Config

data_series = Data()
data_series.add_serie(
    "Genres",
    ["Pop", "Rock", "Jazz", "Metal",
     "Pop", "Rock", "Jazz", "Metal",
     "Pop", "Rock", "Jazz", "Metal"],
    type="dimension"
)
data_series.add_serie(
    "Types",
    ["Hard", "Hard", "Hard", "Hard",
     "Smooth", "Smooth", "Smooth", "Smooth",
     "Experimental", "Experimental", "Experimental", "Experimental"],
    type="dimension"
)
data_series.add_serie(
    "Popularity",
    [114, 96, 78, 52, 56, 36, 174, 121, 127, 83, 94, 58],
    type="measure"
)

Data specified by records:

In [2]:
from ipyvizzu import Chart, Data, Config

data_records = Data()

data_records.add_serie('Genres', type='dimension')
data_records.add_serie('Types', type='dimension')
data_records.add_serie('Popularity', type='measure')

records = [
    ['Pop', 'Hard', 114],
    ['Rock', 'Hard', 96],
    ['Jazz', 'Hard', 78],
    ['Metal', 'Hard', 52],
    ['Pop', 'Smooth', 56],
    ['Rock', 'Smooth', 36],
    ['Jazz', 'Smooth', 174],
    ['Metal', 'Smooth', 121],
    ['Pop', 'Experimental', 127],
    ['Rock', 'Experimental', 83],
    ['Jazz', 'Experimental', 94],
    ['Metal', 'Experimental', 58],
]

result = map(data_records.add_record, records)

Data cube

In [3]:
from ipyvizzu import Chart, Data, Config

data_cube = Data()

data_cube.add_dimension('Genres', [ 'Pop', 'Rock', 'Jazz', 'Metal'])
data_cube.add_dimension('Types', [ 'Hard', 'Smooth', 'Experimental' ])

data_cube.add_measure(
    'Popularity',
    [
        [114, 96, 78, 52],
        [56, 36, 174, 121],
        [127, 83, 94, 58],
    ]
)