Hills and Valleys With Deneb

Hi all,

I’m trying to recreate the “hills and valleys” by Daniel Marsh-Patrick posted here:

The coding is a bit above my level but it would be great if I could get the chart to work.

The expected output is like this:

I’m nearly there, just need to get rid of the blue sections:

The source data I’m using is different to Daniel’s so that’s why the shape of the chart is different.
My PBI file is here:

Error Bands.pbix (3.5 MB)

My JSON code is:

{
“data”: {“name”: “dataset”},
“encoding”: {
“x”: {
“field”: “Month”,
“type”: “temporal”
},
“y”: {“type”: “quantitative”}
},
“layer”: [
{
“description”: “Target area - background”,
“mark”: {
“type”: “area”,
“style”: “delta_negative”
},
“encoding”: {
“y”: {“field”: “Sales PY”}
}
},
{
“description”: “Actual area - masks out target where necessary”,
“mark”: {
“type”: “area”,
“style”: “delta_positive”
},
“encoding”: {
“y”: {“field”: “Sales”}
}
},
{
“description”: “Masking layer (with interpolated points)”,
“transform”: [
{
“calculate”: “min(datum[‘Sales PY’] , datum[‘Sales’])”,
“as”: “low_value”
},
{
“window”: [
{
“op”: “lead”,
“field”: “Month”,
“as”: “month_following”
},
{
“op”: “lead”,
“field”: “Sales”,
“as”: “actual_following”
},
{
“op”: “lead”,
“field”: “Sales PY”,
“as”: “target_following”
}
]
},
{
“calculate”: “(datum[‘actual_following’] - datum[‘Sales’]) / (datum[‘month_following’] - datum[‘Month’])”,
“as”: “actual_slope”
},
{
“calculate”: “(datum[‘target_following’] - datum[‘Sales PY’]) / (datum[‘month_following’] - datum[‘Month’])”,
“as”: “target_slope”
},
{
“calculate”: “datum[‘Sales’] - (datum[‘actual_slope’] * datum[‘Month’])”,
“as”: “actual_y_intercept”
},
{
“calculate”: “datum[‘Sales PY’] - (datum[‘target_slope’] * datum[‘Month’])”,
“as”: “target_y_intercept”
},
{
“calculate”: “(datum[‘target_y_intercept’] - datum[‘actual_y_intercept’]) / (datum[‘actual_slope’] - datum[‘target_slope’])”,
“as”: “intersect_base”
},
{
“calculate”: “datum[‘intersect_base’] > datum[‘Month’] && datum[‘intersect_base’] < datum[‘month_following’]”,
“as”: “intersect_before_following”
},
{
“calculate”: “datum[‘intersect_before_following’] ? datetime(datum[‘intersect_base’]) : null”,
“as”: “intersect_x”
},
{
“calculate”: “datum[‘intersect_before_following’] ? (datum[‘actual_slope’] * datum[‘intersect_base’]) + datum[‘actual_y_intercept’] : null”,
“as”: “intersect_y”
},
{
“fold”: [
“Month”,
“intersect_x”
]
},
{
“filter”: “datum[‘value’] !== null”
},
{
“calculate”: “datum[‘key’] === ‘Month’ ? datum[‘Month’] : datum[‘intersect_x’]”,
“as”: “x”
},
{
“calculate”: “datum[‘key’] === ‘Month’ ? datum[‘low_value’] : datum[‘intersect_y’]”,
“as”: “y”
}
],
“mark”: {
“type”: “area”,
“style”: “mask_foreground”
},
“encoding”: {
“x”: {“field”: “x”},
“y”: {“field”: “y”}
}
}
]
}

Many thanks,
Tim

Hi @Timmay,

The issue is the mask_foreground part at the bottom of the config, e.g.:

{
  ...
  "style": {
    "delta_negative": {
      "color": "#8D1D1C"
    },
    "delta_positive": {
      "color": "#83C79B"
    }
  },
  "mask_foreground": {
    "color": "#ffffff",
    "stroke": "#ffffff"
  }
}

This is currently sitting outside the style object and as such your mark isn’t applying this to its configuration (as the named style cannot be found in the right place). You just need to move this into the style object so that it’s a valid style for your spec, e.g.:

{
  ...
  "style": {
    "delta_negative": {
      "color": "#8D1D1C"
    },
    "delta_positive": {
      "color": "#83C79B"
    },
    "mask_foreground": {
      "color": "#ffffff",
      "stroke": "#ffffff"
    }
  }
}

Your spec will then work as expected with no further changes, e.g.:

I’ve attached an updated version for you though, just in case. Glad you found the template useful!

DM-P

Error Bands.pbix (3.5 MB)

2 Likes

Thanks Daniel, that’s great!

I’m on a mission to create charts that look close to the IBCS charts in Zebra BI. It’s unfortunate that the great looking charts in Zebra Bi are only available for an extra fee, one would like that chats that meet IBCS would come standard with PBI but that just isn’t a reality. There’s some work being done on the PBI visuals by the MS team but we’re still way off where we should be.

I’m hoping to pimp up the hills and valleys chart so if I come up with something looking good, I’ll post it here again, and if I get stuck again also, I’ll let you know.

Many thanks again,
Tim

2 Likes