So here is my successfully generated chart. However for some reason on this chart only it decides the date times should show up at the top of the chart instead of the bottom. Here is my code and what I've tried. Notice the text is neither bold nor is at showing where it should. I've also tried giving the chart a ton of area to work with and it still does this. Any help in the right direction would be greatly appreciated.
ExcelChart paintDewChart = overview.Drawings.AddChart(w.Name + "Dew", OfficeOpenXml.Drawing.Chart.eChartType.LineMarkersStacked);
paintDewChart.Title.Text = "Paint Dew";
paintDewChart.SetPosition(24, 0, 0, 0);
paintDewChart.SetSize(1550, 400);
paintDewChart.Legend.Position = eLegendPosition.Bottom;
var dser1 = (ExcelLineChartSerie)(paintDewChart.Series.Add(w2.Cells["C4:C" + water.Count.ToString()], w1.Cells["A4:A" + water.Count.ToString()]));
var dser2 = (ExcelLineChartSerie)(paintDewChart.Series.Add(w2.Cells["D4:D" + water.Count.ToString()], w1.Cells["A4:A" + water.Count.ToString()]));
dser1.Header = "PC2 Dew";
dser2.Header = "B Dew";
dser1.DataLabel.Position = eLabelPosition.Bottom;
dser2.DataLabel.Position = eLabelPosition.Bottom;
dser1.DataLabel.Font.Bold = true;
dser2.DataLabel.Font.Bold = true;
EDIT:
I figured out I can flip the orientation with this, however labels still overlay on the graph instead of below it.
paintDewChart.YAxis.Orientation = eAxisOrientation.MaxMin;
Here is the correct code I need for my situation.
paintDewChart.YAxis.Orientation = eAxisOrientation.MaxMin;
paintDewChart.XAxis.LabelPosition = eTickLabelPosition.High;
paintDewChart.XAxis.TickLabelPosition = eTickLabelPosition.High;
EDIT: Also depending on minimum and maximum value ranges going from positive to negative, you may need this.
paintDewChart.XAxis.Crosses = eCrosses.Max;
Related
I'm stuck on a problem where i need to set y-axis based on its plot. Right now program stretches the plot to fit whole chart however i need it to let some free space above the plot. I wasn't able to come up with anything so far. Code looks like this:
Chart chart = new Chart()
{
LegendVisibility = Visibility.Hidden,
LeftTitle = YaxisName[i],
BottomTitle = "Carrier i [-]",
};
chart.Content = getChart(graphIndex, GraphYvalues, GraphXvalues, GraphListOfNames[graphIndex]);
chartView.Children.Add(chart);
Could someone please help me out? Thank you
Eventually I was able to scramble something up. It's actually so damn easy. I gave up on setting the range of y-axis and instead of that I added padding to the plot itself like this:
LineGraph lineGraphFar = new LineGraph()
{
Stroke = new SolidColorBrush(Colors.Red),
Padding = new System.Windows.Thickness(0, 30, 0, 0)
};
It's surely not the greatest option but it will do the job.
I know the coordinates of the text on the page. How can I set the background color for this text? Any help would be appreciated.
I sorted out. It is need to add PdfTextMarkupAnnotation to this area.Here is the code. Perhaps it will be useful to someone.
float[] quads = new float[8];
quads[0] = rect.GetX();
quads[1] = rect.GetY() + rect.GetHeight();
quads[2] = rect.GetX() + rect.GetWidth();
quads[3] = quads[1];
quads[4] = quads[0];
quads[5] = rect.GetY();
quads[6] = quads[2];
quads[7] = quads[5];
PdfTextMarkupAnnotation highlightAnnotation =
PdfTextMarkupAnnotation.CreateHighLight(rect, quads);
//установка цвета аннотации
highlightAnnotation.SetColor(ColorConstants.GREEN);
page.AddAnnotation(highlightAnnotation);
I am binding datatable to ASP.NET chart for which I am using custom label for X-Axis. The label text is aligned vertically and the chart size gets reduced.
I tried the following code :
Chart2.ChartAreas[0].AxisX.IsLabelAutoFit = false;
Chart2.ChartAreas[0].AxisX.LabelStyle.Enabled = true;
Chart2.ChartAreas[0].AxisX.LabelStyle.Font = new System.Drawing.Font("Comic Sans", 9F);
Chart2.ChartAreas[0].AxisX.LabelAutoFitStyle = LabelAutoFitStyles.WordWrap;
I also tried the following fix by searching the internet:
Chart2.ChartAreas[0].AxisX.LabelStyle.Angle = 90;
Chart2.ChartAreas[0].AxisX.LabelAutoFitStyle = LabelAutoFitStyles.LabelsAngleStep90;
I tried changing various values for the angle but still it would align vertically.
Any links or suggestion on this would be much appreciated.
I am Ultra New, but this may help:" i have been searching for a solution for the last 4 hrs and someone suggested using annotations. Also this code is in VB, but it may help with another direction if you can't find an answer.
Dim MyTextAnnotation As TextAnnotation
MyTextAnnotation = New TextAnnotation
MyTextAnnotation.Text = "some notation"
MyTextAnnotation.X = 0
MyTextAnnotation.Y = 0
chart1.Annotations.Add(MyTextAnnotation)
Using the Chart controls built into ASP.Net, I'm trying to manually position the Title and the Legend so that they are directly next to each other horizontally just above the ChartArea. I've been able to manually position the Title using the following code:
chart.Titles["Title1"].Position.Auto = false;
chart.Titles["Title1"].Position.X = 10;
chart.Titles["Title1"].Position.Y = 5;
There's nothing to it, really. However, I'm attempting to position the Legend to the right of it with the following code, and the Legend doesn't even appear:
chart.Legends["Legend1"].Position.Auto = false;
chart.Legends["Legend1"].Position.X = 30;
chart.Legends["Legend1"].Position.Y = 5;
Any ideas what I'm doing wrong? This seems like it should be relatively simple. I've even tried various other coordinates, and I can't get the Legend to appear anywhere. It does appear if I use the built-in positioning such as below, but this positioning does not suit my purposes:
chart.Legends["Legend1"].Docking = Docking.Top;
chart.Legends["Legend1"].DockedToChartArea = "ChartArea1";
chart.Legends["Legend1"].IsDockedInsideChartArea = false;
chart.Legends["Legend1"].Alignment = StringAlignment.Far;
Try newing up an ElementPosition object, like this:
chart.Legends["Legend1"].Position.Auto = false;
chart.Legends["Legend1"].Position = new ElementPosition(30, 5, 100, 20);
Note: The constructor for ElementPosition takes 0 or 4 parameters (x, y, width, height).
I stumbled on this question for looking how to move legend at the bottom of a chart.
Answer for that is to use Docking property
Chart1.Legends["Legend1"].Docking = Docking.Bottom;
It may be helpful for someone in future, as this is the first link in google search.
using the MS Charting for .NET, I am trying to zoom into the chart which I have created.
This works fine on the Y axis (type = float) and on the X axis if type = int, but when I have DateTime values on the X axis, scrolling does not behave as it should on this axis.
Vertically, everything still behaves properly, but while I can zoom into the X axis, I cannot drag the sliding bar to move where I am zoomed into. However, I can click either side and it will jump.
Does anyone know how to fix this and make it behave like it does with float values?
Thanks!
Depending on your data, try setting the chart area's CursorX.IntervalType property to something other than Auto.
You may run into a similar issue when trying to use the small scroll arrows of the scroll bar once you are zoomed in. To fix that you can try to set the chart area's AxisX.ScaleView.SmallScrollSizeType property to the same thing as the CursorX.IntervalType.
For example, if you have a chart with data that is reported every 30 seconds you can use the following settings:
chart1.ChartAreas[0].CursorX.IsUserEnabled = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].CursorX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Minutes;
chart1.ChartAreas[0].CursorX.Interval = 0.5D;
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollSizeType = DateTimeIntervalType.Minutes;
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = 0.5D;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "hh:mm:ss";
I had the same problem and these settings solve it for me:
_chart.ChartAreas[0].CursorX.IsUserEnabled = true;
_chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
_chart.ChartAreas[0].CursorX.IntervalType = DateTimeIntervalType.Minutes;
_chart.ChartAreas[0].CursorX.Interval = 1D;
_chart.ChartAreas[0].AxisX.ScaleView.SmallScrollSizeType = DateTimeIntervalType.Minutes;
_chart.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = 1D;
_chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
_chart.ChartAreas[0].AxisX.ScaleView.MinSizeType = DateTimeIntervalType.Minutes;
_chart.ChartAreas[0].AxisX.ScaleView.MinSize = 1D;
_chart.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSizeType = DateTimeIntervalType.Minutes;
_chart.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSize = 1D;
Especially the last two lines did the job.
add
chart.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSizeType = DateTimeIntervalType.Seconds;
My solution was:
chart1.ChartAreas[0].CursorX.IntervalType = DateTimeIntervalType.Milliseconds;