void MapObject(PlotArea plotArea, DocumentObjectModel.Shapes.Charts.PlotArea domPlotArea) { plotArea.BottomPadding = domPlotArea.BottomPadding.Point; plotArea.RightPadding = domPlotArea.RightPadding.Point; plotArea.LeftPadding = domPlotArea.LeftPadding.Point; plotArea.TopPadding = domPlotArea.TopPadding.Point; if (!domPlotArea.IsNull("LineFormat")) { LineFormatMapper.Map(plotArea.LineFormat, domPlotArea.LineFormat); } if (!domPlotArea.IsNull("FillFormat")) { FillFormatMapper.Map(plotArea.FillFormat, domPlotArea.FillFormat); } }
// // Create chart // private void createChart(RazorChartViewer viewer, int chartIndex) { // The data for the chart double[] data = { 85, 156, 179.5, 211, 123 }; string[] labels = { "Mon", "Tue", "Wed", "Thu", "Fri" }; // Create a XYChart object of size 270 x 270 pixels XYChart c = new XYChart(270, 270); // Set the plot area at (40, 32) and of size 200 x 200 pixels PlotArea plotarea = c.setPlotArea(40, 32, 200, 200); // Set the background style based on the input parameter if (chartIndex == 0) { // Has wallpaper image c.setWallpaper(Url.Content("~/Content/tile.gif")); } else if (chartIndex == 1) { // Use a background image as the plot area background plotarea.setBackground2(Url.Content("~/Content/bg.png")); } else if (chartIndex == 2) { // Use white (0xffffff) and grey (0xe0e0e0) as two alternate plotarea background colors plotarea.setBackground(0xffffff, 0xe0e0e0); } else { // Use a dark background palette c.setColors(Chart.whiteOnBlackPalette); } // Set the labels on the x axis c.xAxis().setLabels(labels); // Add a color bar layer using the given data. Use a 1 pixel 3D border for the bars. c.addBarLayer3(data).setBorderColor(-1, 1); // Output the chart viewer.Image = c.makeWebImage(Chart.PNG); // Include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("", "", "title='Revenue for {xLabel}: US${value}K'"); }
internal override void Render() { RenderFilling(); Area contentArea = _renderInfo.LayoutInfo.ContentArea; ChartFormatInfo formatInfo = (ChartFormatInfo)_renderInfo.FormatInfo; if (formatInfo.FormattedHeader != null) { RenderArea(formatInfo.FormattedHeader, GetHeaderRect()); } if (formatInfo.FormattedFooter != null) { RenderArea(formatInfo.FormattedFooter, GetFooterRect()); } if (formatInfo.FormattedTop != null) { RenderArea(formatInfo.FormattedTop, GetTopRect()); } if (formatInfo.FormattedBottom != null) { RenderArea(formatInfo.FormattedBottom, GetBottomRect()); } if (formatInfo.FormattedLeft != null) { RenderArea(formatInfo.FormattedLeft, GetLeftRect()); } if (formatInfo.FormattedRight != null) { RenderArea(formatInfo.FormattedRight, GetRightRect()); } PlotArea plotArea = (PlotArea)_chart.GetValue("PlotArea", GV.ReadOnly); if (plotArea != null) { RenderPlotArea(plotArea, GetPlotRect()); } RenderLine(); }
//adds image private void AnnotatePie(C1.Win.C1Chart.C1Chart chart) { Style s = chart.ChartLabels.DefaultLabelStyle; s.Opaque = false; s.Border.BorderStyle = BorderStyleEnum.None; C1.Win.C1Chart.Label label = chart.ChartLabels.LabelsCollection.AddNewLabel(); label.Text = chart.ChartGroups[0].ChartData.SeriesList[0].X[0].ToString(); label.Compass = LabelCompassEnum.South; label.Visible = true; label.AttachMethod = AttachMethodEnum.Coordinate; PlotArea plot = chart.ChartArea.PlotArea; label.AttachMethodData.X = plot.Location.X; label.AttachMethodData.Y = plot.Location.Y + (plot.Size.Width / 2); }
protected void BuildTitle(ParametersBase parameters) { if (parameters.ShowTitle) { TitleArea = new Rect( PlotArea.Left, 0, PlotArea.Width, 30); PlotArea = PlotArea .WithTop(PlotArea.Top + TitleArea.Height) .WithHeight(Math.Max(PlotArea.Height - TitleArea.Height, 0)); } else { TitleArea = new Rect(PlotArea.Left, 0, 0, 0); } }
public static void AddPieChart(Group elements, float x, float y) { AddCaptionAndRectangle(elements, "Pie Chart", x, y, 225, 225); // Create a chart Chart chart = new Chart(x + 10, y + 25, 200, 200, Font.Helvetica, 10, RgbColor.Black); // Add a plot area to the chart PlotArea plotArea = chart.PlotAreas.Add(50, 50, 300, 300); // Create the Header title and add it to the chart Title tTitle = new Title("Website Visitors (in millions)"); chart.HeaderTitles.Add(tTitle); // Create a scalar datalabel ScalarDataLabel da = new ScalarDataLabel(true, false, false); // Create autogradient colors AutoGradient autogradient1 = new AutoGradient(90f, CmykColor.Red, CmykColor.IndianRed); AutoGradient autogradient2 = new AutoGradient(90f, CmykColor.Green, CmykColor.YellowGreen); AutoGradient autogradient3 = new AutoGradient(90f, CmykColor.Blue, CmykColor.LightBlue); // Create a pie series PieSeries pieSeries = new PieSeries(); // Set scalar datalabel to the pie series pieSeries.DataLabel = da; // Add series to the plot area plotArea.Series.Add(pieSeries); //Add pie series elements to the pie series pieSeries.Elements.Add(27, "Website A"); pieSeries.Elements.Add(19, "Website B"); pieSeries.Elements.Add(21, "Website C"); // Assign autogradient colors to series elements pieSeries.Elements[0].Color = autogradient1; pieSeries.Elements[1].Color = autogradient2; pieSeries.Elements[2].Color = autogradient3; chart.Legends[0].Visible = false; elements.Add(chart); }
/// <summary> /// 根据在坐标轴中的值,来返回这个值在Chart中的几何位置 /// </summary> /// <param name="Ax"></param> /// <param name="Value"></param> /// <returns>如果Ax是一个水平X轴,则返回的是坐标轴Ax中的值Value在Chart中的Left值; /// 如果Ax是一个竖向Y轴,则返回的是坐标轴Ax中的值Value在Chart中的Top值。</returns> /// <remarks></remarks> public static double GetPositionInChartByValue(Axis Ax, double Value) { double PositionInChartByValue = 0; Chart cht = (Chart)Ax.Parent; // double max = Ax.MaximumScale; double min = Ax.MinimumScale; // PlotArea PlotA = cht.PlotArea; switch (Ax.Type) { case XlAxisType.xlCategory: //横向X轴 double PositionInPlot_1 = 0; if (Ax.ReversePlotOrder == false) //正向分类,说明X轴数据为左边小右边大 { PositionInPlot_1 = PlotA.InsideWidth * (Value - min) / (max - min); } else //逆序类别,说明X轴数据为左边大右边小 { PositionInPlot_1 = PlotA.InsideWidth * (max - Value) / (max - min); } PositionInChartByValue = PlotA.InsideLeft + PositionInPlot_1; break; case XlAxisType.xlValue: //竖向Y轴 double PositionInPlot = 0; if (Ax.ReversePlotOrder == false) //顺序刻度值,说明Y轴数据为下边小上边大 { PositionInPlot = PlotA.InsideHeight * (max - Value) / (max - min); } else //逆序刻度值,说明Y轴数据为上边小下边大 { PositionInPlot = PlotA.InsideHeight * (Value - min) / (max - min); } PositionInChartByValue = PlotA.InsideTop + PositionInPlot; break; case XlAxisType.xlSeriesAxis: break; //Debug.Print("暂时不知道这是什么坐标轴") } return(PositionInChartByValue); }
public static void AddLineChart(Group elements, float x, float y) { AddCaptionAndRectangle(elements, "Line Chart", x, y, 225, 225); // Create a chart Chart chart = new Chart(x + 10, y + 25, 200, 200, Font.Helvetica, 10, RgbColor.Black); // Create a plot area PlotArea plotArea = chart.PrimaryPlotArea; // Create header title and add it to the chart Title title1 = new Title("Website Visitors"); chart.HeaderTitles.Add(title1); // Create a indexed line series and add values to it IndexedLineSeries lineSeries1 = new IndexedLineSeries("Website A"); lineSeries1.Values.Add(new float[] { 5, 7, 9, 6 }); IndexedLineSeries lineSeries2 = new IndexedLineSeries("Website B"); lineSeries2.Values.Add(new float[] { 4, 2, 5, 8 }); IndexedLineSeries lineSeries3 = new IndexedLineSeries("Website C"); lineSeries3.Values.Add(new float[] { 2, 4, 6, 9 }); // Add indexed line series to the plot area plotArea.Series.Add(lineSeries1); plotArea.Series.Add(lineSeries2); plotArea.Series.Add(lineSeries3); // Create a title and add it to the yaxis Title lTitle = new Title("Visitors (in millions)"); lineSeries1.YAxis.Titles.Add(lTitle); //Adding AxisLabels to the XAxis lineSeries1.XAxis.Labels.Add(new IndexedXAxisLabel("Q1", 0)); lineSeries1.XAxis.Labels.Add(new IndexedXAxisLabel("Q2", 1)); lineSeries1.XAxis.Labels.Add(new IndexedXAxisLabel("Q3", 2)); lineSeries1.XAxis.Labels.Add(new IndexedXAxisLabel("Q4", 3)); chart.Legends[0].Visible = false; elements.Add(chart); }
protected void AppendCategoryAxis(PlotArea plotArea, uint id, string name, uint crossingAxisId, bool show = true) { List <OpenXmlElement> elements = GetAxisElements(id, name, crossingAxisId, show); elements.Add(new AxisPosition { Val = new EnumValue <AxisPositionValues>(AxisPositionValues.Bottom) }); elements.Add(new AutoLabeled { Val = new BooleanValue(true) }); elements.Add(new LabelAlignment { Val = new EnumValue <LabelAlignmentValues>(LabelAlignmentValues.Center) }); elements.Add(new LabelOffset { Val = new UInt16Value((ushort)100) }); plotArea.AppendChild(new CategoryAxis(elements)); }
public override OpenXmlCompositeElement CreateChart(PlotArea plotArea) { var chart = plotArea.AppendChild <BarChart>(new BarChart()); chart.Append(new BarDirection() { Val = BarDirectionValues.Column }); chart.Append(new BarGrouping() { Val = BarGroupingValues.Clustered }); chart.Append(new VaryColors() { Val = false }); return(chart); }
public IPieChart InsertPieChart() { ChartSpace chartSpace = this.chartPart.ChartSpace; Chart chart = chartSpace.GetFirstChild <Chart>() ?? chartSpace.AppendChild(new Chart()); PlotArea plotArea = chart.PlotArea ?? (chart.PlotArea = new PlotArea()); return(new OpenXmlPieChart( this, plotArea.AppendChild( new DoughnutChart() .AppendChildFluent(new PieChartSeries() { Index = new Index() { Val = 0 } }) ) )); }
public IBarChart InsertBarChart(CartesianAxes axes) { ChartSpace chartSpace = this.chartPart.ChartSpace; Chart chart = chartSpace.GetFirstChild <Chart>() ?? chartSpace.AppendChild(new Chart()); PlotArea plotArea = chart.PlotArea ?? (chart.PlotArea = new PlotArea()); return(new OpenXmlBarChart( this, plotArea.AppendChild( new BarChart() .AppendChildFluent(new AxisId() { Val = axes.CategoryAxis.Id }) .AppendChildFluent(new AxisId() { Val = axes.ValueAxis.Id }) ) )); }
protected void AppendValueAxis(PlotArea plotArea, uint id, string name, uint crossingAxisId, AxisPositionValues axisPos = AxisPositionValues.Left, TickLabelPositionValues tickPos = TickLabelPositionValues.NextTo, bool showMajorGridlines = true) { List <OpenXmlElement> elements = GetAxisElements(id, name, crossingAxisId, tickPosition: tickPos); elements.Add(new AxisPosition { Val = new EnumValue <AxisPositionValues>(axisPos) }); if (showMajorGridlines) { elements.Add(new MajorGridlines()); } elements.Add(new DocumentFormat.OpenXml.Drawing.Charts.NumberingFormat() { FormatCode = new StringValue("General"), SourceLinked = new BooleanValue(true) }); elements.Add(new CrossBetween { Val = new EnumValue <CrossBetweenValues>(CrossBetweenValues.Between) }); plotArea.AppendChild(new ValueAxis(elements)); }
public ILineChart InsertLineChart(CartesianAxes axes) { ChartSpace chartSpace = this.chartPart.ChartSpace; Chart chart = chartSpace.GetFirstChild <Chart>() ?? chartSpace.AppendChild(new Chart()); PlotArea plotArea = chart.PlotArea ?? (chart.PlotArea = new PlotArea()); Marker marker = new Marker(); marker.SetAttribute(new DocumentFormat.OpenXml.OpenXmlAttribute("Val", marker.NamespaceUri, "1")); return(new OpenXmlLineChart( this, plotArea.AppendChild( new LineChart() .AppendChildFluent(new Grouping() { Val = GroupingValues.Standard }) .AppendChildFluent(new VaryColors() { Val = true }) .AppendChildFluent(new Marker()) .AppendChildFluent(new Smooth() { Val = false }) .AppendChildFluent(new AxisId() { Val = axes.CategoryAxis.Id }) .AppendChildFluent(new AxisId() { Val = axes.ValueAxis.Id }) ) )); }
// // Draw track line with data labels // private void trackLineLabel(XYChart c) { // Clear the current dynamic layer and get the DrawArea object to draw on it. DrawArea d = c.initDynamicLayer(); // In this example, we have two track lines. const int trackLineCount = 2; if (trackLinePos.Count == 0) { // Initialize the track line position by distributing them on the plot area PlotArea p = c.getPlotArea(); for (int i = 0; i < trackLineCount; ++i) { trackLinePos.Add(p.getLeftX() + (int)(p.getWidth() * (i + 0.5) / trackLineCount)); } } // Record the positions with the track lines var trackLineLog = new Dictionary <string, double> [trackLineCount]; // Draw the track lines if enabled if (trackLine1Enable.Checked) { drawTrackLine(c, trackLinePos[0], trackLineLog[0] = new Dictionary <string, double>()); } if (trackLine2Enable.Checked) { drawTrackLine(c, trackLinePos[1], trackLineLog[1] = new Dictionary <string, double>()); } // Draw the differences beteween the first two track lines if (trackLineCount >= 2) { drawTrackDiff(c, trackLineLog[0], trackLineLog[1]); } }
void RenderPlotArea(PlotArea area, Rectangle rect) { PdfSharp.Charting.ChartFrame chartFrame = ((ChartFormatInfo)_renderInfo.FormatInfo).ChartFrame; XUnit top = rect.Y; top += area.TopPadding; XUnit bottom = rect.Y + rect.Height; bottom -= area.BottomPadding; XUnit left = rect.X; left += area.LeftPadding; XUnit right = rect.X + rect.Width; right -= area.RightPadding; chartFrame.Location = new XPoint(left, top); chartFrame.Size = new XSize(right - left, bottom - top); chartFrame.DrawChart(_gfx); }
private void PositionLegends() { //reposition the legend and labels C1.Win.C1Chart.ChartLabels labels = c1Chart1.ChartLabels; if (labels == null || labels.LabelsCollection.Count < 5) { return; } c1Chart1.Update(); PlotArea plota = c1Chart1.ChartArea.PlotArea; Legend leg = c1Chart1.Legend; //get left alignment with the legend, and //center about the plot area centerline Point labP = leg.Location; labP.Y = plota.Location.Y + plota.Size.Height / 2; //get the height of the labels and legend int labHeight = labels[0].Size.Height; int h = labHeight * 5 + leg.Size.Height; labP.Y -= h / 2; for (int i = 0; i < 5; i++) { C1.Win.C1Chart.Label lab = labels[i]; lab.AttachMethodData.X = labP.X; lab.AttachMethodData.Y = labP.Y; labP.Y += labHeight; } leg.LocationDefault = new Point(-1, labP.Y); }
/// <summary> /// Returns an initialized and renderer specific rendererInfo. /// </summary> internal override RendererInfo Init() { ChartRendererInfo cri = new ChartRendererInfo(); cri._chart = (Chart)_rendererParms.DrawingItem; _rendererParms.RendererInfo = cri; InitSeries(cri); LegendRenderer lr = new PieLegendRenderer(_rendererParms); cri.legendRendererInfo = (LegendRendererInfo)lr.Init(); PlotArea plotArea = cri._chart.PlotArea; PlotAreaRenderer renderer = GetPlotAreaRenderer(); cri.plotAreaRendererInfo = (PlotAreaRendererInfo)renderer.Init(); DataLabelRenderer dlr = new PieDataLabelRenderer(_rendererParms); dlr.Init(); return(cri); }
protected void FlattenPlotArea(PlotArea plotArea) { }
public PlotAreaSerializerTests() { plotArea = new PlotArea(); }
void drawTrackLine(XYChart c, int lineX, Dictionary <string, double> log) { // The drawarea and plotarea objects DrawArea d = c.getDrawArea(); PlotArea plotArea = c.getPlotArea(); // Get the data x-value that is nearest to the mouse, and find its pixel coordinate. double xValue = c.getNearestXValue(lineX); int xCoor = c.getXCoor(xValue); // Draw empty track line if it is ahead of the data if ((currentIndex <= 0) || ((xCoor < lineX) && (xValue >= chartTimeLimit))) { d.vline(plotArea.getTopY(), plotArea.getBottomY(), lineX, 0x888888); return; } // Draw a vertical track line at the x-position d.vline(plotArea.getTopY(), plotArea.getBottomY(), xCoor, 0x888888); // Draw a label on the x-axis to show the track line position. string xlabel = "<*font,bgColor=000000*> " + c.xAxis().getFormattedLabel(xValue, "nn:ss.ff") + " <*/font*>"; TTFText t = d.text(xlabel, "Arial Bold", 10); log["x"] = xValue; // Restrict the x-pixel position of the label to make sure it stays inside the chart image. int xLabelPos = Math.Max(0, Math.Min(xCoor - t.getWidth() / 2, c.getWidth() - t.getWidth())); t.draw(xLabelPos, plotArea.getBottomY() + 6, 0xffffff); // Iterate through all layers to draw the data labels for (int i = 0; i < c.getLayerCount(); ++i) { Layer layer = c.getLayerByZ(i); // The data array index of the x-value int xIndex = layer.getXIndexOf(xValue); // Iterate through all the data sets in the layer for (int j = 0; j < layer.getDataSetCount(); ++j) { ChartDirector.DataSet dataSet = layer.getDataSetByZ(j); // Get the color and position of the data label int color = dataSet.getDataColor(); int yCoor = c.getYCoor(dataSet.getPosition(xIndex), dataSet.getUseYAxis()); // Draw a track dot with a label next to it for visible data points in the plot area if ((yCoor >= plotArea.getTopY()) && (yCoor <= plotArea.getBottomY()) && (color != Chart.Transparent) && (!string.IsNullOrEmpty(dataSet.getDataName()))) { d.circle(xCoor, yCoor, 4, 4, color, color); string label = "<*font,bgColor=" + color.ToString("x") + "*> " + c.formatValue( dataSet.getValue(xIndex), "{value|P4}") + " <*/font*>"; t = d.text(label, "Arial Bold", 10); log[dataSet.getDataName()] = dataSet.getValue(xIndex); // Draw the label on the right side of the dot if the mouse is on the left side the // chart, and vice versa. This ensures the label will not go outside the chart image. if (xCoor <= (plotArea.getLeftX() + plotArea.getRightX()) / 2) { t.draw(xCoor + 5, yCoor, 0xffffff, Chart.Left); } else { t.draw(xCoor - 5, yCoor, 0xffffff, Chart.Right); } } } } }
/// <summary> /// Initializes a new instance of the <see cref="PlotAreaBuilder" /> class. /// </summary> /// <param name="plotArea">The plot area.</param> public PlotAreaBuilder(PlotArea plotArea) { this.plotArea = plotArea; }
/// <summary> /// Design settings for Y axis. /// </summary> public ValueAxis SetGanttValueAxis(PlotArea plotArea, TimeSpan minSpan, TimeSpan maxSpan) { MajorGridlines majorGridlines1 = new MajorGridlines(); ChartShapeProperties chartShapeProperties2 = new ChartShapeProperties(); Outline outline2 = new Outline(); SolidFill solidFill2 = new SolidFill(); SchemeColor schemeColor2 = new SchemeColor() { Val = SchemeColorValues.Accent1 }; Alpha alpha1 = new Alpha() { Val = 10000 }; schemeColor2.Append(alpha1); solidFill2.Append(schemeColor2); outline2.Append(solidFill2); chartShapeProperties2.Append(outline2); majorGridlines1.Append(chartShapeProperties2); return(plotArea.AppendChild <ValueAxis>(new ValueAxis(new AxisId() { Val = new UInt32Value(48672768u) }, new Scaling(new Orientation() { Val = new EnumValue <DocumentFormat.OpenXml.Drawing.Charts.OrientationValues>( DocumentFormat.OpenXml.Drawing.Charts.OrientationValues.MinMax) }, new MinAxisValue() { Val = 0 }, new MaxAxisValue() { Val = 0.99 }), new Delete() { Val = false }, new AxisPosition() { Val = new EnumValue <AxisPositionValues>(AxisPositionValues.Left) }, majorGridlines1, new MajorTickMark() { Val = TickMarkValues.None }, new MinorTickMark() { Val = TickMarkValues.None }, new MajorUnit() { Val = 4.1666666666666713E-2D }, new DocumentFormat.OpenXml.Drawing.Charts.NumberingFormat() { FormatCode = "h:mm;@", SourceLinked = false }, new TickLabelPosition() { Val = new EnumValue <TickLabelPositionValues> (TickLabelPositionValues.NextTo) }, new CrossingAxis() { Val = new UInt32Value(48650112U) }, new Crosses() { Val = new EnumValue <CrossesValues>(CrossesValues.AutoZero) }, new CrossBetween() { Val = new EnumValue <CrossBetweenValues>(CrossBetweenValues.Between) }))); }
protected void BuildLegend(ParametersBase parameters) { LegendTitle = parameters.LegendTitle; IColorSelector color = parameters.Color; if (String.IsNullOrEmpty(LegendTitle)) { LegendTitle = "Color"; } if (LegendTitle.Length > 15) { LegendTitle = LegendTitle.Substring(0, 13) + "..."; } float maxWidth = 0f; List <string> legendTexts = new List <string>(); if (color is ColorGradient) { ColorGradient gradient = color as ColorGradient; legendTexts = gradient.Stops.Select(s => parameters.LegendTextFormater.Format(s.Value)).ToList(); } else if (color is ColorPalette) { ColorPalette palette = color as ColorPalette; legendTexts = palette.Colors.Keys.Select(s => parameters.LegendTextFormater.Format(s)).ToList(); } var sizes = legendTexts.Select(t => DefaultFont.RenderText(t)); maxWidth = sizes.Max(s => s.Width); LegendTextHeight = sizes.Max(s => s.Height); //Legend title var titleSize = DefaultFontBold.RenderText(LegendTitle); LegendTitleWidth = titleSize.Width; LegendTitleHeight = titleSize.Height; if (parameters.LegendPosition == Position.Right || parameters.LegendPosition == Position.Left) { maxWidth = Math.Max(maxWidth, (float)(LegendTitleWidth - LegendThickness - SmallMargin)); } switch (parameters.LegendPosition) { case Position.Left: case Position.Right: PlotArea = PlotArea.WithWidth(PlotArea.Width - Margin - LegendThickness - SmallMargin - maxWidth); LegendTitleArea = new Rect( PlotArea.Left + PlotArea.Width + Margin, PlotArea.Top, LegendTitleWidth, LegendTitleHeight); LegendArea = new Rect( PlotArea.Left + PlotArea.Width + Margin, PlotArea.Top + LegendTitleHeight + SmallMargin, LegendThickness, Math.Max(PlotArea.Height - LegendTitleHeight - SmallMargin, 0)); break; case Position.Top: case Position.Bottom: PlotArea = PlotArea.WithHeight(PlotArea.Height - Margin - LegendTitleHeight - SmallMargin - LegendThickness); if (color is ColorGradient) { PlotArea = PlotArea.WithHeight(PlotArea.Height - SmallMargin - LegendTextHeight); } LegendTitleArea = new Rect( Math.Max(PlotArea.Left + (PlotArea.Width - LegendTitleWidth) / 2, 0), PlotArea.Top + PlotArea.Height + Margin, LegendTitleWidth, LegendTitleHeight); LegendArea = new Rect( PlotArea.Left, PlotArea.Top + PlotArea.Height + Margin + LegendTitleHeight + SmallMargin, PlotArea.Width, LegendThickness); break; default: break; } }
public bool IsChartDegenerated() { return(ChartArea.IsDegenerated() || PlotArea.IsDegenerated()); }
// // Draw track line with data labels // private void trackLineLabel(XYChart c, int mouseX) { // Clear the current dynamic layer and get the DrawArea object to draw on it. DrawArea d = c.initDynamicLayer(); // The plot area object PlotArea plotArea = c.getPlotArea(); // Get the data x-value that is nearest to the mouse, and find its pixel coordinate. double xValue = c.getNearestXValue(mouseX); int xCoor = c.getXCoor(xValue); // Draw a vertical track line at the x-position d.vline(plotArea.getTopY(), plotArea.getBottomY(), xCoor, d.dashLineColor(0x000000, 0x0101)); // Draw a label on the x-axis to show the track line position. string xlabel = "<*font,bgColor=000000*> " + c.xAxis().getFormattedLabel(xValue, "mmm dd, yyyy") + " <*/font*>"; TTFText t = d.text(xlabel, "Arial Bold", 8); // Restrict the x-pixel position of the label to make sure it stays inside the chart image. int xLabelPos = Math.Max(0, Math.Min(xCoor - t.getWidth() / 2, c.getWidth() - t.getWidth())); t.draw(xLabelPos, plotArea.getBottomY() + 6, 0xffffff); // Iterate through all layers to draw the data labels for (int i = 0; i < c.getLayerCount(); ++i) { Layer layer = c.getLayerByZ(i); // The data array index of the x-value int xIndex = layer.getXIndexOf(xValue); // Iterate through all the data sets in the layer for (int j = 0; j < layer.getDataSetCount(); ++j) { ChartDirector.DataSet dataSet = layer.getDataSetByZ(j); // Get the color and position of the data label int color = dataSet.getDataColor(); int yCoor = c.getYCoor(dataSet.getPosition(xIndex), dataSet.getUseYAxis()); // Draw a track dot with a label next to it for visible data points in the plot area if ((yCoor >= plotArea.getTopY()) && (yCoor <= plotArea.getBottomY()) && (color != Chart.Transparent)) { d.circle(xCoor, yCoor, 4, 4, color, color); string label = "<*font,bgColor=" + color.ToString("x") + "*> " + c.formatValue( dataSet.getValue(xIndex), "{value|P4}") + " <*/font*>"; t = d.text(label, "Arial Bold", 8); // Draw the label on the right side of the dot if the mouse is on the left side the // chart, and vice versa. This ensures the label will not go outside the chart image. if (xCoor <= (plotArea.getLeftX() + plotArea.getRightX()) / 2) { t.draw(xCoor + 5, yCoor, 0xffffff, Chart.Left); } else { t.draw(xCoor - 5, yCoor, 0xffffff, Chart.Right); } } } } }
// // Create chart // private void createChart(RazorChartViewer viewer) { // Data points which more unevenly spaced in time double[] data0Y = { 62, 69, 53, 58, 84, 76, 49, 61, 64, 77, 79 }; DateTime[] data0X = { new DateTime(2007, 1, 1), new DateTime(2007, 1, 2), new DateTime(2007, 1, 5), new DateTime(2007, 1, 7), new DateTime(2007, 1,10), new DateTime(2007, 1, 14), new DateTime(2007, 1, 17), new DateTime(2007, 1, 18), new DateTime(2007, 1, 19), new DateTime(2007, 1, 20), new DateTime(2007, 1, 21) }; // Data points which are evenly spaced in a certain time range double[] data1Y = { 36, 25, 28, 38, 20, 30, 27, 35, 65, 60, 40, 73, 62, 90, 75, 72 }; DateTime data1Start = new DateTime(2007, 1, 1); DateTime data1End = new DateTime(2007, 1, 16); // Data points which are evenly spaced in another time range, in which the spacing is // different from the above series double[] data2Y = { 25, 15, 30, 23, 32, 55, 45 }; DateTime data2Start = new DateTime(2007, 1, 9); DateTime data2End = new DateTime(2007, 1, 21); // Create a XYChart object of size 600 x 400 pixels. Use a vertical gradient color from light // blue (99ccff) to white (ffffff) spanning the top 100 pixels as background. Set border to // grey (888888). Use rounded corners. Enable soft drop shadow. XYChart c = new XYChart(600, 400); c.setBackground(c.linearGradientColor(0, 0, 0, 100, 0x99ccff, 0xffffff), 0x888888); c.setRoundedFrame(); c.setDropShadow(); // Add a title using 18pt Times New Roman Bold Italic font. Set top margin to 16 pixels. c.addTitle("Product Line Order Backlog", "Times New Roman Bold Italic", 18).setMargin2(0, 0, 16, 0); // Set the plotarea at (60, 80) and of 510 x 275 pixels in size. Use transparent border and // dark grey (444444) dotted grid lines PlotArea plotArea = c.setPlotArea(60, 80, 510, 275, -1, -1, Chart.Transparent, c.dashLineColor(0x444444, 0x0101), -1); // Add a legend box where the top-center is anchored to the horizontal center of the plot // area at y = 45. Use horizontal layout and 10 points Arial Bold font, and transparent // background and border. LegendBox legendBox = c.addLegend(plotArea.getLeftX() + plotArea.getWidth() / 2, 45, false, "Arial Bold", 10); legendBox.setAlignment(Chart.TopCenter); legendBox.setBackground(Chart.Transparent, Chart.Transparent); // Set x-axis tick density to 75 pixels and y-axis tick density to 30 pixels. ChartDirector // auto-scaling will use this as the guidelines when putting ticks on the x-axis and y-axis. c.yAxis().setTickDensity(30); c.xAxis().setTickDensity(75); // Set all axes to transparent c.xAxis().setColors(Chart.Transparent); c.yAxis().setColors(Chart.Transparent); // Set the x-axis margins to 15 pixels, so that the horizontal grid lines can extend beyond // the leftmost and rightmost vertical grid lines c.xAxis().setMargin(15, 15); // Set axis label style to 8pt Arial Bold c.xAxis().setLabelStyle("Arial Bold", 8); c.yAxis().setLabelStyle("Arial Bold", 8); c.yAxis2().setLabelStyle("Arial Bold", 8); // Add axis title using 10pt Arial Bold Italic font c.yAxis().setTitle("Backlog in USD millions", "Arial Bold Italic", 10); // Add the first data series LineLayer layer0 = c.addLineLayer2(); layer0.addDataSet(data0Y, 0xff0000, "Quantum Computer").setDataSymbol( Chart.GlassSphere2Shape, 11); layer0.setXData(data0X); layer0.setLineWidth(3); // Add the second data series LineLayer layer1 = c.addLineLayer2(); layer1.addDataSet(data1Y, 0x00ff00, "Atom Synthesizer").setDataSymbol( Chart.GlassSphere2Shape, 11); layer1.setXData2(data1Start, data1End); layer1.setLineWidth(3); // Add the third data series LineLayer layer2 = c.addLineLayer2(); layer2.addDataSet(data2Y, 0xff6600, "Proton Cannon").setDataSymbol(Chart.GlassSphere2Shape, 11); layer2.setXData2(data2Start, data2End); layer2.setLineWidth(3); // Output the chart viewer.Image = c.makeWebImage(Chart.PNG); // Include tool tip for the chart viewer.ImageMap = c.getHTMLImageMap("", "", "title='Backlog of {dataSetName} at {x|mm/dd/yyyy}: US$ {value}M'"); }
internal static void Map(PlotArea plotArea, MigraDoc.DocumentObjectModel.Shapes.Charts.PlotArea domPlotArea) { PlotAreaMapper mapper = new PlotAreaMapper(); mapper.MapObject(plotArea, domPlotArea); }
private static DeclarationList CreateCurrentDeclarations() { DeclarationList declarationList = new DeclarationList(); int num = 1; declarationList[num++] = IDOwner.GetDeclaration(); declarationList[num++] = ReportItem.GetDeclaration(); num++; declarationList[num++] = Report.GetDeclaration(); declarationList[num++] = PageSection.GetDeclaration(); declarationList[num++] = Line.GetDeclaration(); declarationList[num++] = Rectangle.GetDeclaration(); declarationList[num++] = Image.GetDeclaration(); num++; declarationList[num++] = CheckBox.GetDeclaration(); declarationList[num++] = TextBox.GetDeclaration(); declarationList[num++] = SubReport.GetDeclaration(); declarationList[num++] = ActiveXControl.GetDeclaration(); declarationList[num++] = DataRegion.GetDeclaration(); num++; declarationList[num++] = ReportHierarchyNode.GetDeclaration(); declarationList[num++] = Grouping.GetDeclaration(); declarationList[num++] = Sorting.GetDeclaration(); declarationList[num++] = List.GetDeclaration(); declarationList[num++] = Pivot.GetDeclaration(); declarationList[num++] = Matrix.GetDeclaration(); declarationList[num++] = PivotHeading.GetDeclaration(); declarationList[num++] = MatrixHeading.GetDeclaration(); declarationList[num++] = MatrixColumn.GetDeclaration(); num++; declarationList[num++] = MatrixRow.GetDeclaration(); num++; declarationList[num++] = Subtotal.GetDeclaration(); declarationList[num++] = Table.GetDeclaration(); declarationList[num++] = TableColumn.GetDeclaration(); num++; declarationList[num++] = TableGroup.GetDeclaration(); declarationList[num++] = TableRow.GetDeclaration(); num++; declarationList[num++] = OWCChart.GetDeclaration(); declarationList[num++] = ChartColumn.GetDeclaration(); num++; declarationList[num++] = ReportItemCollection.GetDeclaration(); declarationList[num++] = ReportItemIndexer.GetDeclaration(); num++; declarationList[num++] = Style.GetDeclaration(); num++; declarationList[num++] = AttributeInfo.GetDeclaration(); declarationList[num++] = Visibility.GetDeclaration(); declarationList[num++] = ExpressionInfo.GetDeclaration(); num++; declarationList[num++] = DataAggregateInfo.GetDeclaration(); num++; declarationList[num++] = RunningValueInfo.GetDeclaration(); num++; num++; declarationList[num++] = Filter.GetDeclaration(); num++; declarationList[num++] = DataSource.GetDeclaration(); num++; declarationList[num++] = DataSet.GetDeclaration(); num++; declarationList[num++] = ReportQuery.GetDeclaration(); declarationList[num++] = Field.GetDeclaration(); num++; declarationList[num++] = ParameterValue.GetDeclaration(); num++; num++; num++; num++; declarationList[num++] = ReportSnapshot.GetDeclaration(); declarationList[num++] = SenderInformation.GetDeclaration(); declarationList[num++] = InstanceInfo.GetDeclaration(); declarationList[num++] = ReceiverInformation.GetDeclaration(); declarationList[num++] = InstanceInfo.GetDeclaration(); declarationList[num++] = DocumentMapNode.GetDeclaration(); declarationList[num++] = InfoBase.GetDeclaration(); declarationList[num++] = OffsetInfo.GetDeclaration(); declarationList[num++] = InstanceInfo.GetDeclaration(); declarationList[num++] = ReportItemInstanceInfo.GetDeclaration(); declarationList[num++] = ReportInstanceInfo.GetDeclaration(); declarationList[num++] = ReportItemColInstanceInfo.GetDeclaration(); declarationList[num++] = LineInstanceInfo.GetDeclaration(); declarationList[num++] = TextBoxInstanceInfo.GetDeclaration(); declarationList[num++] = RectangleInstanceInfo.GetDeclaration(); declarationList[num++] = CheckBoxInstanceInfo.GetDeclaration(); declarationList[num++] = ImageInstanceInfo.GetDeclaration(); declarationList[num++] = SubReportInstanceInfo.GetDeclaration(); declarationList[num++] = ActiveXControlInstanceInfo.GetDeclaration(); declarationList[num++] = ListInstanceInfo.GetDeclaration(); declarationList[num++] = ListContentInstanceInfo.GetDeclaration(); declarationList[num++] = MatrixInstanceInfo.GetDeclaration(); declarationList[num++] = MatrixHeadingInstanceInfo.GetDeclaration(); declarationList[num++] = MatrixCellInstanceInfo.GetDeclaration(); declarationList[num++] = TableInstanceInfo.GetDeclaration(); declarationList[num++] = TableGroupInstanceInfo.GetDeclaration(); declarationList[num++] = TableRowInstanceInfo.GetDeclaration(); declarationList[num++] = OWCChartInstanceInfo.GetDeclaration(); declarationList[num++] = ChartInstanceInfo.GetDeclaration(); declarationList[num++] = NonComputedUniqueNames.GetDeclaration(); declarationList[num++] = InstanceInfoOwner.GetDeclaration(); declarationList[num++] = ReportItemInstance.GetDeclaration(); num++; declarationList[num++] = ReportInstance.GetDeclaration(); declarationList[num++] = ReportItemColInstance.GetDeclaration(); declarationList[num++] = LineInstance.GetDeclaration(); declarationList[num++] = TextBoxInstance.GetDeclaration(); declarationList[num++] = RectangleInstance.GetDeclaration(); declarationList[num++] = CheckBoxInstance.GetDeclaration(); declarationList[num++] = ImageInstance.GetDeclaration(); declarationList[num++] = SubReportInstance.GetDeclaration(); declarationList[num++] = ActiveXControlInstance.GetDeclaration(); declarationList[num++] = ListInstance.GetDeclaration(); declarationList[num++] = ListContentInstance.GetDeclaration(); num++; declarationList[num++] = MatrixInstance.GetDeclaration(); declarationList[num++] = MatrixHeadingInstance.GetDeclaration(); num++; declarationList[num++] = MatrixCellInstance.GetDeclaration(); num++; num++; declarationList[num++] = TableInstance.GetDeclaration(); declarationList[num++] = TableRowInstance.GetDeclaration(); declarationList[num++] = TableColumnInstance.GetDeclaration(); declarationList[num++] = TableGroupInstance.GetDeclaration(); num++; declarationList[num++] = OWCChartInstance.GetDeclaration(); declarationList[num++] = ParameterInfo.GetDeclaration(); num++; num++; num++; declarationList[num++] = InstanceInfo.GetDeclaration(); num++; declarationList[num++] = RecordSetInfo.GetDeclaration(); declarationList[num++] = RecordRow.GetDeclaration(); declarationList[num++] = RecordField.GetDeclaration(); declarationList[num++] = ValidValue.GetDeclaration(); num++; declarationList[num++] = ParameterDataSource.GetDeclaration(); declarationList[num++] = ParameterDef.GetDeclaration(); num++; declarationList[num++] = ParameterBase.GetDeclaration(); num++; declarationList[num++] = ProcessingMessage.GetDeclaration(); declarationList[num++] = MatrixSubtotalHeadingInstanceInfo.GetDeclaration(); declarationList[num++] = MatrixSubtotalCellInstance.GetDeclaration(); declarationList[num++] = CodeClass.GetDeclaration(); num++; declarationList[num++] = TableDetail.GetDeclaration(); declarationList[num++] = TableDetailInstance.GetDeclaration(); num++; declarationList[num++] = TableDetailInstanceInfo.GetDeclaration(); num++; declarationList[num++] = Action.GetDeclaration(); declarationList[num++] = ActionInstance.GetDeclaration(); declarationList[num++] = Chart.GetDeclaration(); declarationList[num++] = ChartHeading.GetDeclaration(); declarationList[num++] = ChartDataPoint.GetDeclaration(); num++; declarationList[num++] = MultiChart.GetDeclaration(); declarationList[num++] = MultiChartInstance.GetDeclaration(); num++; declarationList[num++] = Axis.GetDeclaration(); declarationList[num++] = AxisInstance.GetDeclaration(); declarationList[num++] = ChartTitle.GetDeclaration(); declarationList[num++] = ChartTitleInstance.GetDeclaration(); declarationList[num++] = ThreeDProperties.GetDeclaration(); declarationList[num++] = PlotArea.GetDeclaration(); declarationList[num++] = Legend.GetDeclaration(); declarationList[num++] = GridLines.GetDeclaration(); declarationList[num++] = ChartDataLabel.GetDeclaration(); declarationList[num++] = ChartInstance.GetDeclaration(); declarationList[num++] = ChartHeadingInstance.GetDeclaration(); declarationList[num++] = ChartHeadingInstanceInfo.GetDeclaration(); num++; declarationList[num++] = ChartDataPointInstance.GetDeclaration(); declarationList[num++] = ChartDataPointInstanceInfo.GetDeclaration(); num++; num++; declarationList[num++] = RenderingPagesRanges.GetDeclaration(); num++; declarationList[num++] = IntermediateFormatVersion.GetDeclaration(); declarationList[num++] = ImageInfo.GetDeclaration(); declarationList[num++] = ActionItem.GetDeclaration(); declarationList[num++] = ActionItemInstance.GetDeclaration(); num++; num++; declarationList[num++] = DataValue.GetDeclaration(); declarationList[num++] = DataValueInstance.GetDeclaration(); num++; num++; declarationList[num++] = Tablix.GetDeclaration(); declarationList[num++] = TablixHeading.GetDeclaration(); declarationList[num++] = CustomReportItem.GetDeclaration(); declarationList[num++] = CustomReportItemInstance.GetDeclaration(); declarationList[num++] = CustomReportItemHeading.GetDeclaration(); declarationList[num++] = CustomReportItemHeadingInstance.GetDeclaration(); num++; num++; num++; num++; declarationList[num++] = CustomReportItemCellInstance.GetDeclaration(); num++; num++; declarationList[num++] = DataValueCRIList.GetDeclaration(); declarationList[num++] = BookmarkInformation.GetDeclaration(); declarationList[num++] = InstanceInfo.GetDeclaration(); declarationList[num++] = DrillthroughInformation.GetDeclaration(); declarationList[num++] = InstanceInfo.GetDeclaration(); num++; declarationList[num++] = CustomReportItemInstanceInfo.GetDeclaration(); declarationList[num++] = ImageMapAreaInstanceList.GetDeclaration(); declarationList[num++] = ImageMapAreaInstance.GetDeclaration(); num++; declarationList[num++] = InstanceInfo.GetDeclaration(); declarationList[num++] = SortFilterEventInfo.GetDeclaration(); declarationList[num++] = EndUserSort.GetDeclaration(); num++; num++; declarationList[num++] = RecordSetPropertyNames.GetDeclaration(); num++; num++; num++; declarationList[num++] = PageSectionInstance.GetDeclaration(); num++; declarationList[num++] = PageSectionInstanceInfo.GetDeclaration(); declarationList[num++] = SimpleTextBoxInstanceInfo.GetDeclaration(); declarationList[num++] = ScopeLookupTable.GetDeclaration(); num++; declarationList[num++] = ReportDrillthroughInfo.GetDeclaration(); declarationList[num++] = InstanceInfo.GetDeclaration(); Global.Tracer.Assert(declarationList.Count == num, "(current.Count == index)"); return(declarationList); }
private static void InsertChartInSpreadsheet(string docName, string worksheetName, string title, Dictionary <string, int> data) { // Open the document for editing. using (SpreadsheetDocument document = SpreadsheetDocument.Open(docName, true)) { IEnumerable <Sheet> sheets = document.WorkbookPart.Workbook.Descendants <Sheet>(). Where(s => s.Name == worksheetName); if (sheets.Count() == 0) { // The specified worksheet does not exist. return; } WorksheetPart worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(sheets.First().Id); // Add a new drawing to the worksheet. DrawingsPart drawingsPart = worksheetPart.AddNewPart <DrawingsPart>(); worksheetPart.Worksheet.Append(new DocumentFormat.OpenXml.Spreadsheet.Drawing() { Id = worksheetPart.GetIdOfPart(drawingsPart) }); worksheetPart.Worksheet.Save(); // Add a new chart and set the chart language to English-US. ChartPart chartPart = drawingsPart.AddNewPart <ChartPart>(); chartPart.ChartSpace = new ChartSpace(); chartPart.ChartSpace.Append(new EditingLanguage() { Val = new StringValue("en-US") }); DocumentFormat.OpenXml.Drawing.Charts.Chart chart = chartPart.ChartSpace.AppendChild <DocumentFormat.OpenXml.Drawing.Charts.Chart>( new DocumentFormat.OpenXml.Drawing.Charts.Chart()); // Create a new clustered column chart. PlotArea plotArea = chart.AppendChild <PlotArea>(new PlotArea()); Layout layout = plotArea.AppendChild <Layout>(new Layout()); BarChart barChart = plotArea.AppendChild <BarChart>(new BarChart(new BarDirection() { Val = new EnumValue <BarDirectionValues>(BarDirectionValues.Column) }, new BarGrouping() { Val = new EnumValue <BarGroupingValues>(BarGroupingValues.Clustered) })); uint i = 0; // Iterate through each key in the Dictionary collection and add the key to the chart Series // and add the corresponding value to the chart Values. foreach (string key in data.Keys) { BarChartSeries barChartSeries = barChart.AppendChild <BarChartSeries>(new BarChartSeries(new Index() { Val = new UInt32Value(i) }, new Order() { Val = new UInt32Value(i) }, new SeriesText(new NumericValue() { Text = key }))); StringLiteral strLit = barChartSeries.AppendChild <CategoryAxisData>(new CategoryAxisData()).AppendChild <StringLiteral>(new StringLiteral()); strLit.Append(new PointCount() { Val = new UInt32Value(1U) }); strLit.AppendChild <StringPoint>(new StringPoint() { Index = new UInt32Value(0U) }).Append(new NumericValue(key)); NumberLiteral numLit = barChartSeries.AppendChild <DocumentFormat.OpenXml.Drawing.Charts.Values>( new DocumentFormat.OpenXml.Drawing.Charts.Values()).AppendChild <NumberLiteral>(new NumberLiteral()); numLit.Append(new FormatCode("General")); numLit.Append(new PointCount() { Val = new UInt32Value(1U) }); numLit.AppendChild <NumericPoint>(new NumericPoint() { Index = new UInt32Value(0u) }) .Append(new NumericValue(data[key].ToString())); i++; } barChart.Append(new AxisId() { Val = new UInt32Value(48650112u) }); barChart.Append(new AxisId() { Val = new UInt32Value(48672768u) }); //// Add the Category Axis. CategoryAxis catAx = plotArea.AppendChild <CategoryAxis>(new CategoryAxis(new AxisId() { Val = new UInt32Value(48650112u) }, new Scaling(new Orientation() { Val = new EnumValue <DocumentFormat. OpenXml.Drawing.Charts.OrientationValues>(DocumentFormat.OpenXml.Drawing.Charts.OrientationValues.MinMax) }), new AxisPosition() { Val = new EnumValue <AxisPositionValues>(AxisPositionValues.Bottom) }, new TickLabelPosition() { Val = new EnumValue <TickLabelPositionValues>(TickLabelPositionValues.NextTo) }, new CrossingAxis() { Val = new UInt32Value(48672768U) }, new Crosses() { Val = new EnumValue <CrossesValues>(CrossesValues.AutoZero) }, new AutoLabeled() { Val = new BooleanValue(true) }, new LabelAlignment() { Val = new EnumValue <LabelAlignmentValues>(LabelAlignmentValues.Center) }, new LabelOffset() { Val = new UInt16Value((ushort)100) })); // Add the Value Axis. ValueAxis valAx = plotArea.AppendChild <ValueAxis>(new ValueAxis(new AxisId() { Val = new UInt32Value(48672768u) }, new Scaling(new Orientation() { Val = new EnumValue <DocumentFormat.OpenXml.Drawing.Charts.OrientationValues>( DocumentFormat.OpenXml.Drawing.Charts.OrientationValues.MinMax) }), new AxisPosition() { Val = new EnumValue <AxisPositionValues>(AxisPositionValues.Left) }, new MajorGridlines(), new DocumentFormat.OpenXml.Drawing.Charts.NumberingFormat() { FormatCode = new StringValue("General"), SourceLinked = new BooleanValue(true) }, new TickLabelPosition() { Val = new EnumValue <TickLabelPositionValues> (TickLabelPositionValues.NextTo) }, new CrossingAxis() { Val = new UInt32Value(48650112U) }, new Crosses() { Val = new EnumValue <CrossesValues>(CrossesValues.AutoZero) }, new CrossBetween() { Val = new EnumValue <CrossBetweenValues>(CrossBetweenValues.Between) })); // Add the chart Legend. Legend legend = chart.AppendChild <Legend>(new Legend(new LegendPosition() { Val = new EnumValue <LegendPositionValues>(LegendPositionValues.Right) }, new Layout())); chart.Append(new PlotVisibleOnly() { Val = new BooleanValue(true) }); // Save the chart part. chartPart.ChartSpace.Save(); // Position the chart on the worksheet using a TwoCellAnchor object. drawingsPart.WorksheetDrawing = new WorksheetDrawing(); TwoCellAnchor twoCellAnchor = drawingsPart.WorksheetDrawing.AppendChild <TwoCellAnchor>(new TwoCellAnchor()); twoCellAnchor.Append(new DocumentFormat.OpenXml.Drawing.Spreadsheet.FromMarker(new ColumnId("1"), new ColumnOffset("581025"), new RowId("1"), new RowOffset("114300"))); twoCellAnchor.Append(new DocumentFormat.OpenXml.Drawing.Spreadsheet.ToMarker(new ColumnId("10"), new ColumnOffset("276225"), new RowId("16"), new RowOffset("0"))); // Append a GraphicFrame to the TwoCellAnchor object. DocumentFormat.OpenXml.Drawing.Spreadsheet.GraphicFrame graphicFrame = twoCellAnchor.AppendChild <DocumentFormat.OpenXml. Drawing.Spreadsheet.GraphicFrame>(new DocumentFormat.OpenXml.Drawing. Spreadsheet.GraphicFrame()); graphicFrame.Macro = ""; graphicFrame.Append(new DocumentFormat.OpenXml.Drawing.Spreadsheet.NonVisualGraphicFrameProperties( new DocumentFormat.OpenXml.Drawing.Spreadsheet.NonVisualDrawingProperties() { Id = new UInt32Value(2u), Name = "Chart 1" }, new DocumentFormat.OpenXml.Drawing.Spreadsheet.NonVisualGraphicFrameDrawingProperties())); graphicFrame.Append(new Transform(new Offset() { X = 0L, Y = 0L }, new Extents() { Cx = 0L, Cy = 0L })); graphicFrame.Append(new Graphic(new GraphicData(new ChartReference() { Id = drawingsPart.GetIdOfPart(chartPart) }) { Uri = "http://schemas.openxmlformats.org/drawingml/2006/chart" })); twoCellAnchor.Append(new ClientData()); // Save the WorksheetDrawing object. drawingsPart.WorksheetDrawing.Save(); } }
// // Draw the track box with legend // private void trackBoxLegend(XYChart c, int mouseX, int mouseY) { // Clear the current dynamic layer and get the DrawArea object to draw on it. DrawArea d = c.initDynamicLayer(); // The plot area object PlotArea plotArea = c.getPlotArea(); // Get the data x-value that is nearest to the mouse double xValue = c.getNearestXValue(mouseX); // Compute the position of the box. This example assumes a label based x-axis, in which the // labeling spacing is one x-axis unit. So the left and right sides of the box is 0.5 unit from // the central x-value. int boxLeft = c.getXCoor(xValue - 0.5); int boxRight = c.getXCoor(xValue + 0.5); int boxTop = plotArea.getTopY(); int boxBottom = plotArea.getBottomY(); // Draw the track box d.rect(boxLeft, boxTop, boxRight, boxBottom, 0x000000, Chart.Transparent); // Container to hold the legend entries ArrayList legendEntries = new ArrayList(); // Iterate through all layers to build the legend array for (int i = 0; i < c.getLayerCount(); ++i) { Layer layer = c.getLayerByZ(i); // The data array index of the x-value int xIndex = layer.getXIndexOf(xValue); // Iterate through all the data sets in the layer for (int j = 0; j < layer.getDataSetCount(); ++j) { ChartDirector.DataSet dataSet = layer.getDataSetByZ(j); // Build the legend entry, consist of the legend icon, the name and the data value. double dataValue = dataSet.getValue(xIndex); if ((dataValue != Chart.NoValue) && (dataSet.getDataColor() != Chart.Transparent)) { legendEntries.Add(dataSet.getLegendIcon() + " " + dataSet.getDataName() + ": " + c.formatValue(dataValue, "{value|P4}")); } } } // Create the legend by joining the legend entries if (legendEntries.Count > 0) { legendEntries.Reverse(); string legend = "<*block,bgColor=FFFFCC,edgeColor=000000,margin=5*><*font,underline=1*>" + c.xAxis().getFormattedLabel(xValue) + "<*/font*><*br*>" + String.Join("<*br*>", (string[]) legendEntries.ToArray(typeof(string))) + "<*/*>"; // Display the legend at the bottom-right side of the mouse cursor, and make sure the legend // will not go outside the chart image. TTFText t = d.text(legend, "Arial Bold", 8); t.draw(Math.Min(mouseX + 12, c.getWidth() - t.getWidth()), Math.Min(mouseY + 18, c.getHeight() - t.getHeight()), 0x000000, Chart.TopLeft); } }
public AxesSequence(IStreamReader reader) : base(reader) { //AXES = [IVAXIS DVAXIS [SERIESAXIS] / DVAXIS DVAXIS] *3ATTACHEDLABEL [PlotArea FRAME] // [IVAXIS DVAXIS [SERIESAXIS] / DVAXIS DVAXIS] if (BiffRecord.GetNextRecordType(reader) == RecordType.Axis) { long position = reader.BaseStream.Position; Axis axis = (Axis)BiffRecord.ReadRecord(reader); Begin begin = (Begin)BiffRecord.ReadRecord(reader); if (BiffRecord.GetNextRecordType(reader) == RecordType.CatSerRange || BiffRecord.GetNextRecordType(reader) == RecordType.AxcExt) { reader.BaseStream.Position = position; ChartAxisIdGenerator.Instance.StartNewAxisGroup(); //IVAXIS this.IvAxisSequence = new IvAxisSequence(reader); //DVAXIS this.DvAxisSequence = new DvAxisSequence(reader); //[SERIESAXIS] if (BiffRecord.GetNextRecordType(reader) == RecordType.Axis) { this.SeriesAxisSequence = new IvAxisSequence(reader); } } else { reader.BaseStream.Position = position; ChartAxisIdGenerator.Instance.StartNewAxisGroup(); //DVAXIS this.DvAxisSequence = new DvAxisSequence(reader); //DVAXIS this.DvAxisSequence2 = new DvAxisSequence(reader); } } //*3ATTACHEDLABEL this.AttachedLabelSequences = new List <AttachedLabelSequence>(); while (BiffRecord.GetNextRecordType(reader) == RecordType.Text) { this.AttachedLabelSequences.Add(new AttachedLabelSequence(reader)); } //[PlotArea FRAME] if (BiffRecord.GetNextRecordType(reader) == RecordType.PlotArea) { this.PlotArea = (PlotArea)BiffRecord.ReadRecord(reader); this.Frame = new FrameSequence(reader); } }