2016-08-04 54 views
0

我不能制作胶乳。plotly js:乳胶不起作用

var trace1 = { 
    x: [1, 2, 3, 4], 
    y: [1, 4, 9, 16], 
    name: '$\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}$', 
    type: 'scatter' 
}; 
var trace2 = { 
    x: [1, 2, 3, 4], 
    y: [0.5, 2, 4.5, 8], 
    name: '$\beta_{1c} = 25 \pm 11 \text{ km s}^{-1}$', 
    type: 'scatter' 
}; 
var data = [trace1, trace2]; 
var layout = { 
    xaxis: {title: '$\sqrt{(n_\text{c}(t|{T_\text{early}}))}$'}, 
    yaxis: {title: '$d, r \text{ (solar radius)}$'} 
}; 
Plotly.newPlot('myDiv', data, layout); 

这里是的jsfiddle一个例子:https://jsfiddle.net/gn1nnaup/

例子来自https://plot.ly/javascript/LaTeX/

采取它引发以下错误:plotly-latest.min.js:11 Error: <rect> attribute x: Expected length, "NaN".

+0

对于它现在的价值:我ve有一个非常类似的问题,但它已经与目前的版本解决了Plotly。 – Christof

+1

@Christof:似乎需要用另一个反斜杠来避免反斜杠,至少在JSfiddle中是必需的。 –

回答

0

你需要你的提琴两个微小的变化。

  1. MathJax.js?config=TeX-AMS-MML_SVG,而不是MathJax.js?config=TeX-MML-AM_CHTML
  2. 在您的代码/导入TeX图书馆来beforePlotly

var trace1 = { 
 
    x: [1, 2, 3, 4], 
 
    y: [1, 4, 9, 16], 
 
    name: '$\\alpha_{1c} = 352 \\pm 11 \\text{ km s}^{-1}$', 
 
    type: 'scatter' 
 
}; 
 
var trace2 = { 
 
    x: [1, 2, 3, 4], 
 
    y: [0.5, 2, 4.5, 8], 
 
    name: '$\\beta_{1c} = 25 \\pm 11 \\text{ km s}^{-1}$', 
 
    type: 'scatter' 
 
}; 
 
var data = [trace1, trace2]; 
 
var layout = { 
 
    xaxis: {title: '$\\sqrt{(n_\\text{c}(t|{T_\\text{early}}))}$'}, 
 
    yaxis: {title: '$d, r \\text{ (solar radius)}$'} 
 
}; 
 
Plotly.newPlot('myDiv', data, layout);
<div id="myDiv" style="width:100%"></div> 
 
<script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_SVG"></script> 
 
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>

+1

未来的注意事项:cdn.mathjax.org即将结束生命周期,请查看https://www.mathjax.org/cdn-shutting-down/获取迁移提示。 –