korthmat Posted October 29, 2008 Report Share Posted October 29, 2008 One of the products I worked on is a bar chart of production against an expected standard. The chart has two series, one for the actual amount, and one for the shortfall amount (if any). The chart is stacked, so that the shortfall bars, when they're present, appear on top of the actual bars. I draw a line across the chart at the level of the expected production. All this is working just fine. But (and you knew this was coming, right?), I've just gotten a batch of defects, and one of them complains that: The series labels ("shortfall" and "actual") in the legend box are reversed from what they were in the previous version of the software; and The expected line is appearing in the legend box, but shouldn't. The problem is, the solutions I've come up with cause problems of their own. I can reverse the order in the legend box by changing the order of the SeriesAttributes that I define in XAML, but this means that I wind up with the actual bars being stacked on top of the shortfall bars, which I don't want. Similarly, I was able to get the expected line to not show up in the legend, but to do that I had to remove the title, which I don't want. Is there any way I can control what gets put in the LegendBox, and in what order? Quote Link to comment Share on other sites More sharing options...
JuanC Posted October 29, 2008 Report Share Posted October 29, 2008 You can control the visibility of items in the legend box using the LegendBox.ItemAttributes property, this property is not XAML friendly so you will have to set it in code. Assuming you are drawing the expected production line using custom gridlines, you can control its visibility in the legend box with the following code: chart1.LegendBox.ItemAttributes[chart1.AxisY.CustomGridLines].Visibility = Visibility.Collapsed; Note that ItemAttributes has another indexer with an integer that specifies the index of the item you want to modify, so if you had a chart with 3 series you could hide the second series from the legend box with the following code chart1.LegendBox.ItemAttributes[chart1.Series, 1].Visibility = Visibility.Collapsed;We do not have an answer for your question on how to control the legend box items order, informally we have discussed the following options 1) By default as you noted we invert the order in the legend box for stacked charts, the rationale behind this change was to show the items in the legend box in a similar way as how they are shown in the plot area. We could add a boolean property to disable this behavior. 2) Adding a integer property in LegendBox.ItemAttributes that allows you to override the order, we would have to decide whether this order apply to items in each of the groups supported by the legend box (series, points, axis gridlines and sections, conditional attributes, etc.) or if it is a global order (allowing you to intermix elements from the different groups). Regards, JuanC Quote Link to comment Share on other sites More sharing options...
Mick Posted March 24, 2009 Report Share Posted March 24, 2009 I came across this post and it seemed to be just what I was looking for. However, setting the LegendBox ItemAttributes doesn't seem to be working in my case. Here is a short sample that highlights what is happening: public Chart PieChart(){ Chart chart = new Chart(); chart.Gallery = Gallery.Pie; // Create the series SeriesAttributes series = new SeriesAttributes(); series.Gallery = Gallery.Pie; chart.Series.Add(series); // Add some data for (int j = 1; j <= 5; j++) chart.Data[0, j - 1] = new DataUnit(j); // Collapse the legend entries chart.LegendBox.ItemAttributes[chart.Series, 0].Visibility = Visibility.Collapsed; return chart;} What I would expect to see from the chart is a pie chart with 5 slices and no legend entries (and perhaps an empty legend box). However, the legend entries still appear as "Point 1," "Point 2," "Point 3," and so on. What am I missing? Thank you in advance, Mick Quote Link to comment Share on other sites More sharing options...
JuanC Posted March 24, 2009 Report Share Posted March 24, 2009 In a pie chart the entries shown on the legend correspond to the X axis, so if you wanted to hide them you would write chart1.LegendBox.ItemAttributes[chart1.AxisX].Visibility = Visibility.Collapsed;Or if you want to hide the legend box completely chart1.LegendBox.Visibility = Visibility.Collapsed; Regards, JuanC Quote Link to comment Share on other sites More sharing options...
TEKGroup Posted March 31, 2009 Report Share Posted March 31, 2009 Has there been any further discussion about how to order the items in the legend? A of ours that we are using the charts we create with your software is having a major issue about how the items are being shown (where the first item is always at the bottom of the list with other stacked on top of that). Aa JuanC stated, giving them to you in the reverse order fixes the issue with the legend, but messes up the order on the chart. Also, is there a way to force the list to show the items in "x" amount of columns, rather than create a huge 1 column listing of all of the items?Example: 2 Column Based --> Item 1 Item 2Item 3 Item 4Item 5 Item 6 Rather than is showing up like this: Item 1Item 2Item 3Item 4Item 5Item 6 It seems that the software arbitrarily determines how this layout should appear, as I've found no documentation that will force a column based legend layout. If I've missed a setting or settings, please let me know what I've overlooked. Thanks, Jason Quote Link to comment Share on other sites More sharing options...
JuanC Posted April 1, 2009 Report Share Posted April 1, 2009 About the order of the series in the legend box: We normally show the first series on top, the only case where we switch it is on a Stacked chart. This is a popular request because in a stacked chart the first series is usually on the bottom of the bar/area. About the layout of the legend box: We use a StackPanel by default but if you want multiple columns you could use a UniformGrid or any other custom built panel that generates the desired layout. Note that because we add the items automatically to the panel, you need to use a panel such as UniformGrid that does not need additional attached properties on each element (e.g. you cannot use Grid as it depends on Grid.Row and Grid.Column). <cfx:Chart.LegendBox> <cfx:LegendBox> <cfx:LegendBox.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Columns="2"/> </ItemsPanelTemplate> </cfx:LegendBox.ItemsPanel> </cfx:LegendBox></cfx:Chart.LegendBox>Regards, JuanC Quote Link to comment Share on other sites More sharing options...
TEKGroup Posted April 1, 2009 Report Share Posted April 1, 2009 JuanC, We are currently using Chart FX for Java 6.2, so based on your responses I have a few more questions: About the order of the series in the legend box: We normally show the first series on top, the only case where we switch it is on a Stacked chart. This is a popular request because in a stacked chart the first series is usually on the bottom of the bar/area. Our client unfortunately wants the reverse of this for their GANTT chart legend. While they want the first item on the bottom of the stacked chart, they want it at the top of the legend. Is there a way to force the legend to swap this? About the layout of the legend box:We use a StackPanel by default but if you want multiple columns you could use a UniformGrid or any other custom built panel that generates the desired layout. Note that because we add the items automatically to the panel, you need to use a panel such as UniformGrid that does not need additional attached properties on each element (e.g. you cannot use Grid as it depends on Grid.Row and Grid.Column). <cfx:Chart.LegendBox> <cfx:LegendBox> <cfx:LegendBox.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Columns="2"/> </ItemsPanelTemplate> </cfx:LegendBox.ItemsPanel> </cfx:LegendBox></cfx:Chart.LegendBox> As I stated above, we are using Chart FX for Java 6.2, so is there a method in the version we have to force the legend to be in 2 columns? I didn't see anything in the documentation regarding ItemsPanel. Thanks,Jason Quote Link to comment Share on other sites More sharing options...
JuanC Posted April 1, 2009 Report Share Posted April 1, 2009 All my answers in this thread apply to ChartFX for WPF. I would suggest you post your question in the ChartFX for Java forums. JuanC Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.