javascript - 搜索框以在折线图中显示信息
问题描述
我正在尝试在我的网页中添加一个搜索框,允许用户选择要在折线图中显示的数据。
我知道如何将变量从搜索框传递给 PHP,但问题是如何在 Javascript 中渲染图表以在 PHP 中更新后使用搜索框的值更新信息?
$(document).ready(function() {
$.ajax({
url: "http://localhost/chartjs/followersdata.php",
type: "GET",
success: function(data) {
console.log(data);
var userid = [];
var facebook_follower = [];
var twitter_follower = [];
var googleplus_follower = [];
for (var i in data) {
userid.push("UserID " + data[i].userid);
facebook_follower.push(data[i].facebook);
twitter_follower.push(data[i].twitter);
googleplus_follower.push(data[i].googleplus);
}
var chartdata = {
labels: userid,
datasets: [{
label: "facebook",
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(59, 89, 152, 0.75)",
borderColor: "rgba(59, 89, 152, 1)",
pointHoverBackgroundColor: "rgba(59, 89, 152, 1)",
pointHoverBorderColor: "rgba(59, 89, 152, 1)",
data: facebook_follower
},
{
label: "twitter",
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(29, 202, 255, 0.75)",
borderColor: "rgba(29, 202, 255, 1)",
pointHoverBackgroundColor: "rgba(29, 202, 255, 1)",
pointHoverBorderColor: "rgba(29, 202, 255, 1)",
data: twitter_follower
},
{
label: "googleplus",
fill: false,
lineTension: 0.1,
backgroundColor: "rgba(211, 72, 54, 0.75)",
borderColor: "rgba(211, 72, 54, 1)",
pointHoverBackgroundColor: "rgba(211, 72, 54, 1)",
pointHoverBorderColor: "rgba(211, 72, 54, 1)",
data: googleplus_follower
}
]
};
var ctx = $("#mycanvas");
var LineGraph = new Chart(ctx, {
type: 'line',
data: chartdata
});
},
error: function(data) {}
});
});
感谢您的回复。
解决方案
此链接可以帮助您 https://www.chartjs.org/docs/latest/developers/api.html
// duration is the time for the animation of the redraw in milliseconds
// lazy is a boolean. if true, the animation can be interrupted by other animations
LineGraph.render({
duration: 800,
lazy: false,
easing: 'easeOutBounce'
});
推荐阅读
- reactjs - 具有大量数据负载的 Highcharts 导致 IE11 崩溃
- ethereum - 无法构建 Solidity 合约:exec:“solc”:$PATH 中找不到可执行文件
- c# - 使用什么数据服务 + 简单示例(WPF C# SQL)
- php - 替换字符串中单个字符的空格
- python - 如何改进它 - 数字生成器 + 从范围中猜测数字
- c++ - C++继承中名称隐藏的优先级
- javascript - 如何使用 Angular 7 项目使用 lightgallery?
- c# - 性能计数器与 .Net Core 的兼容性
- tensorflow - Tensorflow-keras:CNN 预测非常接近 1 或 0
- php - 如何在没有自定义查询的情况下从多表获取数据?