Public
Edited
Mar 12, 2023
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Terminal=html`<div id='terminal' style="background-color:#444;color:#BBB;width:100%;height:auto"' >${title}</div>`
Insert cell
function print(...args){
Terminal.innerHTML+="&nbsp;"
for(let arg of args){
Terminal.innerHTML=arg+"\t"
}
Terminal.innerHTML+="<br>"
}
Insert cell
function cls(){
Terminal.innerHTML=`${title}`
}
Insert cell
cls()
Insert cell
print()
Insert cell
Insert cell
mutable id="@observablehq/notebook-visualizer"
Insert cell
import {chart} with {id as id} from "@observablehq/notebook-visualizer"
Insert cell
function visulizeNB(id){
mutable id=id;
return chart
}
Insert cell
visulizeNB("@cottonsh/echarts-runner")
Insert cell
# 3、Akshare tookit

```javascript
import {akshare} from '@cottonsh/utils'
//return json data
data=akshare(api_name,{arg1:value,arg2:value})
//show data
Inputs.table(data)
```
Insert cell
function akshare(api,args){
var s=''
for(var arg in args){
s+=arg+'='+args[arg]+'&'
}
let url=`http://127.0.0.1:5000/api/public/${api}?${s}`
let data=$.ajax({
url:url
});
console.log(api,url)
return data
}
Insert cell
Insert cell
Insert cell
Insert cell
function Py2(codes,objBack=null){
var msg
$.ajax({
type: "get",
url: "http://127.0.0.1:5000",
dataType : 'json',
crossDomain:true,
contentType:'application/json',
data:{code:codes,objBack:objBack},
async:false,
success: function(res){
msg={
out:res.out,
value:JSON.parse(res.objBack)
}
}
});
return msg
}
Insert cell
### 打印table
https://observablehq.com/@visnup/hello-danfo-js
Insert cell
function printdf(data_as_array) {
const table = html`<table></table>`;
let tableObject = d3.select(table);
tableObject.append("tr")
.selectAll()
.data(data_as_array[0])
.enter()
.append("th")
.text(d => d);
tableObject.selectAll("tr")
.data(data_as_array.slice(1, 15))
.enter()
.append("tr")
.selectAll()
.data(d => d)
.enter()
.append("td")
.text(d => d)
;
return table;
}
Insert cell
# 使用attrs属性
Insert cell
//使用 d3.select('div').call(attrs({width:600,height:800}))
function attrs(o,arg) {
Object.keys(arg).forEach(k=>{
console.log(typeof k,arg[k])
o.attr(k,arg[k])
})
}
Insert cell
Insert cell
import {EchartsRunner} from '@cottonsh/echarts-runner'
Insert cell
moment=require("https://cdn.jsdelivr.net/npm/moment@2.29.4/moment.min.js")
Insert cell
import {dfd} from '@visnup/hello-danfo-js'
Insert cell
$=require("https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js")
Insert cell
sz=akshare('stock_szse_summary',{"date":''+getDate(new Date())})
Insert cell
function handle_null_json(data){
data.forEach(d=>{
for(var key in d){
if (d[key]===null){
d[key]=0
}
}
})
}
Insert cell
import {style} from "@sandraviz/d3image"
Insert cell
htl.html`<div id='test'>test</div><script type='module'>
import { faker } from 'https://cdn.skypack.dev/@faker-js/faker';
console.log(faker.name.fullName();)
document.getElementById("test").innerHTML='test2'
</script>
`

Insert cell
faker=import('https://cdn.skypack.dev/@faker-js/faker')
Insert cell
faker.faker.name.fullName()
Insert cell
Faker = (await import('https://cdn.skypack.dev/faker@5.5.3?min')).default
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
pd.date_range('2013-1-1',periods=6)
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more