jFreeChart: How to hide the legend? - plot

I tried "LegendTitle", but it's not working. How I can hide the legend?
I have two graphic in one: CategoryPlot and
JFreeChart chart = ChartFactory.createStackedBarChart(res.getString("bar_chart.title"),
res.getString("bar_chart.sections.title"),
MessageFormat.format(res.getString("bar_chart.duration.title"),
res.getString("bar_chart.length.unit"),
"DM_ACTIVITY",
"activity_duration"),
dsTime);
CategoryPlot plot = chart.getCategoryPlot();
plot.setDataset(1, dsLength);
plot.mapDatasetToRangeAxis(1, 1);
plot.setRangeAxis(1, new NumberAxis(
MessageFormat.format(res.getString("bar_chart.length.title"),
dataContext.getUnitLabel(dataContext.getOverrideUnitSysId(),
"CD_HOLE_SECT_GROUP", "md_hole_sect_top"))
));
StackedBarRenderer barRenderer = (StackedBarRenderer) plot.getRenderer(0);
barRenderer.setBarPainter(new StandardBarPainter());
LineAndShapeRenderer shapeRenderer = new LineAndShapeRenderer();
shapeRenderer.setSeriesShape(0, new Rectangle.Float(-10, -10, 20, 20));
shapeRenderer.setLegendShape(0, new Rectangle.Float(-5, -5, 10, 10));
shapeRenderer.setBasePaint(Color.red);
shapeRenderer.setSeriesPaint(0, Color.red);
shapeRenderer.setBaseOutlinePaint(Color.white);
shapeRenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
plot.setRenderer(1, shapeRenderer);
plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
LegendTitle legend1 = new LegendTitle(shapeRenderer);
legend1.setVisible(false);
for (int i = 0; i < TIME_NONE; i++) {
plot.getRenderer().setSeriesPaint(i, Color.decode("#" + res.getString("color." + keys[i])));
}

Related

EPPlus few chart in loop

How add a few chart in loop .
I try this but I have only one:
for (int x = 1; x < 5; x++)
{
var chart = worksheet.Drawings.AddChart(zaklad, OfficeOpenXml.Drawing.Chart.eChartType.ColumnClustered);
chart.Title.Text = "Total";
chart.SetPosition(wiersz, 14, wiersz * x, 25);
chart.SetSize(100, 100*x);
worksheet.Cells[wiersz, 14, wiersz + 1, 25].Style.Fill.PatternType = ExcelFillStyle.Solid;
ExcelAddress valueAddress = new ExcelAddress(wiersz, 14 , wiersz + 1, 25);
chart.Legend.Border.LineStyle = eLineStyle.Solid;
chart.Legend.Border.Fill.Style = eFillStyle.SolidFill;
chart.Legend.Border.Fill.Color = Color.DarkBlue;
}
My guess is you're drawing the last one (and the biggest according to your code) above the others.
Try the following:
// left, top, width, height
chart.SetPosition(0, 0, 100 * x, 100);
chart.SetSize(100, 100);

Xamarin.Forms: Putting A Label Inside A BarChart Layout

