为什么我的 RadChart StackedBarChart 没有堆叠条形图以匹配 Y 轴?

发布于 2024-12-23 07:22:25 字数 1060 浏览 4 评论 0原文

我在 Silverlight 4.0 中使用 Telerik RadChart 控件。我有一个问题,因为我认为我的数据集存在差异,这导致我的较大堆叠条形图被裁剪在 ChartArea 内。没问题,我想,我可以循环遍历所有数据并找到 StackedBar 必须达到的最大尺寸,然后调整 y 轴的比例。这是我选择实施的方法。

    private void ForceScaleOfYaxis(IEnumerable<ChartObject> chartData)
    {
        double sum = 0;
        foreach (var bar in chartData)
        {
            sum = Math.Max(sum, bar.Series1 +
                                bar.Series2 +
                                bar.Series3 +
                                bar.Series4 +
                                bar.Series5);
        }

        ChartArea chartArea = radChart1.DefaultView.ChartArea;
        chartArea.AxisY.AutoRange = true;
        double min = chartArea.AxisY.ActualMinValue;
        double step = sum / 10; 
        chartArea.AxisY.AutoRange = false;
        chartArea.AxisY.AddRange(min, sum, step); 
    }

这非常有效,因为它将 y 轴更改为等于堆叠条形图系列值的最大总和。

现在我有一个不同的问题:我正确设置了 y 轴的比例,但图表似乎没有堆叠。 堆叠条形图

人们可以通过下面的图表看到这一点,如该屏幕截图所示。

I am using Telerik RadChart controls for Silverlight with Silverlight 4.0. I have a problem, due I think to the variance in my data sets, which causes my larger stacked bars to be clipped within the ChartArea. No problem, I thought, I can just loop through all my data and find the maximum size my StackedBar has to be, and adjust the scale of the y-axis. Here's the method I chose to implement.

    private void ForceScaleOfYaxis(IEnumerable<ChartObject> chartData)
    {
        double sum = 0;
        foreach (var bar in chartData)
        {
            sum = Math.Max(sum, bar.Series1 +
                                bar.Series2 +
                                bar.Series3 +
                                bar.Series4 +
                                bar.Series5);
        }

        ChartArea chartArea = radChart1.DefaultView.ChartArea;
        chartArea.AxisY.AutoRange = true;
        double min = chartArea.AxisY.ActualMinValue;
        double step = sum / 10; 
        chartArea.AxisY.AutoRange = false;
        chartArea.AxisY.AddRange(min, sum, step); 
    }

This worked quite well, in that it changed the y-axis to equal the largest sum of series values for the stacked bar.

Now I have a different problem: I correctly set the scale of the y-axis, but the Charts do not appear to stack.
Stacked Bar Chart

One can see this with the following chart, as seen in this screen shot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十级心震 2024-12-30 07:22:25

我认为这与 YAxis Range 引起的条形裁剪无关,而是与数据分组和填充图表的方式有关。
您的示例项目应该可以更多地阐明真正的问题。

I don't think that this is related to the clipping of bars caused by the YAxis Range but rather the way you Group the data and populate the Chart.
A sample project of yours should shed some more light on the real issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文