I'm using a line chart to plot some values, where the x-axis has a set of strings and the y-axis has a double value between 0 and 1. Everything works correctly except there is a gap between the first x value and the y-axis
the image shows.
In this question the solution is setting the x-axis maximum and minimum value. However, I can't seem to do it in this case as the values are strings and not doubles / dates.
Given that you are using strings, this may or may not help. Try setting the IsXValueIndexed property of your underlying series to be false.
See this MSDN article for reference:
http://msdn.microsoft.com/en-us/library/system.web.ui.datavisualization.charting.series.isxvalueindexed(v=vs.110).aspx
To remove the margin you need to set
chart.ChartAreas[0].AxisX.IsMarginVisible = false;
Related
I have a chart using Syncfusion LineSeries.
I would like to scale the data on the X axis. Only the same values in the graph (the data on the axis label should be the same as it is now)
In short, the visible graph should be horizontally downloaded (e.g. scaled down 10 times)
Can it be done?
Just dividing the value by 10 does not change anything when the chart continues to fill the chart completely.
Image
We would like to suggest the following chart axis features.
Maximum property used for setting the maximum value for the axis range
Minimum property is used for setting the minimum value for the axis range.
EnableAutoIntervalOnZooming property is used to maintain the interval even it is in zooming state only if we set the interval to the axis. Default value of this property is true. While zooming based on the auto range padding the interval will be calculated.
For more details, please refer below UG,
https://help.syncfusion.com/wpf/charts/axis
Note: I am working in Syncfusion.
I would like to customize the Y axis labels of a graph plotted with Microsoft ReportViewer.
What I want is to have a logic like the following:
If (value>1000000)
return value/1000000 & "M"
else
return value
For example if the value of the label is 12000000 then the label value will be 12M, otherwise if the label value is 1200 the value will remain 1200.
I have tried to customize the numeric format to obtain this kind of behaviour tring something like:
= iif(value>1000000,value/1000000 'M',value)
(to help contextualize my question, i'm talking about this window=> https://dotnetblurb.files.wordpress.com/2012/05/3.jpg)
but, as expected, it didn't work.
Googling didn't help much as well, it seems like this kind of customization is just not possible. Or is it?
Thank you very much!
I solved this issue using both the expressions window and altering the graph's datasource content.
In the method filling the data source I added the logic converting big numbers into smaller numbers:
reportModel.MillionsSymbol = "";
if (reportModel.TotalValue > 1000000)
{
reportModel.TotalValue /= 1000000;
reportModel.MillionsSymbol = "M ";
}
I also added the new MillionsSymbol field to my data source and I change its content based on the TotalValue.
Then, I can use this new field in the dialog Vertical Axis Properties -> Number -> Category[custom]
="0.00" & Fields!MillionsSymbol.Value
The trick here is that I wrote an expression that is returning a string containing the characters mask needed by the function that is formatting the axis numbers' label. In this string I can put anything as long as it contains the mask (0.00, #.##,...).
This method allows me to concatenate a variable to the value that is going to appear as a label for every tick of the vertical axis of the graph. It doesn't allow me to work on that value, since I didn't find any way to get access to it. This is why I altered the values in the data source. In this way, though, I'm changing the value of the graph points and then conseguently the vertical axis ticks' values.
Final result:
*Image edited for clarity
By default the WinForms Chart control shows labels centrally below the ticks.
Is there any way to change that so that the labels are shown between the ticks instead, as per this image:
I think the only way to do this would be to use custom labels. That means taking over the job of adding the labels from the control and doing it manually yourself, which may or may not be suitable in your case.
The "Labeling Axes Using Custom Labels" section of the MSDN documentation describes this in more detail:
Use custom labels to provide custom text for axes. Custom labels are
implemented using the CustomLabels collection property. If you use
custom labels, the chart area does not display axis labels from data
points.
When using CustomLabel objects, you must set the ToPosition and
FromPosition properties of each CustomLabel object, and these
properties must specify the width of the label's text area. Do not
assign the same value to both of these properties because they
represent a range. To position a custom label directly beneath a data
point and its associated tick mark, set the FromPosition property to
the value of that data point's axis minus half of the tick mark
interval, and set the ToPosition property to the value of that data
point's axis plus half of the tick mark interval. For example, if an
axis has an interval of 1 (1, 2, 3,…), and you want to use a custom
label at X=2, then set the ToPosition and FromPosition properties to
1.5 and 2.5, respectively.
The RowIndex property specifies on which row the custom label is
displayed. If a custom label is used in the first label row, the chart
area does not display any labels from the axis scale. The only labels
permitted in the second row and beyond are custom labels.
In your case you don't want the labels to be directly below the tick mark, so in the example in the quoted text above you'd set your position ToPosition to 2 and your FromPosition to 3.
Looking at your specific graph, if the x-axis values are DateTimes, you'll need to check if the To/From Positions will work with DateTimes. If not, you may need to convert the values to serial numbers (you could use e.g. DateTime.ToOADate() to do this) before using them for the x-axis. That won't effect what's displayed as you will be replacing those labels with your own ones anyway, which you can then format as you wish.
The regular Labels will always show with the DataPoints. But you can show the tick marks between.
Depending on the datatype and Interval you can set an MajorTickMark.IntervalOffset:
chart1.ChartAreas[0].AxisX.MajorTickMark.IntervalOffset =
chart1.ChartAreas[0].AxisX.Interval / 2f;
Note: For this to work you need to set the Interval. By default it is set to 0.0, so you need to set it to some other value! Most of the tome a value of 1 will be fine.
The harder altenative would be to use CustomLabels for that.. Much more work for the same result. Not really recommended. You can see an example here
My chart has a Datetime type X Axis and Double type Y Axis. I am trying to use the following code to insert the scalebreakstyle feature but it is not working. Does anyone have sample code for it. I was trying the web.UI code but did not work. Also I set the color of 2 series the same it keeps making them different.
/
/ Enable scale breaks.
chart1.ChartAreas["ChartArea1"].AxisY.ScaleBreakStyle.Enabled = true;
// Show scale break if more than 25% of the chart is empty space.
chart1.ChartAreas["ChartArea1"].AxisY.ScaleBreakStyle.CollapsibleSpaceThreshold = 25;
// Set the line width of the scale break.
chart1.ChartAreas["ChartArea1"].AxisY.ScaleBreakStyle.LineWidth = 2;
// Set the color of the scale break.
chart1.ChartAreas["ChartArea1"].AxisY.ScaleBreakStyle.LineColor = Color.Red;
// If all data points are significantly far from zero, the chart will calculate the scale minimum value.
chart1.ChartAreas["ChartArea1"].AxisY.ScaleBreakStyle.StartFromZero = StartFromZero.Auto;
// Set the spacing gap between the lines of the scale break (as a percentage of the Y-axis).
chart1.ChartAreas["ChartArea1"].AxisY.ScaleBreakStyle.Spacing = 2;
www.tinypic.com/r/6e2c83/5
Scale breaks will not work under a wide array of conditions. According to the documentation any of the following causes scale breaks to be "not supported", which I have found means they will not work at all or they will warp your graph in weird ways
•Pie, doughnut, funnel, pyramid, radial or any stacked chart types are used.
•Custom intervals for labels, tick marks or grid lines are enabled.
•The minimum or maximum value for the axis is set.
•Custom labels are used.
•A logarithmic Y-axis is specified.
•Axis views on the Y-axis, which include scrolling and zooming, are used.
•3-D charts are used.
It looks like you maybe have a custome x axis label which would cause the scale break to fail.
Is it possible to force the display of grid lines on the chart with the dates for the extreme data points?
I've tried almost every configuration of following Chart DateTimeAxis properties: IntervalType, Interval, Minimum and Maximum but I wasn't satisfied with the result.
Setting properties Minimum and Maximum didn't solve the problem.
For instance (IntervalType="Days" , Interval="4" , Minimum="1/1/2010" , Maximum="1/31/2010"):
If I'm lucky I will generate some random data where only one extreme point will have the date with grid line.
Does somebody have an idea how to solve the problem mentioned above?
Edited to add
I added a bounty to this question since I really need a fast solution for this issue.
I am binding a series of specific pairs to my chart and I'd like to display excactly those given DateTime values on the x-axis.
Since these are usually dates like 6/30/11, 6/30/12 and so on, I can't use the Interval/IntervalType properties because adding 1 year or 365 days to 6/30/11 doesn't necessarily result in 6/30/12.
So what I need to do is either disable the "automatic axis label generation" of the DateTime axis or use another axis type.
LinearAxis doesn't work because it expects double values and CategoryAxis is not an option because it displays the axis labels between two tickmarks instead of underneath them.
I am very grateful for any help!
To be perfectly clear, here is what axis labels I need (taken from another chart component):
This is what I get so far with the Silverlight 4 Toolkit:
€: I also opened a thread in the official Silverlight Toolkit Support Forums.
The vertical lines are set where you specify an interval.
There is no vertical line for the data for 1/31/2010 as it does not fall on an interval.