找回密码
 立即注册

QQ登录

只需一步,快速开始

306828231

注册会员

8

主题

22

帖子

156

积分

注册会员

积分
156

微信认证勋章

306828231
注册会员   /  发表于:2019-1-18 09:44  /   查看:2735  /  回复:2
本帖最后由 306828231 于 2019-1-18 14:54 编辑


你好,我使用SpreadChart做图表,添加了1个柱状图、2个折线图。

柱状图的最小值和最大值相关太大时,Y轴会出现非常多的刻度线,如下图

image.png193479918.png

请问这些线可以以隐藏吗,或者设置成和背景相同的颜色

附上代码:

//柱状图

                BarSeries bar = new BarSeries();


                bar.YAxisId = 0;

                bar.LabelVisible = true;


                //最大工作时间折线图

                LineSeries maxLine = new LineSeries();

                maxLine.PointMarker = new BuiltinMarker(MarkerShape.Diamond, 2.0F);

                maxLine.YAxisId = 0;

                maxLine.LabelVisible = false;

                maxLine.LineBorder = new SolidLine(Color.Red,1.5F);


                //定时工作时间折线图

                LineSeries stdLine = new LineSeries();

                stdLine.PointMarker = new BuiltinMarker(MarkerShape.Diamond, 2.0f);

                stdLine.YAxisId = 0;

                stdLine.LabelVisible = false;

                stdLine.LineBorder = new SolidLine(Color.Orange, 1.5f);


                for (int x = 2; x < _myTblData.Columns.Count; x++)

                {

                    var dc = _myTblData.Columns[x];

                    var that = data.FirstOrDefault(s => s.WORK_DATE == Convert.ToDateTime(dc.ColumnName) && s.DATA_TYPE == type);

                    if (that != null)

                    {

                        bar.Values.Add(Convert.ToDouble(ToHours(that.WORK_TIME_ACT)));


                        stdLine.Values.Add(Convert.ToDouble(ToHours(that.WORK_TIME_STD)));


                        maxLine.Values.Add(Convert.ToDouble(ToHours(that.WORK_TIME_MAX)));

                    }

                    else

                    {

                        bar.Values.Add(0);

                        stdLine.Values.Add(0);

                        maxLine.Values.Add(0);

                    }

                }

                //折线图设置

                ValueAxis axisConfig = new ValueAxis();

                axisConfig.AxisId = 1;

                axisConfig.AutoMaximum = true;

                axisConfig.AutoMinimum = true;

                //隐藏折线图Y轴

                axisConfig.LabelVisible = false;

                axisConfig.Location = AxisLocation.Far;


                //Y绘图区

                YPlotArea plotArea = new YPlotArea();

                plotArea.Location = new PointF(0, 0.19F);

                plotArea.Size = new SizeF(1, 0.8F);

                plotArea.Series.Add(bar);

                plotArea.Series.Add(stdLine);

                plotArea.Series.Add(maxLine);

                //隐藏左边Y轴标尺

                plotArea.YAxes[0].RulerLine = new NoLine();

                //隐藏X轴下的数字

                plotArea.XAxis.LabelVisible = false;

                plotArea.XAxis.RulerLine = new NoLine();

                //隐藏柱状图Y轴数字

                plotArea.YAxes[0].LabelVisible = false;

                plotArea.YAxes.Add(axisConfig);


                ChartModel model = new ChartModel();

                model.PlotAreas.Add(plotArea);

                var chart = new FarPoint.Win.Spread.Chart.SpreadChart();

                chart.CanMove = FarPoint.Win.Spread.DrawingSpace.Moving.None;

                chart.CanSize = FarPoint.Win.Spread.DrawingSpace.Sizing.None;

                chart.Size = new Size((_mySheet.ColumnCount - 2) * 30, _spanRowHeight * 4);


                int chartY = Convert.ToInt32((_oneAreaMiniRows + type.Count()) * _rowHeihgt) + (_oneAreaMiniRows + type.Count) * 2 + 2;

                if (i > 0)

                {

                    chartY = chartY + Convert.ToInt32(_spanRowHeight * 4 + 1);

                }


                chart.Location = new Point(_spreadCol1HeaderWidth * 2, chartY);

                chart.Model = model;

                _mySpread.ActiveSheet.Charts.Add(chart);



2 个回复

倒序浏览
306828231
注册会员   /  发表于:2019-1-18 14:53:24
沙发
已解决,设置:
plotArea.YAxes[0].MajorGridLine = new NoLine();
plotArea.YAxes[1].MajorGridLine = new NoLine();

之前因为只设置了:
plotArea.YAxes[0].MajorGridLine = new NoLine();
没看到效果,以为不是这样设置
回复 使用道具 举报
dexteryao讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2019-1-18 19:09:14
板凳
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部