Turn Off Point Labels in MS Chart for .NET - charts

VB2010 using MS Chart: I've added one series as a point chart. On occasion there are over 1000 points and the point labels become way too jumbled. I have smart labeling ON:
cht.Series("srs").SmartLabelStyle.Enabled = True
But nonetheless it still looks bad. So I added a context menu to turn off the labels. The user can then zoom in to a spot and if they wish turn labels back on. I cant seem to figure out a way to do this without looping through ALL data points.
I can totally hide the points and labels by
cht.Series("srs").Enabled = False
But I want just the labels to be hidden and then redisplayed when the user has opted for it.
Any help appreciated.
Edit:
Since I haven't found a method to turn labels off and on with one command I am currently cycling through each point in the series.
Me.Cursor = Cursors.WaitCursor
Application.DoEvents()
'suspend updating UI
cht.Series.SuspendUpdates()
'cycle through all points in the series and set the label either to an empty string or whatever is cached in the Tag property.
'todo: this is not efficient for large datasets but its the only thing we have.
For Each pt As DataPoint In cht.Series("srs").Points
If mnuDisplayLabels.Checked Then
pt.Label = pt.Tag.ToString
Else
pt.Label = ""
End If
Next pt
'resume updating UI
cht.Series.ResumeUpdates()
'force redraw of chart
cht.Update()

I think you have to loop, but you want to suspend updating the UI until you've done it for all points. Try something like:
chart1.Series.SuspendUpdates();
foreach (Series s in chart1.Series)
{
s.IsValueShownAsLabel = false;
}
chart1.Series.ResumeUpdates();

Related

missing figure toolbar and possible change in global variables

Today i tried adding a slider below my graph, so different graphs would be drawn when you slide it. Eventually i got all of this to work perfectly fine, however i still have two small issues.
On top of the figure with the slider, the figure toolbar is gone. It can easily be added by clicking view -> figure toolbar at the top in the figure itself. However to do this everytime is a bit tedious. And when i google'd for the problem, the results where are all guides to create custom toolbars. I just want to add the default toolbar back, it was fine. But i do not know how to do that. Typing 'uitoolbar' gives an empty one. But i am not sure how to fill it with the default icons.
And the second problem i ran into;
The main script calls in the end for a function, this function then creates the new graph with the slider. However herefore i needed to transfer the matrix of data to plot from the main script to the function, so i made the matrix a global variable. However as soon as the function is called, matlab gives me this error (once for each global variable):
> In xxxx at 270
Warning: The value of local variables may have been changed to match the globals.
Future versions of MATLAB will require that you declare a variable to be global before you use that variable.
Before i call the function i type
global xL yL zL p
which are the data required to plot. Then the first line in the function file is this same line again. The data seems to be transmitted fine and the graph shows the correct plot.
Is this some error i can just ignore then? Since everything works as it should? Or what does it mean exactly?
Ok here are my 2 cents:
1) From what I understand the simplest way to fetch the toolbar would be using findobj and then make it visible:
hToolBar = findobj('Type','uitoolbar');
set(hToolBar,'Visible','on');
You can also get the toolbar's properties using "get". Here is what it looks like from a simple script I ran:
get(hToolBar)
hToolBar =
0.1890 %// don't worry about that number; it's the handle for the toolbar.
BeingDeleted = off
ButtonDownFcn =
Children = [1.18896]
Clipping = on
CreateFcn =
DeleteFcn =
BusyAction = queue
HandleVisibility = on
HitTest = on
Interruptible = on
Parent = [1]
Selected = off
SelectionHighlight = on
Tag =
Type = uitoolbar
UIContextMenu = []
UserData = []
Visible = off
I don't know why it disappears though.
2) You might get rid of those global variables if you sent your data as inputs to your function is that a possibility?
For example:
function PlotData(xL,yL,zL,p)
%// Your code here
Hope that helps!

Options Change in Plugin is ignored

I'm trying to create a plugin for flot that will draw axis that cross the origin (0,0) instead of only being shown at the edge of the plot. One thing I'd like to do is, when using my plugin, the drawing of the regular axis (the ones at the edge) should be suppressed. So I added some logic to a function that hooks into processOptions like this:
plot.hooks.processOptions.push(processOptions);
function processOptions(plot, options) {
if (options.crossOrigin) {
if (options.xaxis.crossOrigin) {
options.xaxis.show = false;
plot.hooks.drawBackground.push(drawXAxis);
}
if (options.yaxis.crossOrigin) {
options.yaxis.show = false;
plot.hooks.drawBackground.push(drawYAxis);
}
}
}
By setting options.xaxis.show to false (and the same for the yaxis), this is supposed to stop the axis from appearing, but it doesn't work. The option gets set, but flot ignores it when it draws the graph. The only way I can get it to not plot the regular axes is to explicitly set the show option when setting up the plot.
Any ideas why this doesn't work? Is there a way to make it work?
Update: So after playing around with this for a while, I think what is happening is that there is, for example, an options.xaxis and an options.xaxes (an array) which contains just 1 entry. For some reason, flot wants to use the 1 axis in the options.xaxes[0] instead of options.xaxis. But I'm not quite sure what the logic here is supposed to be. They both get my custom "crossOrigin" option merged in, but only the options.xaxis gets it's "show" property set.
Using xaxes[0] instead of xaxis seems to fix the problem, although it's not clear when and how flot is processing this stuff.

