2016-08-04 55 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/獲取遷移提示。 –