How to use a parameter for a label in a Chart JSON?

0
Hello everyone,I have a Line Chart with multiple y axes and I would like to set labels (using parameters) with JSON.Is there a way to insert a parameter there with this widget? I'm asking because I've tried many syntax combinations and all are interpreted as plain strings.
asked
2 answers
0

Hi Horea,


The Custom Layout field in the Mendix Charts widget is a static JSON text area, not an expression editor.

It is evaluated at design time, not runtime, so you can't change the labels dynamically.

I don't think so it'a a syntax problem, it's an architectural limitation of the widget.


But there is a workaround that I just found in plotly documentation.


You can add a html snippet on the page which will be triigger a js snippet funtion after the rendering completion of your chart .


there you can trigger a plotly.reloyout function like this.

// update only values within nested objects
var update = {
    title: {text: 'some new title'}, // updates the title
    'xaxis.range': [0, 5],   // updates the xaxis range
    'yaxis.range[1]': 15     // updates the end of the yaxis range
};
Plotly.relayout(graphDiv, update)


For more info read this doc: https://plotly.com/javascript/plotlyjs-events/

Please try this
Maybe this works for you 😊


answered
0
Hi Horea,
{1} won't be resolved in the Custom Layout JSON. The Custom Layout property is a static JSON configuration that is passed to Plotly, so Mendix page/text parameters are not evaluated there.
If the axis label is static, you can simply set it directly:

{
  "yaxis": {
    "title": {
      "text": "My Y Axis"
    }
  },
  "yaxis2": {
    "title": {
      "text": "My Second Axis"
    }
  }
}

If you need the label to be dynamic at runtime, I wouldn't try to inject a Mendix parameter into the JSON. Instead, generate the layout JSON dynamically and provide it through a string attribute, or use the Custom Chart approach where the layout can come from a Source attribute.
For example, your context entity could have an unlimited-length String attribute such as ChartLayout, and your microflow can generate:

{
  "yaxis": {
    "title": {
      "text": "Revenue"
    }
  },
  "yaxis2": {
    "title": {
      "text": "Quantity"
    }
  }
}

This is preferable to trying to make {1} work inside the static Custom Layout field.
The current Charts documentation describes Custom Layout as static JSON, while the Custom Chart documentation explicitly supports providing the layout through a Source attribute, which can be generated dynamically.
So, in short:
Static label → Custom Layout JSON is fine.
Dynamic label → generate the layout JSON and use a Source attribute / Custom Chart.
Hope that helps.

Important: Text widget-la {1} parameter syntax irukku, but adha Charts Custom Layout JSON-kulla reuse panna mudiyadhu. Mendix Text parameters are specifically configured through the Text widget's parameter mechanism.

Mendix Charts documentation

Mendix Custom Chart documentation

answered