jonathan jonathan - 27 days ago 9
Javascript Question

"Play with this data!" not showing up for my plotly.js plot

I was under the assumption the "Play with this data!" link was supposed the show up by default. Any ideas on why it may not appear? I am just working with a basic scatter plot.

Note that this code below is not standalone as is, it is just the excerpt that does the plotly work.

var xData = [];
var yData = [];
var h = results;
for(var k in h) {
var localdate = k;
var plotdate = moment(localdate).format('YYYY-MM-DD HH:mm:ss');
xData.push(plotdate);
if (currentPort === "t") {
yData.push(CtoF(h[k]));
} else {
yData.push(h[k]);
};
}
var plotdata = [
{
x: xData,
y: yData,
type: 'scatter',
mode: 'markers+lines',
line: {
'color': HELIUM_BLUE
},
marker: {
'symbol': 'circle',
'color': HELIUM_PINK,
'maxdisplayed': 50
}
}
];
var layout = {
title: currentData,
xaxis: {
'title': 'Date / Time'
},
yaxis: {
'title': title
}
};
Plotly.newPlot(plotHolder, plotdata, layout);

Answer

You would need to add {showLink: true} as the fourth argument (after layout). I guess the default value changed from true to false. If you want to change the name of the link, use {showLink: true, "linkText": "Play with this data"}

var xData = [1, 2, 3, 4, 5];
var yData = [10, 1, 25, 12, 9];

var plotdata = [
    {
        x: xData,
        y: yData,
        type: 'scatter',
        mode: 'markers+lines',
    }
];
var layout = {
    title: 'Edit me',
    xaxis: {
        'title': 'x'
    },
    yaxis: {
        'title': 'y'
    }
};
Plotly.newPlot(plotHolder, plotdata, layout, {showLink: true, "linkText": "Play with this data"});
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<div id='plotHolder'>

</div>

Comments