jFreeChart: How to hide items from legend? - jfreechart

I need to hide every second/third/forth item from the legend. IS there a way to achieve this in jFreeChart?
thanks!

I have tried the above suggestion but it didn't seem to work for me. If you just want to remove series from the legend you can do it with the setSeriesVisibleInLegend() method. My scenario was that some of my series do not have a legend key. If they don't have a legend key then the series shouldn't be visible in the legend. I implemented this with the following code:
for(int i = 0; i < seriesList.size(); i++){
if(seriesList.get(i).getKey() == null || seriesList.get(i).getKey().equals("")){
graph.getXYPlot().getRenderer().setSeriesVisibleInLegend(i, Boolean.FALSE);
}
}
The seriesList is a list of seriesData pojo's that I created that holds all of the graph data to create the graph. If the seriesData object's key value is null or = "" then the series will not be visible in the legend.

okay, just did it myself. This way I remove every second item from the legend.
please leave comments!
LegendItemCollection legendItemsOld = plot.getLegendItems();
final LegendItemCollection legendItemsNew = new LegendItemCollection();
for(int i = 0; i< legendItemsOld.getItemCount(); i++){
if(!(i%2 == 0)){
legendItemsNew.add(legendItemsOld.get(i));
}
}
LegendItemSource source = new LegendItemSource() {
LegendItemCollection lic = new LegendItemCollection();
{lic.addAll(legendItemsNew);}
public LegendItemCollection getLegendItems() {
return lic;
}
};
chart.addLegend(new LegendTitle(source));

Related

get value of RepositoryItemRadioGroup

i need to get selected value of RepositoryItemRadioGroup
how can i get it ??
for (int i = 0; i < gridView1.RowCount; i++)
{
int rowHandle = gridView1.GetVisibleRowHandle(i);
QuestionsAndAnswers row = (QuestionsAndAnswers)((GridView)gridControl1.MainView).GetRow(rowHandle);
// row.RadioGroup> represent RepositoryItemRadioGroup
//i need to get selected value in row.radiongroup
}
It is not quite clear to me why you need to get access to the RadioGroup directly. If you have bound your GridView to the collection of the QuestionsAndAnswers objects you should not iterate GridView rows itself due to the fact that all the values are already mapped onto the QuestionsAndAnswers properties in a two-way manner. Thus iterate your QuestionsAndAnswers collection directly:
List<QuestionsAndAnswers> qaList = new List<QuestionsAndAnswers> {
new QuestionsAndAnswers(){ Question ="How are you?" }
}
// data binding
gridControl1.DataSource = qaList;
...
void getAnswersBtn_Click(object sender, EventArgs e) {
foreach (QuestionsAndAnswers qa in qaList){
var answer = qa.Answer;
// do something
}
}
If you are bound the GridView in another manner, please, update your question with the detailed description:
- how you bind the GridView to data;
- whether or not you use the approach demonstrated by #Alex.T in your previous question;
- whether or no you read and understand the documentation;
BTW, the main question is - have you contacted the DevExpress team direcly and what their guys said?
for (int i = 0; i < gridView1.RowCount; i++)
{
// can't get answer of last record so i added test line in the last record to get all answers without new last record
if (i==gridView1.RowCount-1)
{
continue;
}
int rowHandle = gridView1.GetVisibleRowHandle(i);
string ResultAnswer = (string)gridView1.GetRowCellValue(rowHandle, "Answer");
string ResultQuest = (string)gridView1.GetRowCellValue(rowHandle, "Question");
}

Legend box series title, how to highlight other chart series in LightningChart?

I can see that when moving mouse over series titles in ViewXY's LegendBox, the series gets highlighted.
I'm using WPF chart. I have several series that I'd like to highlight in the same time.
How can this be achieved?
LegendBox class has SeriesTitle* events. You can utilize it pretty much like this:
m_chart.BeginUpdate();
ViewXY viewXY = m_chart.ViewXY;
viewXY.XAxes[0].ValueType = AxisValueType.Number;
int seriesCount = 10;
//Create series that will highlight the other series
for (int i = 0; i < seriesCount; i++)
{
PointLineSeries s = new PointLineSeries(viewXY, viewXY.XAxes[0], viewXY.YAxes[0]);
s.LineStyle.Color = DefaultColors.SeriesForBlackBackgroundWpf[i];
s.Points = GenerateSomeRandomData((i+1) * 20);
s.Title.Text = "Series " + i.ToString();
viewXY.PointLineSeries.Add(s);
}
viewXY.LegendBox.MoveFromSeriesTitle = false;
viewXY.LegendBox.SeriesTitleMouseClick += LegendBox_SeriesTitleMouseClick;
viewXY.LegendBox.Layout = LegendBoxLayout.Vertical;
m_chart.EndUpdate();
and defining the event handler like this:
void LegendBox_SeriesTitleMouseClick(object sender, System.Windows.RoutedEventArgs e)
{
m_chart.BeginUpdate();
foreach (PointLineSeries s in m_chart.ViewXY.PointLineSeries)
{
s.SetHighlight();
//s.RemoveHighlight(); //To remove highlight, use this
}
m_chart.EndUpdate();
}
Then click on any series title, and all the series get highlighted. Based on series.MouseHighlight property setting, it changes to brighter thick line, animated color from bright to dark, or keeps original color.
Hopefully this helps :-)

If else condition on radio buttons

