c# - 如何减少 DotNet.Highcharts 中的列序列间隙

标签 c# charts dotnethighcharts column-chart

我正在使用 DotNet.Highchart 库创建我的图表,我在减少柱形图中数据系列之间的差距方面遇到了问题。这是我当前的图表:

enter image description here

这是我当前的柱形图代码:

DotNet.Highcharts.Highcharts AttritionByReasonBarChart = new DotNet.Highcharts.Highcharts("AttritionByReasonBarChart")
                .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column, Height = 400, Width = 860, Style = "margin: '0 auto'" })
                .SetTitle(new Title { Text = "Attrition by Reason", Style = "font: 'normal 16px Verdana, sans-serif'" })
                .SetCredits(new Credits { Enabled = false })
                .SetXAxis(new XAxis
                {
                    Categories = vEmployment,
                    Labels = new XAxisLabels { Rotation = 0 }
                })
                .SetYAxis(new YAxis
                {
                    Title = new YAxisTitle
                    {
                        Text = "Employment Type",
                        Align = AxisTitleAligns.Middle
                    }
                })
                .SetPlotOptions(new PlotOptions
                {
                    Bar = new PlotOptionsBar
                    {
                        DataLabels = new PlotOptionsBarDataLabels { Enabled = true }
                    }
                })
                .SetLegend(new Legend
                {
                    Layout = Layouts.Vertical,
                    Align = HorizontalAligns.Right,
                    VerticalAlign = VerticalAligns.Middle,
                    Floating = true,
                    BorderWidth = 1,
                    BackgroundColor = new BackColorOrGradient(ColorTranslator.FromHtml("#FFFFFF")),
                    Shadow = true
                })
                .SetSeries(
                    new Series
                    { 
                        Name = "Head Count",
                        Data = new Data(vTotal)
                    });

有没有最好的方法来设置数据系列之间的差距? 谢谢

最佳答案

PlotOptionsBar 替换为 PlotOptionsColumn 并将 PointPadding 添加到您的代码中,如下所示:

Highcharts AttritionByReasonBarChart = new Highcharts("AttritionByReasonBarChart")
            .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column, Height = 400, Width = 860, Style = "margin: '0 auto'" })
            .SetTitle(new Title { Text = "Attrition by Reason", Style = "font: 'normal 16px Verdana, sans-serif'" })
            .SetCredits(new Credits { Enabled = false })
            .SetXAxis(new XAxis
            {
                Categories = new[] { "ABHFGFGETTRRD AGAGGSGSGS", "IEKHLTOTUYYT IIWWIIWEUEUEU", "KMVMVBBV DGDFEFJ", "KRJG JGJGJGT", "HAHAHSHSGD OTERETETE ET", "HAHAHA PRGDGDGDGDG DGT", "NRIRITITITITI WP", "DFC AHAHSSGGDF" },
                Labels = new XAxisLabels { Rotation = 0 }
            })
            .SetYAxis(new YAxis
            {
                Title = new YAxisTitle
                {
                    Text = "Employment Type",
                    Align = AxisTitleAligns.Middle
                }
            })
            .SetPlotOptions(new PlotOptions
            {
                Column = new PlotOptionsColumn
                {
                    PointPadding = -0.2,
                    DataLabels = new PlotOptionsColumnDataLabels { Enabled = false }
                }
            })
            .SetLegend(new Legend
            {
                Layout = Layouts.Vertical,
                Align = HorizontalAligns.Right,
                VerticalAlign = VerticalAligns.Middle,
                Floating = true,
                BorderWidth = 1,
                BackgroundColor = new BackColorOrGradient(ColorTranslator.FromHtml("#FFFFFF")),
                Shadow = true
            })
            .SetSeries(
                new Series
                {
                    Name = "Head Count",
                    Data = new Data(new object[] { 30,10,5,20,5,10,25,15 })
                });

enter image description here

关于c# - 如何减少 DotNet.Highcharts 中的列序列间隙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38071375/

相关文章:

c# - 使用 WCF 的 MSMQ 监听器

c# - 有没有一种简单的方法可以将数字转换为十万和千万的印度文字格式?

javascript - 将 y 刻度扩展到 d3 条形图中所需数字的方法

asp.net-mvc - Dotnet HighCharts - 位于一页上的多个图表

c# - 继续在 dotnet highchart 上画线

c# - 当我尝试加载 xml 文件时,为什么出现解析 EntityName 时出错?

c# - 如何根据 C# 中缺少的属性生成编译器错误?

javascript - 在 y 轴上显示文本而不是数值

charts - Excel VBA - 如何设置图表系列的线条样式?