du8828 2018-11-06 13:46
浏览 56
已采纳

go-go图表库中的文本旋转

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 textenter image description here

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

  • 写回答

1条回答 默认 最新

  • duanchuang3182 2018-11-06 15:17
    关注

    When creating a chart.BarChart, just add TextRotationDegrees to the style of your XAxis

    XAxis: chart.Style{
        Show:                true,
        TextRotationDegrees: 45.0,
    },
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分