8

I am implementing Histogram chart using react-plotlyjs. Graph is implemented but I have to draw the normal distribution curve using X and Y axis. I have the X axis but Y axis is automatically calculated for Frequency. So, I need the co-ordinates of X and Y axis to draw the normalization curve.

Also, I have to figure out like how can we calculate the frequency. I have to get the max of frequency. I cannot be able to share the data because I have a large number of records.

I am looking for the suggestions on this.

const trace1 = {
    x: filteredXRecords,
    type: "histogram",
    histnorm: 'probability', //(Probability is used for Y axis)
    showlegend: true,
    marker: {
        color: 'rgb(255,255,100)',
    }
}
const data = [trace1]
<Plot
    onClick={(data) => doubleClick(data)}
    onRestyle={(data) => onRestyle(data)}
    onSelected={( data ) => handleOnSelected( data ) }
    id={graphName}
    data={data}
    layout={plotLayout}
    style={plotStyle}
    config={{ displaylogo: false }}
    onRelayout={ ( data ) => handleRelayout( data )}
/>
Vikash Dhiman
  • 570
  • 5
  • 16
  • *"I cannot be able to share the data because I have a large number of records"* You can share just a handful of these records and it's still going to be massively helpful for anyone trying to answer this. – inwerpsel Sep 23 '22 at 08:33

1 Answers1

0

I am not sure if that code is sufficient. According to the documentation, a basic histogram has code like this:

var x = [];
for (var i = 0; i < 500; i ++) {
    x[i] = Math.random();
}

var trace = {
    x: x,
    type: 'histogram',
  };
var data = [trace];
Plotly.newPlot('myDiv', data);

But from your code, you are using the const to create the histogram with Plotly.js.

To get the max frequencies, have you tried using

histfunc = 'max'

According to the documentation, you can use histfunc within the type=histogram. Here is the documentation for referencing the histogram Traces https://plotly.com/javascript/histograms

histfun uses any of these arguments: Type: enumerated , one of ( "count" | "sum" | "avg" | "min" | "max" )

I recommend reviewing the documentation links provided and seeing if these solve the issue for you. If not, please feel free to comment further if you are still struggling.

Nikimaria87
  • 78
  • 10