private void Form1_Load(object sender, EventArgs e) { // Add a text annotation to the chart control's repository. chartControl1.AnnotationRepository.Add(new TextAnnotation("Annotation 1")); // And, assign a series point to the annotation's AnchorPoint property. // This adds the annotation to the series point's Annotations collection. chartControl1.AnnotationRepository[0].AnchorPoint = new SeriesPointAnchorPoint(chartControl1.Series[0].Points[2]); // Now, create an image annotation, and add it to the chart's collection. chartControl1.Annotations.AddImageAnnotation("Annotation 2", Bitmap.FromFile(@"...\...\image.png")); // Define the X and Y absolute coordinates for the annotation, in pixels. ((ChartAnchorPoint)chartControl1.Annotations[0].AnchorPoint).X = 150; ((ChartAnchorPoint)chartControl1.Annotations[0].AnchorPoint).Y = 150; // Obtain the additional pane from the diagram's collection. XYDiagramPaneBase myPane = ((XYDiagram)chartControl1.Diagram).Panes[0]; // And, position the chart's annotation in this pane's right top corner; ((FreePosition)chartControl1.Annotations[0].ShapePosition).DockTarget = myPane; ((FreePosition)chartControl1.Annotations[0].ShapePosition).DockCorner = DockCorner.RightTop; // Another annotation is now being added to the collection of this pane. myPane.Annotations.AddImageAnnotation("Annotation 3", Bitmap.FromFile(@"...\...\image.png")); // Define its axis coordinates (in units appropriate for the scale type of the axes). ((PaneAnchorPoint)myPane.Annotations[0].AnchorPoint).AxisXCoordinate.AxisValue = 2; ((PaneAnchorPoint)myPane.Annotations[0].AnchorPoint).AxisYCoordinate.AxisValue = 180; // Position the annotation in relation to its anchor point. ((RelativePosition)myPane.Annotations[0].ShapePosition).Angle = -135; ((RelativePosition)myPane.Annotations[0].ShapePosition).ConnectorLength = 50; // You can get an annotation either via the collection of the element to which it is anchored, // or centrally, via the chart control's repository (e.g. by its name). TextAnnotation myTextAnnotation = (TextAnnotation)chartControl1.AnnotationRepository.GetElementByName("Annotation 1"); ImageAnnotation myImageAnnotation = (ImageAnnotation)chartControl1.AnnotationRepository.GetElementByName("Annotation 3"); // Define the text for the text annotation. myTextAnnotation.Text = "<i>Basic</i> <b>HTML</b> <u>is</u> <color=blue>supported</color>."; // Enable the interactive positioning for the image annotation. myImageAnnotation.RuntimeMoving = true; myImageAnnotation.RuntimeAnchoring = true; myImageAnnotation.RuntimeResizing = true; myImageAnnotation.RuntimeRotation = true; // Specify image annotation size mode. myImageAnnotation.SizeMode = ChartImageSizeMode.Tile; // And, adjust image annotation appearance options. myImageAnnotation.ShapeKind = ShapeKind.RoundedRectangle; myImageAnnotation.ShapeFillet = 10; myImageAnnotation.ConnectorStyle = AnnotationConnectorStyle.Arrow; }
void UptadeSeries(Series series, XYDiagramPaneBase pane, AxisYBase axis) { XYDiagramSeriesViewBase view = (XYDiagramSeriesViewBase)series.View; view.AxisY = axis; view.Pane = pane; }
AxisYBase GetAxisY(XYDiagramPaneBase currentPane) { for (int i = 0; i < Diagram.Panes.Count; i++) { if (Diagram.Panes[i] == currentPane) { return(Diagram.SecondaryAxesY[i]); } } return(Diagram.AxisY); }
private void BindChart() { ConnDB conn = new ConnDB(); string strsql, strsql2, month; int deptid; deptid = (int)comboBoxDept.SelectedValue; List <Series> myseries = new List <Series>(); month = dateTimePicker1.Text.ToString(); if (deptid == 0) { strsql = "select SALE_TYPE_NAME 营业类型,dept_name 部门,Cdate 日期,DIRECT_HOURS 直接人工小时数,cast(round(DIRECT_COST,2) as decimal(18,2)) 直接人工成本,INDIRECT_HOURS 间接人工小时数,cast(round(INDIRECT_COST,2) as decimal(18,2)) 间接人工成本,cast(round(POINTCOUNT,2) as decimal(18,2)) 点数,cast(round(COST,2) as decimal(18,2)) 预估成本,COST_POINT 预估单点成本,STANDARD_POINT 标准单点成本,cast(round(isnull(STANDARD_COST,0),2) as decimal(18,2)) 标准成本,cast(round(PROFIT,2) as decimal(18,2)) 盈亏 from COST_DEPT_CALCULATE where cdate like '" + month + "%' and sale_type_id =2"; strsql2 = "select distinct dept_name 部门 from COST_DEPT_CALCULATE where cdate like '" + month + "%' and sale_type_id =2"; } else { strsql = "select SALE_TYPE_NAME 营业类型,dept_name 部门,Cdate 日期,DIRECT_HOURS 直接人工小时数,cast(round(DIRECT_COST,2) as decimal(18,2)) 直接人工成本,INDIRECT_HOURS 间接人工小时数,cast(round(INDIRECT_COST,2) as decimal(18,2)) 间接人工成本,cast(round(POINTCOUNT,2) as decimal(18,2)) 点数,cast(round(COST,2) as decimal(18,2)) 预估成本,COST_POINT 预估单点成本,STANDARD_POINT 标准单点成本,cast(round(isnull(STANDARD_COST,0),2) as decimal(18,2)) 标准成本,cast(round(PROFIT,2) as decimal(18,2)) 盈亏 from COST_DEPT_CALCULATE where cdate like '" + month + "%' and sale_type_id =2 and dept_id =" + deptid; strsql2 = "select distinct dept_name 部门 from COST_DEPT_CALCULATE where cdate like '" + month + "%' and sale_type_id =2 and dept_id = " + deptid; } DataSet ds = conn.ReturnDataSet(strsql); DataTable dt = ds.Tables[0]; DataSet ds2 = conn.ReturnDataSet(strsql2); XYDiagram dg = (XYDiagram)chartControlDeptDay.Diagram; if (dg != null) { dg.Panes.Clear(); } chartControlDeptDay.Series.Clear(); chartControlDeptDay.Annotations.Clear(); chartControlDeptDay.DataSource = dt; for (int i = 0; i < ds2.Tables[0].Rows.Count; i++) { //预估成本 myseries.Add(new Series(ds2.Tables[0].Rows[i][0].ToString() + "预估成本", DevExpress.XtraCharts.ViewType.Spline)); myseries[i * 2].ArgumentDataMember = dt.Columns["日期"].ToString(); myseries[i * 2].ValueDataMembersSerializable = dt.Columns["预估成本"].ToString(); chartControlDeptDay.Series.Add(myseries[i * 2]); //标准成本 myseries.Add(new Series(ds2.Tables[0].Rows[i][0].ToString() + "标准成本", DevExpress.XtraCharts.ViewType.Spline)); myseries[i * 2 + 1].ArgumentDataMember = dt.Columns["日期"].ToString(); myseries[i * 2 + 1].ValueDataMembersSerializable = dt.Columns["标准成本"].ToString(); chartControlDeptDay.Series.Add(myseries[i * 2 + 1]); //设置过滤 DataFilter df = new DataFilter("部门", "System.String", DataFilterCondition.Equal, ds2.Tables[0].Rows[i][0].ToString()); //series1.DataFiltersConjunctionMode = ConjunctionTypes.Or; myseries[i * 2].DataFilters.Clear(); myseries[i * 2].DataFilters.AddRange(new DataFilter[] { df }); myseries[i * 2 + 1].DataFilters.Clear(); myseries[i * 2 + 1].DataFilters.AddRange(new DataFilter[] { df }); //设置pane XYDiagram diagram = (XYDiagram)chartControlDeptDay.Diagram; if (i > 0) { //// Add secondary axes to the diagram, and adjust their options. //diagram.SecondaryAxesX.Add(new SecondaryAxisX(Convert.ToString(i - 1))); //diagram.SecondaryAxesY.Add(new SecondaryAxisY(Convert.ToString(i - 1))); //diagram.SecondaryAxesX[i - 1].Alignment = AxisAlignment.Near; //diagram.SecondaryAxesY[i - 1].Alignment = AxisAlignment.Near; //diagram.Panes[ds2.Tables[0].Rows[i][0].ToString()] diagram.Panes.Add(new XYDiagramPane(ds2.Tables[0].Rows[i][0].ToString())); SplineSeriesView myView1 = (SplineSeriesView)myseries[i * 2].View; //myView1.AxisX = diagram.SecondaryAxesX[i - 1]; //myView1.AxisY = diagram.SecondaryAxesY[i - 1]; myView1.Pane = diagram.Panes[i - 1]; SplineSeriesView myView2 = (SplineSeriesView)myseries[i * 2 + 1].View; //myView2.AxisX = diagram.SecondaryAxesX[i - 1]; //myView2.AxisY = diagram.SecondaryAxesY[i - 1]; myView2.Pane = diagram.Panes[i - 1]; chartControlDeptDay.Annotations.AddTextAnnotation(Convert.ToString(i)); XYDiagramPaneBase myPane = diagram.Panes[i - 1]; ((FreePosition)chartControlDeptDay.Annotations[i].ShapePosition).DockTarget = diagram.Panes[i - 1]; ((FreePosition)chartControlDeptDay.Annotations[i].ShapePosition).DockCorner = DockCorner.LeftTop; TextAnnotation myTextAnnotation = (TextAnnotation)chartControlDeptDay.AnnotationRepository.GetElementByName(Convert.ToString(i)); //myTextAnnotation.Text = "<color=red>" + ds2.Tables[0].Rows[i][0].ToString() + " </color>"; myTextAnnotation.Text = ds2.Tables[0].Rows[i][0].ToString(); myTextAnnotation.ShapeKind = ShapeKind.Rectangle; myTextAnnotation.ConnectorStyle = AnnotationConnectorStyle.None; } else { chartControlDeptDay.Annotations.AddTextAnnotation("Annotation 0"); XYDiagramPaneBase myPane = diagram.DefaultPane; ((FreePosition)chartControlDeptDay.Annotations[i].ShapePosition).DockTarget = myPane; ((FreePosition)chartControlDeptDay.Annotations[i].ShapePosition).DockCorner = DockCorner.LeftTop; TextAnnotation myTextAnnotation = (TextAnnotation)chartControlDeptDay.AnnotationRepository.GetElementByName("Annotation 0"); //myTextAnnotation.Text = "<color=red>" + ds2.Tables[0].Rows[i][0].ToString() + " </color>"; myTextAnnotation.Text = ds2.Tables[0].Rows[i][0].ToString(); myTextAnnotation.ShapeKind = ShapeKind.Rectangle; myTextAnnotation.ConnectorStyle = AnnotationConnectorStyle.None; } ((SplineSeriesView)myseries[i * 2].View).MarkerVisibility = DefaultBoolean.True; ((SplineSeriesView)myseries[i * 2 + 1].View).MarkerVisibility = DefaultBoolean.True; ((SplineSeriesView)myseries[i * 2].View).Color = Color.Orange; ((SplineSeriesView)myseries[i * 2 + 1].View).Color = Color.OliveDrab; ((FreePosition)chartControlDeptDay.Annotations[i].ShapePosition).InnerIndents.All = 0; ((FreePosition)chartControlDeptDay.Annotations[i].ShapePosition).OuterIndents.Top = 10; diagram.PaneDistance = 10; diagram.PaneLayoutDirection = PaneLayoutDirection.Vertical; diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight; diagram.DefaultPane.Weight = 1.2; } //外观 chartControlDeptDay.Legend.Visibility = DefaultBoolean.True; chartControlDeptDay.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Center; chartControlDeptDay.Legend.AlignmentVertical = LegendAlignmentVertical.TopOutside; chartControlDeptDay.Legend.Direction = LegendDirection.LeftToRight; conn.Close(); }
protected virtual void SetupXtraChartsPane(XYDiagramPaneBase pane) { var backColor = Utils.ColorFromString(BackColor); if (backColor != Color.Empty) { pane.BackColor = backColor; } var borderColor = Utils.ColorFromString(BorderColor); if (borderColor != Color.Empty) { pane.BorderColor = borderColor; pane.BorderVisible = true; } if (BorderVisible.HasValue) { pane.BorderVisible = true; } if (FillMode.HasValue) { pane.FillStyle.FillMode = FillMode.Value; switch (FillMode.Value) { case DevExpress.XtraCharts.FillMode.Empty: break; case DevExpress.XtraCharts.FillMode.Solid: break; case DevExpress.XtraCharts.FillMode.Gradient: if (pane.FillStyle.Options is RectangleGradientFillOptions gradientOptions) { var backColor2 = Utils.ColorFromString(BackColor2); if (backColor2 != System.Drawing.Color.Empty) { gradientOptions.Color2 = backColor2; } if (FillGradientMode.HasValue) { gradientOptions.GradientMode = FillGradientMode.Value; } } break; case DevExpress.XtraCharts.FillMode.Hatch: if (pane.FillStyle.Options is HatchFillOptions hatchOptions) { var backColor2 = Utils.ColorFromString(BackColor2); if (backColor2 != System.Drawing.Color.Empty) { hatchOptions.Color2 = backColor2; } if (FillHatchStyle.HasValue) { hatchOptions.HatchStyle = FillHatchStyle.Value; } } break; } } if (Column.HasValue) { pane.LayoutOptions.Column = Column.Value; } if (ColumnSpan.HasValue) { pane.LayoutOptions.ColumnSpan = ColumnSpan.Value; } if (Row.HasValue) { pane.LayoutOptions.Row = Row.Value; } if (RowSpan.HasValue) { pane.LayoutOptions.RowSpan = RowSpan.Value; } var shadowColor = Utils.ColorFromString(ShadowColor); if (shadowColor != Color.Empty) { pane.Shadow.Color = shadowColor; pane.Shadow.Visible = true; } if (ShadowSize.HasValue) { pane.Shadow.Size = ShadowSize.Value; pane.Shadow.Visible = true; } if (!string.IsNullOrWhiteSpace(Title)) { pane.Title.Text = Title; pane.Title.Visibility = DefaultBoolean.True; } if (TitleAlignment.HasValue) { pane.Title.Alignment = TitleAlignment.Value; } var font = Utils.StringToFont(TitleFont, out Color titleColor); if (font != null) { pane.Title.Font = font; if (titleColor != Color.Empty) { pane.Title.TextColor = titleColor; } } if (TitleMargins != null && TitleMargins.Length == 1) { pane.Title.Margins.All = TitleMargins[0]; } else if (TitleMargins != null && TitleMargins.Length == 4) { pane.Title.Margins.Left = TitleMargins[0]; pane.Title.Margins.Top = TitleMargins[1]; pane.Title.Margins.Right = TitleMargins[2]; pane.Title.Margins.Bottom = TitleMargins[3]; } }
private void CreateAnnotations(StrategyDataItemInfo info) { if (Visual.Items.Count == 0) { return; } PropertyInfo pInfo = Visual.Items[0].GetType().GetProperty(info.FieldName, BindingFlags.Instance | BindingFlags.Public); PropertyInfo pAnchor = Visual.Items[0].GetType().GetProperty(info.AnnotationAnchorField, BindingFlags.Instance | BindingFlags.Public); PropertyInfo pTime = Visual.Items[0].GetType().GetProperty("Time", BindingFlags.Instance | BindingFlags.Public); XYDiagramPaneBase pane = ((XYDiagram)Chart.Diagram).DefaultPane; if (info.PanelName != "Default") { pane = ((XYDiagram)Chart.Diagram).Panes[info.PanelName]; } int index = 0; ResizeableArray <TextAnnotation> res = new ResizeableArray <TextAnnotation>(); info.DataSource = res; for (int i = 0; i < Visual.Items.Count; i++) { object obj = Visual.Items[i]; object value = pInfo.GetValue(obj); if (value == null) { index++; continue; } if (value is bool && !((bool)value)) { index++; continue; } DateTime time = (DateTime)pTime.GetValue(obj); double yValue = (double)pAnchor.GetValue(obj); string annotationText = string.Empty; if (info.HasAnnotationStringFormat) { annotationText = GetFormattedText(info.AnnotationText, obj); } else { annotationText = Convert.ToString(value); } TextAnnotation annotation = pane.Annotations.AddTextAnnotation(info.FieldName + "InPane" + info.PanelName, annotationText); res.Add(annotation); annotation.Tag = obj; annotation.ConnectorStyle = AnnotationConnectorStyle.Line; annotation.ShapeKind = ShapeKind.Rectangle; annotation.Font = new Font("Segoe UI", 6); ((RelativePosition)annotation.ShapePosition).Angle = 180; ((RelativePosition)annotation.ShapePosition).ConnectorLength = 70; PaneAnchorPoint point = new PaneAnchorPoint(); point.AxisXCoordinate.AxisValue = time; point.AxisYCoordinate.AxisValue = yValue; point.Pane = pane; annotation.AnchorPoint = point; annotation.ShapeKind = ShapeKind.Rectangle; annotation.ShapeKind = ShapeKind.Rectangle; index++; } }
protected virtual void CreateConstantLines(StrategyDataItemInfo info) { XYDiagram dg = (XYDiagram)Chart.Diagram; XYDiagramPaneBase pane = CheckAddPanel(info); Axis axis = null; if (info.PanelName == "Default") { axis = info.ChartType == ChartType.ConstantX? (Axis)dg.AxisX: (Axis)dg.AxisY; } else { if (info.ChartType == ChartType.ConstantX) { axis = dg.SecondaryAxesX[info.PanelName]; } else { axis = dg.SecondaryAxesY[info.PanelName]; } } if (axis == null) { return; } if (axis != null) { System.Collections.IEnumerable en = info.DataSource as System.Collections.IEnumerable; if (en != null) { PropertyInfo pi = null; foreach (object item in en) { if (pi == null) { pi = item.GetType().GetProperty(info.FieldName, BindingFlags.Instance | BindingFlags.Public); } double value = Convert.ToDouble(pi.GetValue(item)); axis.ConstantLines.Add(new ConstantLine() { AxisValue = value, Color = info.Color, Name = item.ToString(), ShowInLegend = false }); } } else { object value = info.DataSource == null ? info.Value : info.DataSource; if (value != null) { axis.ConstantLines.Add(new ConstantLine() { AxisValue = value, Color = info.Color, Name = info.Name, ShowInLegend = false }); } } if (info.ChartType == ChartType.ConstantY) { this.Chart.AxisWholeRangeChanged -= OnYAxisWholeRangeChanged; this.Chart.AxisWholeRangeChanged += OnYAxisWholeRangeChanged; } } }
void ccHousesSales_BoundDataChanged(object sender, EventArgs e) { if (ccHousesSales.Series.Count == 0) { return; } ccHousesSales.BeginInit(); try { List <string> seriesNames = new List <string>(); PaletteEntry[] colors = ccHousesSales.GetPaletteEntries(10); Dictionary <string, XYDiagramPaneBase> panes = new Dictionary <string, XYDiagramPaneBase>(); foreach (XYDiagramPane pane in Diagram.Panes) { pane.Visible = false; } foreach (SecondaryAxisY axisY in Diagram.SecondaryAxesY) { axisY.Visibility = DefaultBoolean.False; axisY.GridLines.Visible = false; axisY.GridLines.MinorVisible = false; } foreach (Series series in ccHousesSales.Series) { string[] splittedName = series.Name.TrimEnd().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); string name = splittedName.Length == 3 ? splittedName[2] : "All Regions"; string key = splittedName[0].Trim() + " (" + splittedName[1].Trim() + ")"; if (seriesNames.Contains(name)) { ((LineSeriesView)series.View).Color = colors[seriesNames.IndexOf(name)].Color; series.ShowInLegend = false; } else { seriesNames.Add(name); ((LineSeriesView)series.View).Color = colors[seriesNames.Count - 1].Color; } series.Name = name; if (panes.Keys.Count == 0) { panes.Add(key, Diagram.DefaultPane); ((TextAnnotation)ccHousesSales.Annotations[0]).Text = key; } else if (panes.ContainsKey(key)) { XYDiagramPaneBase currentPane = panes[key]; UptadeSeries(series, currentPane, GetAxisY(currentPane)); } else { int paneIndex; for (paneIndex = 0; paneIndex < Diagram.Panes.Count; paneIndex++) { if (!panes.ContainsValue(Diagram.Panes[paneIndex])) { break; } } XYDiagramPane pane = Diagram.Panes[paneIndex]; pane.Visible = true; panes.Add(key, pane); SecondaryAxisY axis = Diagram.SecondaryAxesY[paneIndex]; axis.GridLines.Visible = true; axis.GridLines.MinorVisible = true; axis.Visibility = DefaultBoolean.True; UptadeSeries(series, pane, axis); ((TextAnnotation)ccHousesSales.Annotations[paneIndex + 1]).Text = key; } } } finally { ccHousesSales.EndInit(); } }