Question about WebChart

Is there a way to start a bar chart scale from zero? What I’m seeing is that when the data spread is small, say from values 2 to 10, the scale starts at 2.

From what I’ve investigated in JS this is how the scale is set:

options: {
    scales: {
        yAxes: [{
            ticks: {
                beginAtZero: true
            }
        }]
    }
}

I can’t seem to find a way to do it in Xojo.

Any help is appreciated :slight_smile:

In OverrideOptions event of the WebChart
you can do something lile this:

Var json_scales As New JSONItem
Var json_yAxes As New JSONItem

Var json_ticks As New JSONItem
json_ticks.value("beginAtZero") = True

json_yAxes.add(json_ticks)

json_scales.value("yAxes") = json_yAxes
json.value("scales") = json_scales

Untested but that’s your direction.

You may need to test for the keys already existing and just update what you want, i’m not sure about that.

Thank you!

That points me in the right direction

In case someone needs this, following @DerkJ 's advice this is what I got working:

Var json_scales As New JSONItem
Var json_yAxes As New JSONItem

Var json_ticks As New JSONItem
json_ticks.value("ticks") = "ticks"

Var json_begin_at_zero As New JSONItem
json_begin_at_zero.Value("beginAtZero") = True

json_ticks.Value("ticks") = json_begin_at_zero

json_yAxes.add(json_ticks)

json_scales.value("yAxes") = json_yAxes

options.value("scales") = json_scales

2 Likes