原創|其它|編輯:郝浩|2012-11-06 10:14:17.000|閱讀 352 次
概述:Nevron SharePoint使用一個點圖表類型表示XY散點圖,附加源碼。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
假設你正在使用一個點的圖表類型表示XY散點圖,假設你的數據源有兩列,X和Y - 定義數據點的X和Y坐標。同時也使這個圖表中有一個單一的類別分組表達式:=Fields![RowIndex] (例如按照列來分組)。
這個代碼實例創建了X和Y恒定的線,這是一般定位的X和Y坐標的平均值。代碼實例根據他們所屬的平均象限點來為他們著色。
要獲取的 X 和 Y 的列的平均值,我們使用兩個代碼參數:
Name: AverageX, Expression: =AVG(Fields!X)
Name: AverageY, Expression: =AVG(Fields!Y)
下面的代碼就是就是添加這個constant lines到第一個圖表區域,根據它們所屬的區域為這些點著色。
using System; using System.Drawing; using Nevron.GraphicsCore; using Nevron.Chart; using Nevron.ReportingServices; namespace MyNamespace { /// <summary> /// Sample class /// </summary> public class MyClass { /// <summary> /// Main entry point /// </summary> /// <param name="context"></param> public static void RSMain(NRSChartCodeContext context) { if (context.Document.Charts.Count == 0) return; // get the first chart in the document NChart chart = context.Document.Charts[0]; if (chart.Series.Count == 0) return; // get the first point series in the chart NPointSeries point = chart.Series[0] as NPointSeries; if (point == null) return; // get the evaluated average X and Y double averageX = context.GetDoubleParameter("AverageX"); double averageY = context.GetDoubleParameter("AverageY"); // initialize quadrant colors Color[] quadrantColors = new Color[4]; quadrantColors[0] = Color.Red; quadrantColors[1] = Color.Green; quadrantColors[2] = Color.Blue; quadrantColors[3] = Color.Yellow; // get the X and Y primary axes NAxis xAxis = chart.Axis(StandardAxis.PrimaryX); NAxis yAxis = chart.Axis(StandardAxis.PrimaryY); // add a constline for the left axis NAxisConstLine averageYConstLine = yAxis.ConstLines.Add(); averageYConstLine.Value = averageY; // add a constline for the bottom axis NAxisConstLine averageXConstLine = xAxis.ConstLines.Add(); averageXConstLine.Value = averageX; // colorize the data points according to quadrant int count = point.Values.Count; for (int i = 0; i < count; i++) { int quadrant = 0; double yValue = (double)point.Values[i]; double xValue = (double)point.XValues[i]; // determine quadrant if (yValue > averageY) { if (xValue > averageX) { quadrant = 0; } else { quadrant = 1; } } else { if (xValue > averageX) { quadrant = 3; } else { quadrant = 2; } } // set point color depending on quadrant point.FillStyles[i] = new NColorFillStyle(quadrantColors[quadrant]); } } } }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件