I have two questions about axis labels:
How do I make a label at the Y2-axis, that shows a highlighted label following the dynamic price (y2-value) of the last bar/candlestick? As the red label in this example:
And possibly also the same on the XAxis, showing the time of the last bar.
Also I wonder how to make the time axis plot only every 30 min, and also that it should be full half hours, not arbitrary 30 min spots.. As also shown in the above image.
ZedGraph is awesome. But takes some time to figure out the tricks and tweaks.. :)
Ad. 1.
You probably need to create a custom text object. If I remember correctly:
TextObj label = new TextObj("some text", 1, y2coordinate);
label.Location.CoordinateFrame = CoordType.XChartFractionY2Scale;
label.Location.AlignH = AlignH.Left;
myPane.GraphObjList.Add(label);
to change the color and background, just edit properties of label.FontSpec
Ad. 2.
You need to set manualy the Min, Max and MajorStep of the Scale object of your axis.
Related
I would like to ensure the labels of my bar chart are above the bars. Can you force a label on top of a bar chart in SQL Server Reporting Services? If so, how?
The issues are the colors are so dark, it's hard to read them if they are not above the bar in the chart. I could just change the colors, but I'd rather learn how to force the label location if possible.
I'd like all numbers to be above the bar, like over the blue bar below. I have over 100 different charts in my report, so the scale will vary greatly depending on the particular report.
Thank you!
In Visual Studio, design mode, ensure that the properties window is visible, then click on any of the labels on the chart.
At this point, the properties window should show the properties for Chart Series Label.
Find the 'Position' property, which probably is showing the value 'Auto', change this value to 'Top' and this should do the trick.
You have to first make sure the chart type is not stacked.
In my experience the "Position" property doesn't always work.
Sometimes you have to go to the properties of the series, then "Custom Attributes", then "Label Style" then select "Top".
What #niktrs said in the comments of the other answer about setting the AllowOutsidePlotArea property is also true.
Microsoft do not use the label Position property for some of the chart types.
They tell us what they use by default here - in your case "on bar charts labels are placed outside of the bars that represent data points" (they appear to mean "column charts")...but sometimes with a large value it's placed just inside, sometimes partially in-out (and if you try the "Outside" position it just fails to render!).
As #jayvee has mentioned the trick with Column charts is to select the value and change the SmartLabels AllowOutSidePlotArea to True (from Partial).
However if you have a Stacked Bar chart then labels are always in the centre of the particular value.
The hack to get labels on top is to add an extra Stacked Bar value with the Color set to "No Color" and move it to the top of the values (using the Chart Data designer arrows).
The trick is getting a good expression value to use - a constant ends up too big or too small at some point, so I found a percentage of the stacked values works best (remembering to change Nulls to Zeros)...25% to 30% usually works.
Then set the value Label to the value you want to display in the data label.
I just had this issue, I was able to fix it by making sure the chart series "Smart Labels" - "Disabled" property was set to "True"
This is what my properties pane looks like:
I am creating a custom bar chart using VB.NET, I am wondering if there is a way to program the distance between intervals in the y axis. For example if I wanted the distance between points 1 and 2 in the axis to be of a certain length e.g 2cm long and the next interval to be of a certain length e.g 5cm long, is there a way to achieve this. Any help would be appreciated.
You can set the ChartArea to be a specific size and then configure the Axis.Interval property
No (at least, not easily). The Axis.Interval property sets all intervals to be the same size. You would need to subclass Chart and override the OnPaint method to draw the ticks (and/or grid lines) with different spacings. Not sure offhand if there are ways to have it paint parts of the chart as it normally would, while doing custom painting on other parts...
ETA: It may become slightly easier if you only have 2 intervals to worry about (e.g., the axis line itself, then one line 2 cm up, then another line 5 cm up from that, and no more lines after that). You could probably use the Axis.Interval and Axis.MinorGrid.Interval properties in that case.
ETA again, since it didn't show up nice in the comments: One thing you could try is to hide all of the ticks and grid lines, and then handle the OnPaint event (not override) to just draw lines on top of the chart where needed. Something like this psuedocode
private void ChartPaint(object sender, Args e) {
e.Graphics.DrawLine(figure_out_2cm_above_axis, Color.Black, etc);
e.Graphics.DrawLine(figure_out_5cm_above_line, Color.Black, etc);
}
I guess there's tons of answers, but i have only found answers regarding the data update, not the chart itself.
In my case i have a chart that updates every X minutes. When the program starts, it looks in a file for some values. Lets say there's only one one value (one column in this case), and this value is 20. Then it shows it nice with 30 as maximum.
When it refresh, i do something like this
TheDiagram.Series.Clear()
Dim Serie_Value As New Series
With Serie_Value
.Name = "MySerie"
.ChartType = SeriesChartType.StackedColumn
.Color = Color.Green
With .Points
.AddXY("MyName", theValueFromFile)
End With
End With
TheDiagram.Series.Add(Serie_Value)
In this case, we say that the value now is 60, then the y-axis is still on 30 as max so that I can't see the end (top) of the column.
How can I tell the chart/chartarea to "redraw yourself like you were rendered the first time"?
To reset the auto scale just use this after loading the points into the chart.
Chart1.ResetAutoValues()
Have you tried auto-scaling the y-axis?
' Auto axis scale
Chart1.ChartAreas("ChartArea1").AxisY.Minimum = [Double].NaN
Chart1.ChartAreas("ChartArea1").AxisY.Maximum = [Double].NaN
You should set those every time the chart refreshes, the axis should adjust automatically then.
Available since .NET 4.0: Chart1.ChartAreas[0].RecalculateAxesScale();
In my simple vb.net chart that displays a particular series, I would like to obtain running values of the actual values in the chart. I can already obtain the x-y coordinates, which is easy (e.x and e.y) - but wondering if there is a available method to convert the coordinates to the values related to the chart itself.
I need to use the mousemove event rather than mousedown.
I wish to transfer these actual values to a textbox on the form.
Thanks - burnt out trying to figure this out on my own.
This is pretty easy, unless the chart control doesn't give you some crucial information, in which case it's pretty hard :)
Your chart control probably shows several elements: the chart itself (bounded by the X and Y axes), the chart title, the axis titles, maybe a legend, etc. What you need to know is the .Left and .Width values of your X-axis. Assuming you can obtain those, the formula you want is
actualX = (mouseX - axis.Left) / axis.Width * (axis.Max - axis.Min) + axis.Min
Without knowing what chart control you're using on which platform, it's hard to tell you how to find all those pieces, but the formula is what you're looking for.
How may I get a DataVisualization.Charting Chart to show its axes and gridlines before points are added? Currently the chart area is blank even if axes scale limits are set manually, and I can see no good reason for this.
Set the Axis.Enabled properties to 'AxisEnabled.True' instead of 'AxisEnabled.Auto'
chartArea.AxisX.Enabled = System.Windows.Forms.DataVisualization.Charting.AxisEnabled.True;
chartArea.AxisY.Enabled = System.Windows.Forms.DataVisualization.Charting.AxisEnabled.True;