I am using oxyplot to plot a bar chart. I wish to add an extra label in the chart. I've tried to use Textannotation but it's not showing on the chart. What is the mistake I'm making to cause the text not to appear, is it the DataPoint? Please help.
plotModel = new PlotModel
{
Title = "Daily",
LegendPlacement = LegendPlacement.Outside,
LegendPosition = LegendPosition.BottomCenter,
LegendOrientation = LegendOrientation.Horizontal,
LegendBorderThickness = 0
};
TextAnnotation txtlabel = new TextAnnotation();
txtlabel.Text = "Test";
txtlabel.TextColor = OxyColors.Red;
txtlabel.Stroke = OxyColors.Red;
txtlabel.StrokeThickness = 5;
txtlabel.FontSize = 36;
txtlabel.TextPosition = new DataPoint(21, 3.5);
plotModel.Annotations.Add(txtlabel);
string sPrevType = "";
string sCurrentType = "";
DateTime dtdate;
var sr = new ColumnSeries();
var col = new ColumnItem();
int iCount = 0;
List<decimal> lstI = new List<decimal>();
List<decimal> lstD = new List<decimal>();
List<decimal> lstS = new List<decimal>();
foreach (var itm in _dateodr)
{
dtdate = itm.date;
sCurrentType = itm.Type;
lstI.Add(itm.I_Unit);
lstD.Add(itm.D_Unit);
lstS.Add(itm.S_Unit);
if (sCurrentType != sPrevType && sPrevType != "")
{
sr = new ColumnSeries();
sr.Title = sPrevType;
sr.LabelPlacement = LabelPlacement.Outside;
sr.StrokeColor = OxyColors.Black;
sr.StrokeThickness = 1;
//sr.LabelFormatString = "{0:#,##0.00}";
plotModel.Series.Add(sr);
}
sPrevType = sCurrentType;
iCount += 1;
}
if (iCount == _dateodr.Count)
{
sr = new ColumnSeries();
sr.Title = sPrevType;
sr.LabelPlacement = LabelPlacement.Outside;
sr.StrokeColor = OxyColors.Black;
sr.StrokeThickness = 1;
//sr.LabelFormatString = "{0:#,##0.00}";
sr.FontSize = 10;
plotModel.Series.Add(sr);
}
for (int i = 0; i < iCount; i++)
{
ColumnSeries ssr = (ColumnSeries)plotModel.Series[i];
var colIm = new ColumnItem();
colIitm.Value = double.Parse(lstI[i].ToString()) / 1000;
ssr.Items.Add(colIitm);
var colDOitm = new ColumnItem();
colDitm.Value = double.Parse(lstD[i].ToString()) / 1000;
ssr.Items.Add(colDitm);
var colSitm = new ColumnItem();
colSitm.Value = double.Parse(lstS[i].ToString()) / 1000;
ssr.Items.Add(colSitm);
}
categoryaxis.Labels.Add("I");
categoryaxis.Labels.Add("Dr");
categoryaxis.Labels.Add("Sr");
switch (sUnitType)
{
case "2":
valueAxis = new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, MaximumPadding = 0.06, AbsoluteMinimum = 0, Title = "m", Angle = 90, FontWeight = FontWeights.Bold, FontSize = 15 };
break;
case "qy":
valueAxis = new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, MaximumPadding = 0.06, AbsoluteMinimum = 0, Title = "Qy", Angle = 90, FontWeight = FontWeights.Bold, FontSize = 15 };
break;
case "Am":
valueAxis = new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, MaximumPadding = 0.06, AbsoluteMinimum = 0, Title = "Am", Angle = 90, FontWeight = FontWeights.Bold, FontSize = 15 };
break;
}
plotModel.Axes.Add(categoryaxis);
plotModel.Axes.Add(valueAxis);
}
PlotView plot = new PlotView
{
VerticalOptions = LayoutOptions.Fill,
HorizontalOptions = LayoutOptions.Fill,
BackgroundColor = Color.White,
Model = plotModel
};
Content = plot;

how to create radiobutton list using itextsharp in c#

i am trying to make radiobutton list in pdf file using itextsharp but it create box.
Is there anyone can say me why this is happening ?
for (int j = 0; j < 8; j++)
{
Rectangle(0, 0, 22, 22), "RadioButtons_" + j.ToString(), "On");
Rectangle _rect;
_rect = new Rectangle(100, 100, 100, 100);
radios[j] = new RadioCheckField(writer, _rect, "RadioButtons_" + j.ToString(), "On");
radios[j].BackgroundColor = new GrayColor(0.8f);
radios[j].BorderColor = GrayColor.BLACK;
radios[j].CheckType = RadioCheckField.TYPE_CIRCLE;
cell = new PdfPCell();
if (j == 6)
{
cell.Colspan = 3;
radios[j].Text = " Not Important";
}
else if (j == 7)
{
cell.Colspan = 3;
radios[j].Text = "Not Applicable";
}
else
{
cell.Colspan = 1;
}
kid = new iTextSharp.text.pdf.events.FieldPositioningEvents(writer, radios[j].CheckField, "radios");
kid.Padding = 0.5f;
cell.CellEvent = kid;
table.AddCell(cell);
}

asp.net chart control value label position

