由于我不熟悉C3.js库,当我试图拆分数组数据时,我有点困惑.
对于即时我有一些来自json的数组值.
var jsondata=[[123],[45],[56],[22]];
var jsondataName=[["apple"],["orange"],["banana"],["pear"]];
Run Code Online (Sandbox Code Playgroud)
我试图将第一个数组jsondata传递到图表中,但这些值进入同一列,这不是我想看到的.
我希望这些数组值成为独立数据并将名称推入其中
请参阅我制作的演示:http: //jsfiddle.net/q8h39/92/
更新json数据格式:
"Name": apple,
"data": {
"value": 1434,
}
"Name": banana,
"data": {
"value": 342,
}
}
}
Run Code Online (Sandbox Code Playgroud) 所以我有一个预加载元素的功能,并使用"display:none"隐藏图表
<div class="col-sm-9 topTenWebCus" ></div>
Run Code Online (Sandbox Code Playgroud)
javscript:
$(document).ready(function() {
window.setTimeout(function(){
$(".topTenWebCus").css("display","none");
},200);
});
Run Code Online (Sandbox Code Playgroud)
然后我得到另一个onclick函数来删除"display:none" css
$("#buttonFire").click(function(){
$(".topTenWeb30d").css("display","none");
$(".topTenWebCus").css("display","block");
});
Run Code Online (Sandbox Code Playgroud)
它工作正常.但即使我在网站上插入引导程序,它也不会重新调整大小.
我正在考虑使用内部函数来执行.resize()但它不起作用,是否有更好的方法来修复调整大小问题?
更新1:
如果用户更改缩放率,图表将自行调整大小.
我只想弄出一件重要的事情,如果缩放率为100%,图表会正确显示,但如果用户更改缩放率,图表将不会调整到合适的大小.
Update2 我尝试使用.show()和.hide()但没有运气
样品溶液
$("#buttonFire").click(function(){
$(".topTenWeb30d").css("display","none");
$(".topTenWebCus").css("display","block");
chart.flush() // chart depends on your chart's name it could be anything like charrt112.flush()
});
Run Code Online (Sandbox Code Playgroud) 我的网站目前受到 csurf 保护。
我已将所有 ajax 调用分配给 csrf 令牌,如下所示
"/data/someAPI?_csrf="+ $("#_csrf").val它与我拥有的所有功能配合得很好。
但现在我正在编写一个文件上传功能,并且互联网上的大多数教程都是使用 sumbit 形式来执行此操作。
所以我写了类似的东西
Node.js
app.post('/upload', function(req, res) {
if (!req.files)
return res.status(400).send('No files were uploaded.');
// The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
let sampleFile = req.files.sampleFile;
// Use the mv() method to place the file somewhere on your server
sampleFile.mv('/somewhere/on/your/server/filename.jpg', function(err) {
if (err)
return res.status(500).send(err);
res.send('File uploaded!');
});
});
Run Code Online (Sandbox Code Playgroud)
解决了
超文本标记语言
<html>
<body>
<form ref='uploadForm'
id='uploadForm'
action='http://localhost:8000/upload?_csrf=<your_csrf_token>"'
method='post' …Run Code Online (Sandbox Code Playgroud) 我已经在我的网站上创建了一个C3js圆环图,我已经onclick在图表中分配了一个功能,我想要一个按钮来启动该功能但是,我无法想出任何好的方法来做到这一点.
我尝试创建一个按钮,以便像下面一样触发函数,找到元素并将其绑定到我的.onclick()函数:
$("#test").click(function(){
$(".c3-arc-data2").click();
});
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
请参阅fiddleJS中的示例:https://jsfiddle.net/mcd6ucge/52/
延期:
我有一个if语句,它将更改图表的数据,当数据被更改为另一个案例时,该onclick函数不起作用
if(x = "something"){
$(".uldateBtn1").html(
'<li id="test-fliter" class="dateBtn hvr-underline-from-left" style="margin-top:10px !important;">test</li>'
)
$("#test-fliter").click(function(){
var evt = new MouseEvent("click");//make a mouse event
d3.select(".c3-arc-test").node().dispatchEvent(evt);
});
}
else{
$(".uldateBtn1").html(
'<li id="test2-fliter" class="dateBtn hvr-underline-from-left" style="margin-top:10px !important;">test</li>'
)
$("#test2-fliter").click(function(){
var evt = new MouseEvent("click");//make a mouse event
d3.select(".c3-arc-test2").node().dispatchEvent(evt);
});
}
Run Code Online (Sandbox Code Playgroud)
if工作正常,但其他工作不正常.
如何创建 if 语句以检查整数是否以 0 结尾?
例如,我想要一个这样的 if 语句:
var test = 107; //107 is an example it'should some unknown number
if(test is xx1 - xx9){
//do something
}
else if(test is xx0){
//do something
}
Run Code Online (Sandbox Code Playgroud) 我已经通过 highchart 创建了一个散点图,它需要在工具提示框中显示一些数据。
大多数数字包含大数字,因此我想在中间添加一些数字分隔符,如下所示
我研究了其他一些帖子,说我应该做类似的事情,{point.x:.2f}但是由于我从 json 文件中获取所有数据,因此我无法向原始数字添加任何符号。
我的图表工具提示框的属性如下所示:
//*highchart codes
tooltip: {
useHTML: true,
headerFormat: '<table>',
pointFormat: '<tr><th colspan="2"><h3>{point.name}</h3></th></tr>' +
'<tr><th>Fan rate:</th><td>{point.y}</td></tr>' +
'<tr><th>Coverage:</th><td>{point.x}</td></tr>' +
'<tr><th>Volume:</th><td>{point.z}</td></tr>',
footerFormat: '</table>',
followPointer: true
},
Run Code Online (Sandbox Code Playgroud) 所以例如我总共有3个数组,如下所示
var arr1 = ['123','456','789'];
var arr2 = ['435','551','778'];
var arr3 = ['5','7','1'];
Run Code Online (Sandbox Code Playgroud)
我试图将它们存储在一个对象中以供进一步使用.
var Chart = "";
for(var i = 0; i < arr1.length ;i++){
Chart = {
x : arr1[i],
y : arr2[i],
z : arr3[i]
};
}
Run Code Online (Sandbox Code Playgroud)
我的方法完成了这项工作,但是当我控制它并使用它时它只返回最后一组数据.
所以只有 {arr1[2],arr2[2],arr3[2]}用过其余的都没有了.
我怎么能解决这个问题?
javascript ×7
jquery ×5
c3.js ×2
ajax ×1
arrays ×1
csrf ×1
d3.js ×1
highcharts ×1
if-statement ×1