cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create JS function compatible for line chart visual

Tarunbt
Observer

Hi Team,

I am using following function to fetch data but using that code I am unable to create line chart. 


export default async function () {
try {
const data = JSON.parse($mpcheckoutv2);
// Check if data is not null and is an array
if (data && Array.isArray(data)) {
// Extract the data from the result 
const Records = data;
return Records;
} else {
throw new Error("Invalid data format");
}
} catch (error) {
// Handle the error
console.log("Error:", error.message);
return "Error processing data";
}
}

I need similar output of following query.

| fieldsAdd success = matchesPhrase(Message, "Order raised successfully" )
| makeTimeseries count(), by: {success, OrderType}, time: toTimestamp(timestamp)

3 REPLIES 3

marco_irmer
Advisor

Time series charts require a special record format. The record must have the following elements:

  • timeframe: a field of type 'timeframe' containing timestamps which signify the start time and end time of your timeseries
  • interval: a value of type 'duration' specifying the length of each interval
  • data (or any other field name): an sequential array containing all the data points. The size of the array should be consistent with the expected size based on the timeframe and interval elements.

Here is an example of a simple record containing a time series:

marco_irmer_0-1741642402212.png

Raw JSON (trimmed down to 5 minutes for readability):

marco_irmer_1-1741642727049.png

You will have to amend your code so that the record format produced by your code matches the format Dynatrace uses for time series data.

Tarunbt
Observer

Hello @marco_irmer

Thanks for your response, But my requirment is different. I have two fileds for group by, like this "" {success, OrderType} "" and the output shoud visualize like below image. I want to know what output would be for the below chart using JS code. 

 

 

Screenshot 2025-03-18 at 1.57.37 PM.png

Hi @Tarunbt,

Your code parses a JSON object and then returns it to Dynatrace as a variable named Records. You'll have to write new JavaScript code that manipulates the JSON into a format that Dynatrace can understand as a timeseries. The exact code necessary to accomplish this depends very much on the specific format of your data. If you are able to share the format of your records your code currently outputs then perhaps it would be possible to give additional pointers.

Featured Posts