go - Text rotation in go- go chart library
问题描述
I am using go chart library https://github.com/wcharczuk/go-chart to make a bar chart. The problem I am facing is that the label values are of long length and I want to rotate the text with 45 degree to show the complete text
The date format I like to show is like this 2018-05-12
.
var values []chart.Value
for k, v := range timeline {
// leng += 1
new_data := k[0:10]
println(new_data)
val := float64(v)
values = append(values, chart.Value{Label: new_data, Value: val, Style: chart.Style{FontColor: drawing.Color{R: 255, G: 0, B: 0, A: 255}, FontSize: 4.0}})
}
pie := chart.BarChart{
Title: "Timeline Chart",
Height: 350,
TitleStyle: chart.StyleShow(),
Background: chart.Style{
Padding: chart.Box{
Top: 40,
},
},
BarWidth: 60,
XAxis: chart.StyleShow(),
YAxis: chart.YAxis{
Style: chart.StyleShow(),
// TickStyle: chart.Style{
// TextRotationDegrees: 45.0,
// },
NameStyle: chart.Style{Show: true, TextRotationDegrees: 45.0},
},
Bars: values,
}
The chart.Style property is also not working as I want to make font size small and change color of the label text
解决方案
创建时chart.BarChart
,只需添加TextRotationDegrees
到您的样式XAxis
XAxis: chart.Style{
Show: true,
TextRotationDegrees: 45.0,
},
推荐阅读
- jquery - Vue.js 通过外部库对 DOM 进行动态更改(jQuery 样式)
- html - 本地存储记住单击的选项卡类
- spring-boot - 动态添加队列消费者春季问题
- ios - StoreKit 测试应用内购买 Xcode 12 beta 和 iOS 13 或更低版本
- multithreading - 机器上的线程数和 ThreadPool 线程数
- firebase - 在 Flutter 中使用 FirebaseAuth 检查用户的身份验证状态
- javascript - Node js 中的 response.on() 方法有什么作用
- java - 如何不允许用户突出显示 JTextArea 中的文本?但是我只能突出显示文本吗?
- android - 使用 Jetpack Benchmark 执行测试时的 INSTALL_FAILED_DUPLICATE_PERMISSION
- python - django.db.utils.OperationalError:没有这样的表:polls_post