Determine/Save the position of text in matlab

I plotted few points using scatter and then label them using text. The position of these labels are same as the position of the points + some offset. Some of these text label overlap with each other and hence I moved them interactively (using mouse). I can check the new position of each of these text individually using property editor. However this is very time-consuming. Is there a better way to get the coordinates of all these text-label?
You can use findobj to get handles to text objects that are children of the current axes (or another handle... your choice):
text_handles = findobj('parent',gca,'type','text');
Then you can get the positions of these text objects:
positions = get(text_handles,'position');
You may need to do a bit more work to associate each text object with its data point - I suggest taking advantage of the property system, perhaps via the UserData field, for this, though there are many options.
If you want to do it easily later do this in your plots, for example:
h=text(2.9,7.5,'MyText');
This will put "MyText" at position 2.9, and 7.5.
Then to change the position use:
set(h,'Position',[2.5 7]);
This will change the position to 2.5 and 7.
Later if you need to see tthe position of text again use:
get(h);
Hope this helps.

D3.js pie chart labels for slices not tweening

When I click on the various hyperlinks to tween my chart: while the pie's slices are tweening but I cannot figure out how to bring along each slice's label.
A mostly working JSfiddle is here: http://jsfiddle.net/lukateake/MX7JC/
Thanks in advance for any insights you can provide me. I promise to update the fiddle with whatever solution we discover as I imagine this effect is of interest to a great many D3'ers.
The main issue here is in your updateChart function - while you rebound the data to arcs, you did not do so for sliceLabel: (second line added)
arcs.data(donut(data.pct)); // recompute angles, rebind data
sliceLabel.data(donut(data.pct));
One other small thing - your slice label text selection seems a little bit strange:
var sliceLabel = label_group.selectAll("text.value")
but you are creating no text with class = "value"; this doesn't really end up affecting much, but might cause problems in other implementations - selectAll("text") or selectAll("text.arcLabel") might be more appropriate here.
updated fiddle at http://jsfiddle.net/MX7JC/9/

asp.net charts: Legend overlapping with X-axis

I am creating a Chart (DataVisualization.Charting.Chart) programmatically, which is a Stacked Bar chart.
I am also adding Legend entries programmatically to it. I want to show the Legend at the bottom of the chart.
But, while doing so, the Legend overlapps with the X-axis of the chart.
Here is the code I am using:
Private Function GetLegend(ByVal legendName As String, ByVal s As Single) As System.Windows.Forms.DataVisualization.Charting.Legend
Dim objLegend As System.Windows.Forms.DataVisualization.Charting.Legend = New System.Windows.Forms.DataVisualization.Charting.Legend()
objLegend.Name = legendName
objLegend.Font = New System.Drawing.Font("Verdana", s)
objLegend.IsDockedInsideChartArea = False
objLegend.Docking = Docking.Bottom
Return objLegend
End Function
Below statement adds that Legend to the chart
_msChart.Legends.Add(GetLegend("SomeValue1", 10.0F))
Any idea, what is missing? I want to show the legend at the bottom only, but it should not overlapp with the X-axis.
I had the same problem today. Try adding:
objLegend.Position.Auto = true
objLegend.DockedToChartArea = "yourChartAreaName"
That did not help me but I found on the net that this might be helpful (and clean solution).
What actually worked for me was moving chart area to make space for legend so it no longer overlaps. My legend was on top so this code worked for me:
chart.ChartAreas[0].Position.Y = 15
You can try resizing it instead, forcing it to be for example 20 pixels shorter than chart.Size.
Hope this helps.
I had an overlapping legend/chart area problem as well but none of the other suggestions here seemed to make any difference. I think the problem stems from legend text wrapping to two lines and the sizing algorithms not taking account of this.
The ideas here got me thinking more clearly about the problem though, and I was able control the size and position of the chart area using the following.
Chart1.ChartAreas[0].InnerPlotPosition = new ElementPosition(15, 5, 90, 75);
There's not much intellisense on those parameters, but as well as I could deduce, the parameters are all percentages of the total chart area (I initially thought they might be pixel values and got some very odd results). So what I've written above would set the plot area to start at 15% in from the left edge of the chart image and 5% down from the top, and have a width of 90% and a height of 75%.