When making a Bar chart with percentage label, I am using this way.
Excel.DataLabel dl1 = (Excel.DataLabel)series.DataLabels(0);
dl1.NumberFormat = "0.00%;-0.00%;";
By putting this format, it would multyply 100 to input values. That is fine. But the problem is the Axis measure values show like:
How can I fix it? Or any other ways to add '%' to value labels?
Thanks.
You'll need to select the X axis of the chart and then change the format of the TickLabels.NumberFormat property:
// Select the X axis
var xAxis = (Axis)yourChart.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary);
// Update the format of the tick labels
xAxis.TickLabels.NumberFormat = "0.00%;";
Related
This should be easy, I just can't find it:
I find a datapoint in a series given some rules, I then want to show that point on the chart, at the moment it shows only the Y value. I need it to show both X and Y values, something like -1506;409
(X axis value = -1506, Y axis value = 409)
To display the datapoint I have at the moment:
datapoint.Font = new System.Drawing.Font("Serif", 7);
datapoint.LabelFormat = "#,#";
datapoint.IsValueShownAsLabel = true;
Any ideas?
Edit:
datapoint, of course is:
Datapoint datapoint
A nice overview of Labels in Chart controls is here on MSDN.
Here is an example at work; the first line labels each point in a whole series, the second line only one point in another series:
chart1.Series[3].Label = "Y = #VALY\nX = #VALX";
chart1.Series[1].Points[5].Label = "Y = #VALY\nX = #VALX";
A less crowded altenative may be setting tooltips, which only show up when the mouse is over the datapoint:
chart1.Series[2].ToolTip = "Y = #VALY\nX = #VALX";
For more ways to include data values do look into the chart Keywords!!
With the help of #Taw's code, its easy, just append the format to your specific datapoint:
datapoint.Label = "Y = #VALY\nX = #VALX";
I have a chart which is populated with DateTime values in descending order, but the x axis labels are in ascending order. How do I get the labels to match the data?
foreach (var eventData in eventResultsFinal)
{
sensorTimeStamp = ConvertFromUnixTimestamp(secondsSinceEpoch +
Convert.ToInt32(eventData.t1));
if (eventData.v1.Equals("active"))
chart1.Series[chartSeriesCounter].Points
.AddXY(sensorTimeStamp.ToOADate(), 1 + yOffset);
else if (eventData.v1.Equals("inactive"))
chart1.Series[chartSeriesCounter].Points
.AddXY(sensorTimeStamp.ToOADate(), 0 + yOffset);
}
}
See the image above - the timestamps are increasing, I would like them decreasing.
If you want to show the data in a reversed order you can tell the X-axis to do so by setting its IsReversed property:
chart1.ChartAreas[0].AxisX.IsReversed;
An alternative, but not recommended way would be to add the X-Values as strings instead of DateTimes. Then the DataPoints would be ordered in the same way you add them, but you could not really work with the X-values anymore..
Update: Since Reversing the X-Axis also reverses the order of the Y-Axis placement you may want to set the Y-Axes like this:
chart1.ChartAreas[0].AxisY.Enabled = AxisEnabled.False;
chart1.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True;
Note: All styling of the primary Y-Axis should now go to the secondary one (AxisY2), including any CustomLabels.
I'm trying to use the chart control on a windows form and have it working, plotting some real time data, however before the data arrives nothing is displayed. I would like to show an empty graph with an X Y of 10 30 but still have the graph auto range if values go above this.
I cannot find a property to show the "blank" graph it this possible and if so how?
thanks
You can hide all data of a Series by making its line color Transparent. If you also set its LegendText to be " " all you can see are the Axis ticks. you can control them by adding a few Points and by setting the Minimum and Maximum values:
// short reference for our dummy:
Series S0 = chart1.Series[0];
// a simple type
S0.ChartType = SeriesChartType.Line;
// set 10 point with x-values going from 0-100 and y-values going from 1-10:
for (int i = 0; i < 100; i +=10) S0.Points.AddXY(i , i / 10);
// or add only a few, e.g. the first and last points:
//S0.Points.AddXY(100, 10);
//S0.Points.AddXY(0, 10);
// hide the line:
S0.Color = Color.Transparent;
// hide the legend text (it will still take up a little space, though)
S0.LegendText = " ";
// limit the axis to the target values
chart1.ChartAreas[0].AxisX.Maximum = 100;
chart1.ChartAreas[0].AxisX.Minimum = 0;
The result looks like an empty chart:
So, I am trying to plot the graph and I have 3 fastlines in the Tchart, It seems like the graph are correct but there is something I need to set with labels of axes, What I get is this,
[my graph with x labels as 0 0 0 0 1 1 1 1 ]
http://s8.postimage.org/t7tappekl/image.png
[I want something like this]
http://s7.postimage.org/amltkb917/untitled.png
and what I want to get is something like this , the actual x labels as these . X labels are seconds.
I have already tried setting the valueformat for series and chart lablels. It did not work,
How should I do this? and also I am trying to zoom and scroll up the y axes to set the focus like the image 2. the y graph always starts from 0 , but initially is there any way to set the focus on starting point i.e.81
Thank you so much!
You can set desired increment for the bottom axis labels using the so called Increment property, for example:
tChart1.Axes.Bottom.Increment = 0.1;
For changing axes range you can use SetMinMax or Minimum and Maximum properties:
tChart1.Axes.Left.SetMinMax(50, 100);
or
tChart1.Axes.Left.AutomaticMinimum = false;
tChart1.Axes.Left.Minimum = 50;
tChart1.Axes.Left.AutomaticMaximum = false;
tChart1.Axes.Left.Maximum = 100;
Finally, you can change the chart view perspective changing some of the following properties:
tChart1.Aspect.View3D = true;
tChart1.Aspect.Orthogonal = false;
tChart1.Aspect.Chart3DPercent = 50;
tChart1.Aspect.Elevation = 0;
tChart1.Aspect.Rotation = 345;
tChart1.Aspect.Perspective = 50;
BTW, you'll find more information about axis settings in tutorial 4. Tutorials can be found a TeeChart's program group.
I'm using MS Chart generated image on a MVC3 view.
The chart works but the maximum value is so high on the top of the chart that I can't read the values.
Shouldn't the chart have a margin from the max value?
I don't really know if this is a real problem but I can't make this look nice unless I define a AxisYMaximum value that I think should not be used on dynamic values.
Yes, the chart control should calculate the margin necessary to clearly display the data, but in my experience, it doesn't.
Since your y-values are dynamic, you can dynamically set the AxisYMaximum to a value just above the greatest displayed y-value. Something like this could set it:
double greatestYValue = double.MinValue;
foreach (var pt in Chart1.Series[0].Points)
{
if (greatestYValue < pt.YValues[0]) greatestYValue = pt.YValues[0];
}
Chart1.ChartAreas[0].AxisY.Maximum = greatestYValue * 1.2;
// or
Chart1.ChartAreas[0].AxisY.Maximum = greatestYValue + 20;
I just looped through all the points in the first series to find the greatest y-value, then set the y-axis maximum to 120% of that value, or some absolute amount above that value, or whatever you need.
You could also get the greatest y-value in a one-liner using LINQ:
double greatestYValue = Chart1.Series[0].Points.Select(p => p.YValues[0]).Max();