我正在制作一些谷歌图表,我被困在这里.Google允许您将列堆叠起来.但它有限或我无法配置它工作.以谷歌为例,这里有一个例子,显示了两个国家每年生产的咖啡杯数量:
假设我有两个国家的另一个数据集,但这次我有速溶咖啡而不是地面.例:
我想做的是将这两个数据集叠加在一起.所以每个专栏都是一个国家,但有两个部门:豆类和速溶咖啡.
我在想是否有一种方法可以通过以下方式格式化数据表:
['Year', 'Austria', 'Austria (instant)', 'Bulgaria', 'Bulgaria (instant')],
['2003', 1736060, 10051, 250361, 68564],
['2004', 1338156, 65161, 786849, 1854654],
['2005', 1276579, 65451, 120514, 654654]
Run Code Online (Sandbox Code Playgroud)
生成类似的东西
非常感谢您的帮助.
我正在尝试将模式与可能具有多个模式实例的字符串进行匹配.我需要单独的每个实例.re.findall()
应该这样做,但我不知道我做错了什么.
pattern = re.compile('/review: (http://url.com/(\d+)\s?)+/', re.IGNORECASE)
match = pattern.findall('this is the message. review: http://url.com/123 http://url.com/456')
Run Code Online (Sandbox Code Playgroud)
我需要" http://url.com/123 ",http://url.com/456和两个数123 456是不同的元素match
列表.
我也尝试'/review: ((http://url.com/(\d+)\s?)+)/'
过这种模式,但没有运气.
我的Apache Web服务器突然停止自动提供index.php文件.它显示了direcotry列表.我尝试过帮助但没有运气.
我的htttpd.conf文件包括
<IfModule module_php5>
AddType application/x-httpd-php .php
</IfMOdule>
Run Code Online (Sandbox Code Playgroud)
和
DirectoryIndex index.php index.html
Run Code Online (Sandbox Code Playgroud)
如果以上都可以,那可能是什么问题?
我试图在成功执行后重定向页面.但是,我想在重定向完成时向用户显示一条消息(例如"Changed made.Redirecting ...").header
在页面输出后更改变量会导致PHP出错,我知道这一点.我的问题是,我该怎么做?
我目前的代码是这样的
// ... execution code
echo 'Changes made successfully. Now redirecting...';
header('Location: index.php');
Run Code Online (Sandbox Code Playgroud)
这不起作用.我也看到了SO的答案,建议我分别使用ob_start()
和ob_flush()
在页面的开头和结尾.但这也没有解决我的问题,我仍然得到错误.
NB我只需要使用PHP,我不希望JavaScript用于重定向.
编辑:我最终使用JavaScript进行重定向,因为我需要在重定向之前向用户输出一些有用的消息,而单独使用PHP并不是最好的解决方案.
我正在使用Laravel 5.1,由于某些原因我不时会收到此错误:
Response.php第397行中的UnexpectedValueException:Response内容必须是实现__toString()的字符串或对象,给出"boolean".
非常令人沮丧的是这是非常不可预测的,它只是偶尔发生 - 因此它甚至很难调试,因为它不一致.我有一个简单的路径来转储翻译文件,如下所示:
Route::get('test', function() {
return trans('restaurant');
});
Run Code Online (Sandbox Code Playgroud)
如果我不断刷新页面,它会在大多数时间显示输出正常.但是,每20到30个电话,我就会收到错误!有人可以在这里说清楚吗?
这是堆栈跟踪:
UnexpectedValueException in Response.php line 397:
The Response content must be a string or object implementing __toString(), "boolean" given.
in Response.php line 397
at Response->setContent(false) in Response.php line 54
at Response->setContent(array(...)) in Response.php line 200
at Response->__construct(array(...)) in Router.php line 1229
at Router->prepareResponse(object(Request), array(...)) in Router.php line 709
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in LocaleSettings.php line 30
at LocaleSettings->handle(object(Request), object(Closure))
at …
Run Code Online (Sandbox Code Playgroud) 所以我的代码看起来像这样:
<div id="blackbox">style="background: black;
width: 90px;
height: 80px;
color: white;
text-align: center;
font-family: Times;
font-size: 20px;
position: fixed;
left: 0px;
bottom: 150px
Run Code Online (Sandbox Code Playgroud)
现在它以某种方式在内联CSS中不起作用,这是我能做到的唯一事情.如果你有一个解决方案,我会很高兴.但是,我想制作:hover属性但是如何因为这不起作用:
<div style="background: black;
width: 90px;
height: 80px;
color: white;
text-align: center;
font-family: Times;
font-size: 20px;
position: fixed;
left: 0px;
bottom: 150px}
blackbox:hover {background: white;}
Run Code Online (Sandbox Code Playgroud)
要么
:hover {background: white;}
Run Code Online (Sandbox Code Playgroud)
要么
hover {background: white;}
Run Code Online (Sandbox Code Playgroud) 有没有可能的方法在窗体中创建一个for循环:
for i in 0 to some_var loop
// blah,blah
end loop;
Run Code Online (Sandbox Code Playgroud)
如果没有,有没有其他方法来创建相同的循环?由于While循环允许使用变量作为限制,但它们在我的项目中不可合成.
提前致谢,
Bojan Matovski
我正在为带有导航的SPA使用react和react-router。每次切换导航项目时,路由器都会将React组件称为“构造函数”。这是相关的代码位:
class Home extends React.Component {
constructor(props) {
super(props);
console.log('component constructed!');
this.state = {
counter: 0
}
setInterval(() => this.setState({
counter: this.state.counter+1
}), 1000)
}
render() {
return (
<h3>Counter: {this.state.counter}</h3>
);
}
}
ReactDOM.render(
<Router history={hashHistory}>
<Route path="/" component={App}>
<IndexRoute component={Home} />
<Route path="profile" component={Profile} />
<Route path="settings" component={Settings} />
</Route>
</Router>,
document.getElementById('container')
);
Run Code Online (Sandbox Code Playgroud)
每次我从一个选项卡切换到另一个选项卡时,计数器都从0开始。显然,我知道render()
每次状态更改或路由器切换选项卡时都应调用该方法,但是为什么constructor
要更改选项卡呢?那是React-Router的工作方式,还是我做错了什么?
我有两个变量:var1 和 var2。我想显示 var1 默认值,但如果 var1 为空或 null,则显示 var2。不管它是否有 var2 值。
我正在尝试在Google散点图上获取所选实体的工具提示.我创建我的数据表如下:
data = google.visualization.arrayToDataTable([
['Lines changed', 'TTL', 'Tooltip'],
[25, 12, 'Text for first'],
[34, 20, 'Text for second']
]);
Run Code Online (Sandbox Code Playgroud)
然后我可以使用访问所选的一个
google.visualization.events.addListener(chart, 'select', function () {
// when a point is selected
var selection = chart.getSelection();
console.log(data.getValue(selection[0].row, selection[0].column)); // this gives me the Y-value for that row and index
});
Run Code Online (Sandbox Code Playgroud)
有谁知道如何从该行和索引而不是Y值获取工具提示文本?
编辑
我可以确实添加使用工具提示arrayToDataTable()
通过设置列属性类似的方法:
data.setColumnProperty(2, 'role', 'tooltip');
Run Code Online (Sandbox Code Playgroud)
这使得第三列(索引2)成为工具提示.只是我不能(轻松地)使用上述方法将HTML添加到工具提示中.我不得不恢复使用new google.visualization.DataTable()
.
我的.htaccess
文件中有一些用于干净 URL 的重写规则,并且我的网页中还需要 AJAX 调用。由于重写规则,我在处理 ajax 文件请求时遇到问题。这是我的 htaccess 文件内容:
Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteBase /~mavili/loran/orders/
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)
当我做这样的事情时:
$.ajax({
type: 'get',
url: 'http://domain.com/misc/page.php',
success: function(data) {
$('#load_content').html(data);
},
error: function() {
$('#load_content').html('Error: Unable to load file.');
}
});
Run Code Online (Sandbox Code Playgroud)
的请求http://domain.com/misc/page.php
通过了 htaccess 重写规则并弄乱了一切。有什么方法可以阻止 AJAX 调用通过 htaccess 设置吗?
无论我尝试什么,我都无法获得带有选择框作为插件的输入。
这是我想要的:
但是,我似乎无法按照输入组的 Bootstrap 指南使其工作:
<div class="input-group">
<input type="text" class="form-control"/>
<select class="form-control input-group-addon">
<option>Item 1</option>
<option>Item 2</option>
</select>
</div>
Run Code Online (Sandbox Code Playgroud)
有人可以帮我吗?我已经找了一段时间了!
这可能是一个基本的OOP问题,但我不确定答案,并且在Google搜索中找不到有用的东西(当然是第一页)
如果我有一个类是另一个实现接口的类的子类,那么我的子类是否会自动成为接口的实现,或者我必须明确地说它是什么?所以
interface HtmlElementInterface {
public function getName();
}
abstract class HtmlElement implements HtmlElementInterface {
protected $_name;
public function __construct($name) {
$this->_name = $name;
}
public function getName() {
return $this->_name;
}
abstract public function __toString();
}
class TextInput extends HtmlElement {
public function __toString() {
return "<input type='input' name='{$this->_name}' id='{$this->_name}' />\n";
}
}
Run Code Online (Sandbox Code Playgroud)
在上述情况下,我没有告诉TextInput
到implement HtmlElementInterface
,难道不是吗?