I have a Ms Chart on a simple Form and the follow Testcode:
ChartArea myAreachart2 = new ChartArea();
myAreachart2.AxisX.IntervalType = DateTimeIntervalType.Months;
myAreachart2.AxisX.Minimum = new DateTime(2011, 1, 1).ToOADate();
myAreachart2.AxisX.Maximum = new DateTime(2011, 12, 31).ToOADate();
myAreachart2.AxisX.IsLabelAutoFit = false;
myAreachart2.AxisX.LabelStyle.IsEndLabelVisible = false;
myAreachart2.AxisX.LabelStyle.Format = "MMMM";
chart2.ChartAreas.Add(myAreachart2);
chart2.Series.Add("Default");
chart2.Series[0].XValueType = ChartValueType.DateTime
chart2.Series[0].BorderWidth = 4;
chart2.Series[0].Color = Color.Black;
chart2.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
chart2.Series[0].Points.AddXY(new DateTime(2011, 1, 1), 100);
chart2.Series[0].Points.AddXY(new DateTime(2011, 2, 1), 200);
chart2.Series[0].Points.AddXY(new DateTime(2011, 3, 1), 300);
chart2.Series[0].Points.AddXY(new DateTime(2011, 4, 1), 400);
chart2.Series[0].Points.AddXY(new DateTime(2011, 5, 1), 500);
The result is a Chart with the Values and on the x-Axis are the monthnames as Labels. But not on january. The monthname will not be displayed. (There ist nothing.)
Please help me ? :-) I seach a lot of websites an examples, but i can't find any solution.
Thank you very much.
Might be because you set:
myAreachart2.AxisX.LabelStyle.IsEndLabelVisible = false;
From MSDN:
LabelStyle.IsEndLabelVisible Property Gets or sets a flag that
determines whether the labels are shown at axis ends.
Related
My requirement is to read an existing IFC file with GeometryGym and add a new object to it. So I've written a C# code as follow,
public void CreateDocuemntRefIcon(string filePath)
{
DatabaseIfc db = new DatabaseIfc(filePath);
IfcProject project = db.Project;
List<IfcBuilding> buildings = project.Extract<IfcBuilding>();
IfcBuilding thisBuilding = buildings.FirstOrDefault();
//Creating cube object
List<Coord3d> points = new List<Coord3d>() {
new Coord3d(0, 0, 0), new Coord3d(10, 0, 0),
new Coord3d(10, 10, 0), new Coord3d(0, 10, 0),
new Coord3d(0, 0, 10), new Coord3d(10, 0, 10),
new Coord3d(10, 10, 10), new Coord3d(0, 10, 10) };
IfcCartesianPointList3D cartesianPointList3D = new IfcCartesianPointList3D(db, points);
List<CoordIndex> coordIndex = new List<CoordIndex>() {
new CoordIndex(1, 6, 5), new CoordIndex(1, 2, 6), new CoordIndex(6, 2, 7),
new CoordIndex(7, 2, 3), new CoordIndex(7, 8, 6), new CoordIndex(6, 8, 5),
new CoordIndex(5, 8, 1), new CoordIndex(1, 8, 4), new CoordIndex(4, 2, 1),
new CoordIndex(2, 4, 3), new CoordIndex(4, 8, 7), new CoordIndex(7, 3, 4)
};
IfcTriangulatedFaceSet triangulatedFaceSet = new IfcTriangulatedFaceSet(cartesianPointList3D, true, coordIndex);
IfcColourRgbList colourRgbList = new IfcColourRgbList(db, new List<Color>() { Color.Red, Color.Green, Color.Yellow });
IfcIndexedColourMap indexedColourMap = new IfcIndexedColourMap(triangulatedFaceSet, colourRgbList, new List<int>() { 1, 1, 2, 2, 3, 3, 1, 1, 1, 1, 1, 1 });
IfcBuildingElementProxy buildingElementProxy =
new IfcBuildingElementProxy(thisBuilding, null, new IfcProductDefinitionShape(new IfcShapeRepresentation(triangulatedFaceSet)));
//Writed the file
db.WriteFile(string.Format("{0}.ifc", "EditedIFC"));
}
This is working well with IFC4 release. But not working for IFC2x3 release. What could be the issue ?
IFC2X3 has no IfcTriangulatedFaceSet. This has been added with IFC4.
You can emulate triangulated surfaces with IfcShellBasedSurfaceModel under IFC2X3.
I was trying to overlap two chart areas. They would share the same x values, but Y would have different values and scales.
Here is outcome of my code:
As you can see red series is not in alignment with green series.I was searching this site for answers, but couldn't find one that worked. Could someone explain me why they don't align?
Code:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace TestGraph
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
#region Data
// Creating first series
Series s1 = new Series();
s1.Name = "Values";
s1.ChartType = SeriesChartType.Column;
s1.XValueType = ChartValueType.DateTime;
s1.Color = Color.Green;
s1.BorderWidth = 2;
// Hard Coding test values
DataPoint[] values =
{
new DataPoint(new DateTime(2017, 8, 1).ToOADate(), 10),
new DataPoint(new DateTime(2017, 8, 2).ToOADate(), 11),
new DataPoint(new DateTime(2017, 8, 3).ToOADate(), 12),
new DataPoint(new DateTime(2017, 8, 4).ToOADate(), 13),
};
// Adding vales to s1
foreach (DataPoint p in values)
{
s1.Points.Add(p);
}
// Creating second series
Series s2 = new Series();
s2.Name = "Values 2";
s2.ChartType = SeriesChartType.Column;
s2.XValueType = ChartValueType.DateTime;
s2.Color = Color.Red;
s2.BorderWidth = 2;
// Hard Coding test values
DataPoint[] values2 =
{
new DataPoint(new DateTime(2017, 8, 1).ToOADate(), 0.1),
new DataPoint(new DateTime(2017, 8, 2).ToOADate(), -0.2),
new DataPoint(new DateTime(2017, 8, 3).ToOADate(), -0.7),
new DataPoint(new DateTime(2017, 8, 4).ToOADate(), 13),
};
// Adding vales to s2
foreach (DataPoint p in values2)
{
s2.Points.Add(p);
}
#endregion
#region Charts
// Initializing chart
Chart mainChart = new Chart();
ChartArea area = new ChartArea();
ChartArea area2 = new ChartArea();
Controls.Add(mainChart);
mainChart.Dock = DockStyle.Fill;
// Adding areas to mainChart
mainChart.ChartAreas.Add(area);
mainChart.ChartAreas.Add(area2);
// Adding series to areas
s1.ChartArea = area.Name;
s2.ChartArea = area2.Name;
mainChart.Series.Add(s1);
mainChart.Series.Add(s2);
// Aligning areas
// Overlapping area2 with area
area2.AlignmentStyle = AreaAlignmentStyles.All;
area2.AlignmentOrientation = AreaAlignmentOrientations.All;
area2.AlignWithChartArea = area.Name;
// Scale actualization
area2.RecalculateAxesScale();
area.RecalculateAxesScale();
// Defining Y scale
area2.AxisY.Maximum = 2;
area2.AxisY.Minimum = -2;
area2.BackColor = Color.Transparent;
// Disabling unnecessary graphics
area2.BackGradientStyle = GradientStyle.None;
area2.AxisX.IsMarginVisible = false;
area2.AxisX.LabelStyle.Enabled = false;
area2.AxisY.LabelStyle.Enabled = false;
area2.AxisX.Enabled = AxisEnabled.False;
area2.AxisY.Enabled = AxisEnabled.False;
// Resizing chart back to 100%
area.Position = new ElementPosition(0, 0, 100, 100);
#endregion
}
}
}
One of your chart has AxisX.IsMarginVisible set to true, the other to false, hence the mismatch.
However, if you are trying to plot overlapping series, why are you not adding them to the same chart area instead of going through all this trouble?
I'm trying to put a Microsoft.Office.Interop.Word.Shape inside a table cell like in this short example:
Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Word.Document oDocument = oWord.Documents.Add();
Word.Table oTable = oDocument.Tables.Add(oDocument.Range(), 4, 1);
Word.Cell oCell1 = oTable.Cell(1,1);
Word.Shape oShape1 = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, oCell1.Range);
Word.Cell oCell2 = oTable.Cell(2, 1);
Word.Shape oShape2 = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, oCell2.Range);
Word.Cell oCell3 = oTable.Cell(3, 1);
Word.Shape oShape3 = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, oCell3.Range);
Word.Cell oCell4 = oTable.Cell(4, 1);
Word.Shape oShape4 = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, oCell4.Range);
oWord.Visible = true;
The rectangle only appears on the top left corner of the document.
I'm not sure what I'm doing wrong since I set the shape anchor to the cells range.
12/07/2016:
Okay, check this out,
I have now 5 columns and 100 rows and try to place the shape into the third column. I'm using the "in line with text" property.
Now, on the first two pages, all the shapes are placed in the first row/column. Starting at the third page it's looking right...
I'm using Office 2013.
Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Word.Document oDocument = oWord.Documents.Add();
int numRows = 100;
Word.Table oTable = oDocument.Tables.Add(oDocument.Range(), numRows, 5);
oTable.Borders.OutsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
oTable.Borders.InsideLineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
for (int r = 1; r <= numRows; ++r)
{
Word.Range anchorRange = oTable.Cell(r, 3).Range;
Word.Shape oShape = oDocument.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle.GetHashCode(), 7, 7, 11, 11, anchorRange);
oShape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapInline;
}
oWord.Visible = true;
If you click on the rectangle that's added, and enable paragraph/formatting symbols (it's the backwards P looking button in Home > Paragraph), you'll notice that the anchors are indeed on the table cells. Text-wrapped shapes also need other settings to have certain positions on the page. Mess with the Size and Position dialog to get a feel for it.
Making a chart using secondary axis,
makes my chart primary y-axis is shown with some values which I don't want to have.
Only x-axis and secondary y-axis.
and also the x-axis is drawn without the date values what I've passed.
Code:
chartType2 = GetChartType(worksheet, chartToDraw, endcolcnt, i, chartType2, chartType);
chartType2.UseSecondaryAxis = true;
Scale(headerString, endcolcnt, worksheet, chartType2, stcol, isFieldSame, endcol, stcolumn1, endrow, startRow);
and Scale Function only assigns the header names and all.
Details about the series taken
Output:
Input
Hard to say without more code. What are those functions doing exactly?
Are you trying to just get the axis on the right side? Based on the black chart you posted that would seem like what you are after. You could just do chartType.YAxis.Crosses = eCrosses.Max.
Or do you actually want TWO axes which would require two charts/series? If you want that then you would need to create a second chart based on the first (looks like your function might be doing that) and then add a unique series to each but with a common x-value dataset. Just make sure you add them in the right order.
This shows both scenarios:
[TestMethod]
public void Chart_Secondary_Axis_Test()
{
//http://stackoverflow.com/questions/28540458/using-secondary-axis-for-chart-cause-x-axis-and-primary-y-axis-issue-excel
var existingFile = new FileInfo(#"c:\temp\temp.xlsx");
if (existingFile.Exists)
existingFile.Delete();
using (var pck = new ExcelPackage(existingFile))
{
var wsContent = pck.Workbook.Worksheets.Add("Content");
//Some data
wsContent.Cells["A1"].Value = "A"; wsContent.Cells["B1"].Value = "B"; wsContent.Cells["C1"].Value = "C"; wsContent.Cells["D1"].Value = "D";
wsContent.Cells["A2"].Value = 100; wsContent.Cells["A3"].Value = 400; wsContent.Cells["A4"].Value = 200; wsContent.Cells["A5"].Value = 300; wsContent.Cells["A6"].Value = 600; wsContent.Cells["A7"].Value = 500;
wsContent.Cells["B2"].Value = 300; wsContent.Cells["B3"].Value = 200; wsContent.Cells["B4"].Value = 1000; wsContent.Cells["B5"].Value = 600; wsContent.Cells["B6"].Value = 500; wsContent.Cells["B7"].Value = 200;
wsContent.Cells["D2"].Value = new DateTime(2015, 1, 1); wsContent.Cells["D3"].Value = new DateTime(2015, 1, 2); wsContent.Cells["D4"].Value = new DateTime(2015, 1, 3); wsContent.Cells["D5"].Value = new DateTime(2015, 1, 4); wsContent.Cells["D6"].Value = new DateTime(2015, 1, 5); wsContent.Cells["D7"].Value = new DateTime(2015, 1, 6);
const int dataRow = 7;
const string FORMATDATE = "m/d/yy";
wsContent.Cells[2, 4, dataRow, 4].Style.Numberformat.Format = FORMATDATE;
//Single Axis with intersection on the right
var chart1 = wsContent.Drawings.AddChart("Chart1", eChartType.XYScatterLines);
chart1.SetSize(600, 400);
var serie1 = (ExcelScatterChartSerie)chart1.Series.Add(wsContent.Cells[2, 1, dataRow, 1], wsContent.Cells[2, 4, dataRow, 4]);
serie1.Header = wsContent.Cells[1, 1].Value.ToString();
chart1.YAxis.Crosses = eCrosses.Max;
//Dual Axis
var chart2a = wsContent.Drawings.AddChart("Chart2", eChartType.ColumnStacked);
chart2a.SetSize(600, 400);
chart2a.SetPosition(400, 0);
var serie2a = chart2a.Series.Add(wsContent.Cells[2, 2, dataRow, 2], wsContent.Cells[2, 4, dataRow, 4]);
serie2a.Header = wsContent.Cells[1, 2].Value.ToString();
var chart2b = chart2a.PlotArea.ChartTypes.Add(eChartType.XYScatterLines);
var serie2b = chart2b.Series.Add(wsContent.Cells[2, 1, dataRow, 1], wsContent.Cells[2, 4, dataRow, 4]);
serie2b.Header = wsContent.Cells[1, 1].Value.ToString();
chart2b.UseSecondaryAxis = true; //Flip the axes
pck.Save();
}
}
Is it possible to create a broken line chart with the Microsoft chart control?
Similar to this:
Preferably using the same series.
Yes, it's possible. You can use the DataPoint.IsEmpty property to indicate blank points.
Sample code:
Series series = new Series("sample") { ChartType = SeriesChartType.Line, BorderWidth = 2, MarkerSize = 5, MarkerStyle = MarkerStyle.Square };
series.Points.Add(new DataPoint(0, 1));
series.Points.Add(new DataPoint(1, 1));
series.Points.Add(new DataPoint(1.5, double.NaN) { IsEmpty = true });
series.Points.Add(new DataPoint(2, 1));
series.Points.Add(new DataPoint(3, 2));
chart.Series.Add(series);