I am displaying data in asp.net chart control. Using a 3d bar chart. I am showing the values next to the bars. (seriesCount.IsValueShownAsLabel = true;). The chart control is rendering the value label still on top of the bar and is making the value hard to read. I am trying to position this label to the right but so far I've found no way to do it. I've also tried enabling Smart labels hoping and putting a marker on the bar to push the value away but I haven't been successful. Any suggestions are appreciated.
Sample code:
Chart chartSubjects = new Chart();
chartSubjects.Width = Unit.Pixel(800);
chartSubjects.Height = Unit.Pixel(300);
chartSubjects.AntiAliasing = AntiAliasingStyles.All;
Series seriesCount = new Series("subjectsCountSeries");
seriesCount.YValueType = ChartValueType.Int32;
seriesCount.ChartType = SeriesChartType.Bar;
seriesCount.IsValueShownAsLabel = true;
seriesCount.ChartArea = "subjectsCountArea";
chartSubjects.Series.Add(seriesCount);
ChartArea areaCount = new ChartArea("subjectsCountArea");
LabelStyle yAxisStyle = new LabelStyle();
yAxisStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#444444");
yAxisStyle.Font = new System.Drawing.Font("Arial", 11, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
areaCount.AxisY.LabelStyle = yAxisStyle;
areaCount.AxisY.IsLabelAutoFit = false;
areaCount.Position.Width = 50;
areaCount.Position.Height = 100;
areaCount.Position.X = 0;
areaCount.Position.Y = 0;
areaCount.Area3DStyle.Enable3D = true;
areaCount.Area3DStyle.LightStyle = LightStyle.Realistic;
areaCount.Area3DStyle.WallWidth = 4;
areaCount.Area3DStyle.Inclination = 10;
areaCount.Area3DStyle.Perspective = 10;
areaCount.Area3DStyle.Rotation = 20;
areaCount.Area3DStyle.PointDepth = 90;
chartSubjects.ChartAreas.Add(areaCount);
int[] pointsToAdd = new int[] { 1434, 712, 601, 204, 173, 168, 64, 35, 22, 8, 2 };
foreach (int point in pointsToAdd)
{
DataPoint dataPoint = new DataPoint();
dataPoint.SetValueY(point);
seriesCount.Points.Add(dataPoint);
}
Is this what you are looking for?
<asp:Series Name="Series1" ChartType="Bar"
CustomProperties="BarLabelStyle=Right" IsValueShownAsLabel="True"
Palette="EarthTones" XValueMember="xvalue" YValueMembers="yvalue">
</asp:Series>
CustomProperties="BarLabelStyle=Right" did it for me.
In your case I'd use:
chartSubjects.Series["seriesCount"]["LabelStyle"] = "Right";

ZedGraph labels

In ZedGraph, how do I show text labels for each point and in the XAxis all together?
If I do
myPane.XAxis.Type = AxisType.Text;
myPane.XAxis.Scale.TextLabels = array_of_string;
I get labels on the XAxis like this
And if I do
for (int i = 0; i < myCurve.Points.Count; i++)
{
PointPair pt = myCurve.Points[i];
// Create a text label from the Y data value
TextObj text = new TextObj(
pt.Y.ToString("f0"), pt.X, pt.Y + 0.1,
CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
text.ZOrder = ZOrder.A_InFront;
text.FontSpec.Angle = 0;
myPane.GraphObjList.Add(text);
}
I get labels on the curve, like this
But if I do both at the same time, labels on the curve disappear.
Is there a way to combine both kind of labels?
I've changed my answer after you clarified the question.
You just have to remember to position the labels correctly:
<%
System.Collections.Generic.List<ZedGraphWebPointPair> points = new System.Collections.Generic.List<ZedGraphWebPointPair>();
for (int i = 0; i < 15; i++)
{
// Let's have some fun with maths
points.Add(new ZedGraphWebPointPair
{
X = i,
Y = Math.Pow(i - 10, 2) * -1 + 120
});
}
System.Collections.Generic.List<string> XAxisLabels = new System.Collections.Generic.List<string>();
TestGraph.CurveList.Add(new ZedGraphWebLineItem { Color = System.Drawing.Color.Red });
TestGraph.XAxis.Scale.FontSpec.Size = 9;
int j = 1;
foreach (ZedGraphWebPointPair point in points)
{
// Add the points we calculated
TestGraph.CurveList[0].Points.Add(point);
// Add the labels for the points
TestGraph.GraphObjList.Add(new ZedGraphWebTextObj
{
Location =
{
CoordinateFrame = ZedGraph.CoordType.XChartFractionYScale,
// Make sure we position them according to the CoordinateFrame
X = Convert.ToSingle(j) / points.Count - 0.05f,
Y = Convert.ToSingle(point.Y) + 3f,
AlignV = ZedGraph.AlignV.Top
},
Text = point.Y.ToString(),
FontSpec = { Angle = 90, Size = 9, Border = { IsVisible = false } }
});
// Add the labels for the XAxis
XAxisLabels.Add(String.Format("P{0}", j));
j++;
}
TestGraph.RenderGraph += delegate(ZedGraphWeb zgw, System.Drawing.Graphics g, ZedGraph.MasterPane mp)
{
ZedGraph.GraphPane gp = mp[0];
gp.XAxis.Type = ZedGraph.AxisType.Text;
gp.XAxis.Scale.TextLabels = XAxisLabels.ToArray();
};
%>
That code will produce this graph:
If the axis type is text, the code below is easier to get x-coordinates of the points ;)
for (int tPoint = 0; tPoint < curve.Points.Count; tPoint++)
{
TextObj text = new TextObj(curve.Points[tPoint].Y.ToString(), curve.Points[tPoint].X, curve.Points[tPoint].Y + 10);
}

Resources