I was able to create buttons.I will be using about 65 buttons, how do you use if else condition on the buttons? Can someone please show me an example? Thank you in advance.
private void createButtons()
{
flowLayoutPanel1.Controls.Clear();
for(int i = 0;i <10;i++)
{
RadioButton b = new RadioButton();
b.Name = i.ToString();
b.Text = "radiobutton" + i.ToString();
b.AutoSize = true;
flowLayoutPanel1.Controls.Add(b);
}
}
How about putting the RadioButtons in a list or an array? This way you could use if (allRadioButtons[1].checked) {...}.
Here is an example
private List<RadioButton> allRadioButtons = new List<RadioButton>();
private void createButtons()
{
flowLayoutPanel1.Controls.Clear();
for (int i = 0; i < 10; i++)
{
RadioButton b = new RadioButton();
b.Name = i.ToString();
b.Text = "radiobutton" + i.ToString();
b.AutoSize = true;
flowLayoutPanel1.Controls.Add(b);
//add every button to the list
//the one with the Text radiobutton0 will be accessible as allRadioButtons[0]
//the one with the Text radiobutton1: allRadioButtons[1]
//etc
allRadioButtons.Add(b);
}
}
//you can use your list in any other method
private void myMethod() {
if (allRadioButtons[0].Checked)
{
//do something
}
}
If Andrea's answer didn't work for you (since you didn't mark it as a solution), another option would be to create a container, such as a GroupBox, and then add your programatically created RadioButton controls to this container. Then you can loop over the controls belonging to the GroupBox like this:
foreach (Control c in myGroupBox.Controls)
{
if ((RadioButton)c).Checked)
//Do something
}
This will loop over all the controls in the GroupBox and cast them to a RadioButton and check if they're checked or not. I've used something similar to this as the basis for quite a few requirements in different applications; it's very easy to make a recursive method that takes a ControlCollection, loop over it and apply logic as needed depending on some condition, like the type of control or perhaps the Tag value of the control.
Then as far as adding the RadioButtons to the GroupBox at run time you just do something like myGroupBox.Controls.Add(b) where b is the RadioButton you've created in your for loop in your sample code. More on runtime control creation here.

How to show multiple icons on winforms tabcontrol tab page?

I don't know if it is even possible, but maybe someone found a way to do this...
I have a tab control to which I allow the user to add tabs with a button click.
I want to show some icons on the tab so I added an ImageList, but I can show only one icon at a time, and I need to show at least 3 icons together.
I thought about having an image of 3 icons together, but the icons are shown after some actions the use do. For example: at first I show icon_1 and if the user clicks some where I add icon_2 etc...
Can someone come up with a way to do this ?
Thank you very much in advance...
No. It's not possible. Using the standard WinForms TabControl component you only can show one image at the same time.
The solution here, is using overlay icons. You have a base icon, and you add decorators. This is how Tortoise SVN, for example,
The following code builds an overlayed image in C#:
private static object mOverlayLock = new object();
public static Image GetOverlayedImage(Image baseImage, Image overlay)
{
Image im = null;
lock (mOverlayLock)
{
try
{
im = baseImage.Clone() as Image;
Graphics g = Graphics.FromImage(im);
g.DrawImage(overlay, 0, 0, im.Width, im.Height);
g.Dispose();
}
catch
{
// log your exception here
}
}
return im;
}
NOTE: The overlayed image must have the same size than the base image. It must have transparent color, and the decorator in the overlayed image must be placed in the right place, for example bottom-right or top-right.
I found this code:
private Bitmap CombineImages(params Image[] images)
{
int width = 0;
for (int i = 0; i < images.Length; i++)
width += images[i].Width + 3;
int height = 0;
for (int i = 0; i < images.Length; i++)
{
if (images[i].Height > height)
height = images[i].Height;
}
int nIndex = 0;
Bitmap fullImage = new Bitmap(width, height);
Graphics g = Graphics.FromImage(fullImage);
g.Clear(SystemColors.AppWorkspace);
foreach (Image img in images)
{
if (nIndex == 0)
{
g.DrawImage(img, new Point(0, 0));
nIndex++;
width = img.Width;
}
else
{
g.DrawImage(img, new Point(width, 0));
width += img.Width;
}
}
return fullImage;
//img3.Save(finalImage, System.Drawing.Imaging.ImageFormat.Jpeg);
//img3.Dispose();
//imageLocation.Image = Image.FromFile(finalImage);
}
from this link http://www.codeproject.com/Articles/502249/Combineplusseveralplusimagesplustoplusformplusaplu

Scroll to item in listview in Silverlight 3

I have a silverlight 3 app with a textbox on the main window and a childwindow that has a list of all the potential textbox values. When I open that childwindow I want it to scroll to the correct one in the list.
I'm trying to do this with the code below...using the ScrollIntoView. It was not working at all until I add the UpdateLayerout(). However it does not seem to work all the time. At times it scrolls but not all the way to the item, it is a few items higher than it should be. The listbox is in an Accordion and the list items use a ItemTemplate\DataTemplate, not sure if that effects anything but thought I'd mention it.
Any ideas what I'm missing in the code below?
What I would like is to scroll the item to the top of the list ....any ideas how to that?
(Or any other suggestions on how to code this better)
Thanks!
for (int index = 0; index < myList.Items.Count; index++) {
object obj = myList.Items[index];
var listItem= obj as listItemObject;
if (listItemObj != null) {
if (string.Compare(listItemObj.id, _PastedInId, StringComparison.InvariantCultureIgnoreCase) == 0) {
selectThisIndex = index;
scrollToThisItem = obj;
}
}
}
myList.SelectedIndex = selectThisIndex;
if (scrollToThisItem != null){
myList.UpdateLayout();
myList.ScrollIntoView(scrollToThisItem);
}
Consider using the ItemsControlExtensions implementation from the Silverlight Toolkit, available at http://silverlight.codeplex.com/sourcecontrol/network/Show?projectName=Silverlight&changeSetId=47051#637494
This has a ScrollIntoView(FrameworkElement element) method that may help.

Resources