我创建了一个圆环图,它可以正常工作,但现在我需要在其中心显示数字 45,例如。
我应该在哪里指定要显示的文本和坐标?在图表的选项中?
我正在使用反应组件
class DoughnutChart extends React.Component {
render() {
const data = {
datasets: [{
data: [],
backgroundColor: [
'#999',
'#eee'
]
}],
text: '45'
};
return (
<Doughnut data={data} />
);
}
};
export default DoughnutChart;
Run Code Online (Sandbox Code Playgroud)
编辑
我找到了这个插件,但我找不到它如何应用于反应组件
//Plugin for center text
Chart.pluginService.register({
beforeDraw: function(chart) {
var width = chart.chart.width,
height = chart.chart.height,
ctx = chart.chart.ctx;
ctx.restore();
var fontSize = (height / 160).toFixed(2);
ctx.font = fontSize + "em sans-serif";
ctx.textBaseline = "top";
var text = "Foo-bar",
textX …Run Code Online (Sandbox Code Playgroud) 我一直在阅读类似的问题,直到现在都没有解决这个错误,或者我没有找到它.
我有一个TableView,我需要该表具有特定的行数.
现在它可以处理来自数组的通知计数.在这个数组中,我保留了来自服务器的通知.但我希望如果此数组计数大于40,则行数为40,它们不是数组的计数.
这是我的代码:
class ClassName: UITableViewController, UITabBarControllerDelegate {
public var notifications: [APINotification] = []
override func viewDidLoad() {
super.viewDidLoad()
self.tabBarController?.delegate = self
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 140
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewDidAppear(_ animated: Bool) {
self.notifications = []
self.getLastNotifications()
APIAuth.shared.count_badge = 0
self.tabBarController?.tabBar.items![0].badgeValue = nil
}
public func getLastNotifications() {
let req = Notification()
req.getLastNotifications(onComplete: {events in
self.notifications = events
DispatchQueue.main.async(execute: {
self.tableView.reloadData()
}) …Run Code Online (Sandbox Code Playgroud)