【发布时间】:2017-09-29 18:51:01
【问题描述】:
我正在使用react-sparklines 为给定城市绘制 5 天天气数据图表。
这是我的 React 容器(尚未完成),它显示用户搜索的每个城市的天气数据 -
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Sparklines, SparklinesLine } from 'react-sparklines';
class WeatherList extends Component {
constructor(props) {
super(props);
this.renderWeather = this.renderWeather.bind(this);
}
renderWeather(cityData) {
const name = cityData.city.name;
const temps = cityData.list.map(w => w.main.temp);
console.log(temps);
return (
<tr key={name}>
<td>{name}</td>
<td>
<Sparklines height={40} width={80} data={temps}>
<SparklinesLine color="red" />
</Sparklines>
</td>
</tr>
)
}
render() {
return (
<table className="table table-hover">
<thead>
<tr>
<th>City</th>
<th>Temperature</th>
<th>Pressure</th>
<th>Humidity</th>
</tr>
</thead>
<tbody>
{this.props.weather.map(this.renderWeather)}
</tbody>
</table>
)
}
}
function mapStateToProps(state) {
return {weather: state.weather};
}
export default connect(mapStateToProps, null)(WeatherList);
而且,我已经给出了说明每个迷你图的宽度和高度的具体测量值 -
<Sparklines height={40} width={80} data={temps}>
然而,虽然测量结果在 chrome 上呈现时看起来正确,但图表在 Firefox 上完全不成比例。这是截图 -
上面是chrome,下面是Firefox——
接下来,我在 Firefox 和 Chrome 上使用 React Dev Tools 检查了迷你图。结果如下:
该项目仅使用 Bootstrap,没有使用其他 CSS。对于此特定表,仅使用 table 和 table-hover 类。那么,为什么即使width 和height 在两者上都保持不变,图表在 Firefox 上的呈现方式与在 Chrome 上的呈现方式不同?我该如何解决?
【问题讨论】:
标签: css reactjs google-chrome firefox