StackedColumn图表显示了奇怪的列宽 [英] StackedColumn chart shows weird column width

查看:158
本文介绍了StackedColumn图表显示了奇怪的列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这真的是我在这里要做的简单任务。我需要将两个系列作为StackedColumn和1点系列放到一个ChartArea中。下面是代码。
每个系列仅具有三个用于测试目的的数据点。

It's really a simple task I am doing here. I need to put two series as StackedColumn and 1 Point series together in one ChartArea. Below is the code. Each series only has three DataPoints for test purpose.

结果图表显示在下面的第一张图片中。堆叠柱的宽度看起来很小。如果我在三个月中将Point系列的数据更改为每月1个点,那么生成的堆叠列宽看起来就很好(图2)。另外,如果我对s1和s2使用Column而不是StackedColumn,则无论Point系列s3中的什么数据,列宽都将很好(图3)。

The resulting chart looks in the first picture below. The width of the stacked column looks slim. If I change the data of the Point series to 1 point per month over the three months, the resulting stacked column width looks just fine (picture 2). Also, if I use Column instead of StackedColumn for s1 and s2, the column width will be all good (Picture 3), no matter what data in the Point series s3.

有人可以解释这里发生的事情以及如何解决图1中的问题。

Can anybody explain what's going on here and how to fix the problem in picture 1.

        Series s1 = new Series("s1");            
        s1.ChartType = SeriesChartType.StackedColumn;
        //s1.ChartType = SeriesChartType.Column;
        s1.XValueType = ChartValueType.Date;
        s1.Points.Add(new DataPoint((new DateTime(2016, 1, 1)).ToOADate(), 100));
        s1.Points.Add(new DataPoint((new DateTime(2016, 2, 1)).ToOADate(), 100));
        s1.Points.Add(new DataPoint((new DateTime(2016, 3, 1)).ToOADate(), 100));

        Series s2 = new Series("s2");
        s2.ChartType = SeriesChartType.StackedColumn;
        //s2.ChartType = SeriesChartType.Column;
        s2.XValueType = ChartValueType.Date;
        s2.Points.Add(new DataPoint((new DateTime(2016, 1, 1)).ToOADate(), 200));
        s2.Points.Add(new DataPoint((new DateTime(2016, 2, 1)).ToOADate(), 200));
        s2.Points.Add(new DataPoint((new DateTime(2016, 3, 1)).ToOADate(), 200));

        Series s3 = new Series("s3");
        s3.ChartType = SeriesChartType.Point;
        s3.XValueType = ChartValueType.Date;
        s3.Points.Add(new DataPoint((new DateTime(2016, 1, 1)).ToOADate(), 400));
        s3.Points.Add(new DataPoint((new DateTime(2016, 1, 4)).ToOADate(), 400));
        s3.Points.Add(new DataPoint((new DateTime(2016, 1, 7)).ToOADate(), 400));
        //s3.Points.Add(new DataPoint((new DateTime(2016, 1, 1)).ToOADate(), 400));
        //s3.Points.Add(new DataPoint((new DateTime(2016, 2, 4)).ToOADate(), 400));
        //s3.Points.Add(new DataPoint((new DateTime(2016, 3, 7)).ToOADate(), 400));

        cht.Series.Add(s1); cht.Series.Add(s2); cht.Series.Add(s3);

        cht.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Months;
        cht.ChartAreas[0].AxisX.Interval = 1;
        cht.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
        cht.ChartAreas[0].AxisY.MajorGrid.Enabled = false;

推荐答案

根据 StackedColumn上的MSDN a>:


堆叠的序列必须对齐。否则,数据点将被错误地渲染
。有关更多信息,请参见
对齐
数据
。。 p>

Stacked series must be aligned. Otherwise, data points will be rendered incorrectly. For more information, see Aligning Data.

这里是说:


两个系列是如果它们具有相同数量的数据点
和相应的X值中的相同数据,则视为对齐。

Two Series are considered to be aligned if they have the same number of data points and the same data in their corresponding X values.

由于 Point StackedColumn 系列未对齐,因此这些列为丢失的列留出了空间。

Since the Point and the StackedColumn series' are not aligned, the columns make room for the missing columns.

如果要显示的点数比堆积的列数多,这是无法避免的,因为:

This can't really be avoided if you want more points to show than stacked columns because :


系列数:一个或多个(堆叠多个系列)。

Number of series : One or more (multiple series are stacked).

您可以尝试第二 ChartArea 与第一个重叠,然后添加一个Point系列。请参阅此处的两个示例!可能需要进行一些测试才能找到设置第二个海图及其轴的正确方法。

You could try to overlay a second ChartArea with the first one and then add a Point series. See here for two examples! It may take some test to find the right way to set up the second chartarea and its axes..

这篇关于StackedColumn图表显示了奇怪的列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