Dataviewjs: multiplying field values?

What I’m trying to do

I want to adjust a field’s value by multiplying it as a workaround for Chart not having a left & right axis option like the Tracker plugin.

The use-case would to fields of values where one field is a much higher number than the other.

For example, Field A’s values range from 80-120 while Field B’s values range from 1-10.

In Tracker, I could assign Field A to the left vertical axis and Field B to the right vertical axis and see both lines easily, but in Chart Field B is a tiny line at the bottom of the graphic with miniscule variations.

If I could multiply Field B’s values by 10 they would be visible in a useful manner but I can’t figure it out.

Things I have tried

I thought I might be able to create a new variable that multiplies the variable I want to adjust, but to no avail.

Here’s how I set the variable:

const hourSleep = pages.map(p => p.sleep).values

And here’s what I tried that failed:

const hourSleep = pages.map(p => p.sleep).values
const sleepAdjust = (hoursSleep * 10)

And some variations thereof, but all of them resulted in an error so I didn’t even get as far as trying to plot the new figures.

If that is the map you’re using, then why not just change the map part to become map(p => p.sleep * 10) ? Doesn’t that produce the result you’re wanting?

If it doesn’t, please provide a little bit more of your query, so we can see what’s happening.

1 Like

I hadn’t considered that possibility but I will try it out now!

Edit: that worked, thank you!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.