问题描述:FpChart如何实现多Y轴图表功能。
问题解答:FpChart支持多Y轴图表功能,而且可通过图表设计器或编码添加图表,图表中的标题、系列、Y轴、X轴、图例等元素均可自定义。
关键代码:
设置线性数据系列lineSeries的相关属性,并通过YAxisId属性关联到相关的Y轴上。
- FarPoint.Win.Chart.LineSeries lineSeries2 = new FarPoint.Win.Chart.LineSeries();
- lineSeries2.SeriesName = "系列2";
- lineSeries2.SmoothedLine = true;
- lineSeries2.Values.AddRange(new double[] {
- 100D,
- 130D,
- 231D,
- 180D,
- 350D});
- lineSeries2.YAxisId = 1;
- yPlotArea1.Series.AddRange(new FarPoint.Win.Chart.Series[] {
- lineSeries1,
- lineSeries2,
- lineSeries3,
- lineSeries4,
- lineSeries5,
- lineSeries6,
- lineSeries7,
- lineSeries8});
复制代码
设置轴的子属性,并添加多个Y轴。
- FarPoint.Win.Chart.ValueAxis valueAxis1 = new FarPoint.Win.Chart.ValueAxis(); valueAxis1.LabelOffset = 5F;
- valueAxis1.RulerLine = new FarPoint.Win.Chart.SolidLine(System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(255))))), 0.75F);
- valueAxis1.Title = "Y-1";
- valueAxis1.TitleOffset = 0F;
- valueAxis1.TitleTextDirection = FarPoint.Win.Chart.TextDirection.Vertical;
- valueAxis1.TitleTextFont = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
-
- yPlotArea1.YAxes.AddRange(new FarPoint.Win.Chart.ValueAxis[] {
- valueAxis1,
- valueAxis2,
- valueAxis3,
- valueAxis4,
- valueAxis5,
- valueAxis6,
- valueAxis7,
- valueAxis8});
复制代码
效果截图:
示例下载:
|