【问题标题】:Draw highcharts with many year for xAxis为 xAxis 绘制多年的 highcharts
【发布时间】:2023-03-25 14:59:01
【问题描述】:

我是 Highligh Charts 的新手,我想创建一个这样的图表:

我的问题是如何像图像一样自定义 xAxis? 请帮我做。 我使用 dotnet 高亮图表。

提前致谢。

编辑

这是源代码:

DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart")
            .SetTitle(new Title()
            {
                Text = "Position of Cash/Group"
            })
            .SetYAxis(new YAxis()
            {
                Title = new YAxisTitle()
                {
                    Text = ""
                },
                Labels = new YAxisLabels
                {
                    Formatter =
                    "function () {if(Math.abs(this.value)>=1000) return this.value / 1000 + 'k'; else return this.value;}"
                }
            })
            .SetXAxis(new XAxis
            {
                TickmarkPlacement = Placement.On,

                Categories =
                    new[] {"1/2016", "2/2016", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"},
            })
            .SetSeries(new Series
            {
                Data =
                    new Data(new object[]
                    {29.9, 71.5, 106.4, 129.2, 1440.0, 176.0, 135.6, -1480.5, 216.4, 194.1, 95.6, 54.4}),
                Color = Color.YellowGreen
            }).SetLegend(new Legend()
            {
                Enabled = false
            }).SetTooltip(new Tooltip()
            {
                Formatter = "function() {if(Math.abs(this.y)>=1000) return this.y / 1000 + 'k'; else return this.y; }"
            }).SetCredits(new Credits()
            {
                Enabled = false

            });

【问题讨论】:

  • 到目前为止你的代码是什么?
  • 如果我看一下this 示例,他们会使用您注释掉的行 (//Categories = )。那有什么问题?您的图片显示您需要 2 行 X-Label 刻度,对吗?是你的问题吗?
  • @Mong Zhu:不,我忘了取消注释类别。
  • 不支持Dotnet.Highlightchart。

标签: javascript c# .net highcharts


【解决方案1】:

感谢您的澄清。 dotnet.highcharts 的问题是,它不支持分组类别。有关声明,请参阅此 link

但是,您可以通过在数组中使用换行符来生成此图表。您可以将其硬编码到您的数组中,例如"May\r\n2016",或者您可以编写一个函数来编辑您的数组以在中间位置附加换行符 + 年份或类似的东西。也许您需要基于您的环境的另一个换行命令,但这将是一种摆弄的方法。祝你好运!


您可以使用分组类别,这样您就可以创建所需的 xAxis 标签。这是一个link,其中有一个来自 github 的示例。

【讨论】:

  • 我正在使用 Dotnet.HighlightChart,它不支持 DotNet
  • 编辑对您有帮助吗?你有进步吗?
猜你喜欢
  • 1970-01-01
  • 2022-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多