asp.net chart control value label position - asp.net

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";

Related

Table header column background color not changing

I am using ASPOSE Slides in my project to perform a PPT task. I want to change my table header background-color but I have not found any solutions in Aspose forum for it. Can anybody provide me with the solution?
ISlide sld = press.Slides[0];
double[] dblCols = { 250, 250};
double[] dblRows = { 70, 70, 70,70 };
// Add table shape to slide
ITable tbl = sld.Shapes.AddTable(100, 100, dblCols, dblRows);
tbl[0, 1].TextFrame.Text = "some text";
tbl[0, 2].TextFrame.Text = "some text";
tbl[0, 3].TextFrame.Text = "some text";
tbl[0, 3].BorderBottom.FillFormat.FillType = FillType.Solid;
tbl[0, 3].FillFormat.SolidFillColor.BackgroundColor = Color.Blue;
tbl[0,3].BorderBottom.Width = 2;
Portion portion = (Portion)tbl[0, 1].TextFrame.Paragraphs[0].Portions[0];
portion.PortionFormat.FillFormat.FillType = FillType.Solid;
portion.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
}
I have observed you requirements related to setting table header background. Please try using following sample code that has example of setting fill color for one of header row cell. You can replicate the same for other cells too.
public static void TestTableBackground()
{
Presentation press = new Presentation();
ISlide sld = press.Slides[0];
double[] dblCols = { 250, 250 };
double[] dblRows = { 70, 70, 70, 70 };
// Add table shape to slide
ITable tbl = sld.Shapes.AddTable(100, 100, dblCols, dblRows);
tbl[0, 1].TextFrame.Text = "some text";
tbl[0, 2].TextFrame.Text = "some text";
tbl[0, 3].TextFrame.Text = "some text";
tbl[0, 0].FillFormat.FillType = FillType.Solid;
tbl[0, 0].FillFormat.SolidFillColor.Color = Color.Blue;
Portion portion = (Portion)tbl[0, 1].TextFrame.Paragraphs[0].Portions[0];
portion.PortionFormat.FillFormat.FillType = FillType.Solid;
portion.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
press.Save(#"C:\Aspose Data\TableFormat.pptx", Aspose.Slides.Export.SaveFormat.Pptx);
}
I am working as Support developer/ Evangelist at Aspose.

jFreeChart: How to hide the legend?

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])));
}

xamarin core plot y-axis value

Hello guys I have a problem with core plot in xamarin. I managed to create a graph like below:
click here for the graph
I'm using this code:
/// <summary>
/// Configure the Axes of the graph
/// </summary>
void SetupAxes()
{
var plotspace = _graph.DefaultPlotSpace;
plotspace.AllowsUserInteraction = true;
var axisSet = (CPTXYAxisSet)_graph.AxisSet;
// Label x with a fixed interval policy
var x = axisSet.XAxis;
x.LabelingPolicy = CPTAxisLabelingPolicy.None;
x.Title = "X Axis";
x.TitleOffset = 0;
x.MinorTickLength = 5f;
x.MajorTickLength = 7f;
x.LabelOffset = 3;
x.MajorIntervalLength = 5;
x.MinorTicksPerInterval = 4;
// Label y with an automatic label policy.
var y = axisSet.YAxis;
y.LabelingPolicy = CPTAxisLabelingPolicy.None;
y.LabelOffset = 0;
y.Title = "Y Axis";
y.TitleOffset = 0;
y.MinorTickLength = 5f;
y.MajorTickLength = 7f;
y.LabelOffset = 3;
y.MajorIntervalLength = 5;
y.MinorTicksPerInterval = 4;
}
/// <summary>
/// Set up data source and configure plots
/// </summary>
void SetupBarPlots(List<float> inputSocket)
{
var barPlot = new CPTBarPlot
{
DataSource = new BarSourceData(inputSocket),
BaseValue = 0,
BarOffset = (NSDecimal)(-0.25),
Identifier = (NSString)"Bar Plot 1"
};
_graph.AddPlot(barPlot);
barPlot.Fill = new CPTFill(CPTColor.BrownColor);
_graph.AddPlot(barPlot, _graph.DefaultPlotSpace);
var space = _graph.DefaultPlotSpace as CPTXYPlotSpace;
space.ScaleToFitPlots(new CPTPlot[] { barPlot });
//get the highest value in the input data
var yMax = (decimal)inputSocket.Max();
decimal newYMax = yMax*2;
space.YRange = new CPTPlotRange(-20, new NSDecimalNumber(newYMax.ToString()).NSDecimalValue);
decimal newXMax = (decimal)space.XRange.MaxLimit + 2;
decimal newXMin = (decimal)space.XRange.MinLimit - 1;
space.XRange = new CPTPlotRange(new NSDecimalNumber(newXMin.ToString()).NSDecimalValue,
new NSDecimalNumber(newXMax.ToString()).NSDecimalValue);
//RectangleF(position x, position y, width, height
//AddSubview = adding a view on top of a View
_view.AddSubview(new CPTGraphHostingView(new RectangleF(20, 320, 662, 320))
{
HostedGraph = _graph
});
}
I want to show y value in the graph (red square in the image) so it could look like a proper graph. Anyone has an experience how to create graph using Xamarin/monotouch? There is not quite a lot of xamarin tutorial for core plot. Thanks before :)
Turns out I have to set labellingPolicy to Automatic. See below:
y.LabelingPolicy = CPTAxisLabelingPolicy.Automatic;
Then it will set the y axis value based on the data.

Can't Adjust Chart Margin

I created a Chart but it has a left margin between the Y.Axis and the Chart's border.
How can I make it 0?
And is it possible to define a 5px uniform margin (left, top, right, bottom) between the chart and the border?
My Chart code is the following:
Chart chart = new Chart {
AntiAliasing = AntiAliasingStyles.All,
TextAntiAliasingQuality = TextAntiAliasingQuality.High,
BackColor = Color.FromArgb(250, 250, 250),
Height = size.Height,
Width = size.Width
};
chart.Legends.Clear();
ChartArea area = new ChartArea {
BackColor = Color.Transparent,
BorderColor = Color.FromArgb(240, 240, 240),
BorderWidth = 1,
BorderDashStyle = ChartDashStyle.Solid,
AxisX = new Axis {
Enabled = AxisEnabled.True,
IntervalAutoMode = IntervalAutoMode.VariableCount,
IsLabelAutoFit = true,
IsMarginVisible = true,
LabelStyle = new LabelStyle { ForeColor = Color.FromArgb(100, 100, 100), Font = new Font("Arial", 10, FontStyle.Regular) },
LineColor = Color.FromArgb(220, 220, 220),
MajorGrid = new Grid { LineColor = Color.FromArgb(240, 240, 240), LineDashStyle = ChartDashStyle.Solid },
MajorTickMark = new TickMark { LineColor = Color.FromArgb(220, 220, 220), Size = 4.0f },
},
AxisY = new Axis {
Enabled = AxisEnabled.True,
IntervalAutoMode = IntervalAutoMode.VariableCount,
IsLabelAutoFit = true,
IsMarginVisible = true,
LabelStyle = new LabelStyle { ForeColor = Color.FromArgb(100, 100, 100), Font = new Font("Arial", 10, FontStyle.Regular) },
LineColor = Color.Transparent,
MajorGrid = new Grid { LineColor = Color.FromArgb(240, 240, 240), LineDashStyle = ChartDashStyle.Solid },
MajorTickMark = new TickMark { LineColor = Color.FromArgb(240, 240, 240), Size = 2.0f }
},
Position = new ElementPosition { Height = 100, Width = 100, X = 0, Y = 0 }
};
chart.ChartAreas.Add(area);
area.AxisX.LabelStyle.Format = "H:mm";
area.AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Hours;
Series series = new Series {
CustomProperties = "PointWidth = 1",
IsXValueIndexed = true,
XValueType = (ChartValueType)Enum.Parse(typeof(ChartValueType), x.Data.GetType().GetGenericArguments()[0].Name)
};
series.BorderWidth = 2;
series.BorderColor = Color.FromArgb(84, 164, 232);
series.ChartType = SeriesChartType.Area;
series.Color = Color.FromArgb(222, 234, 244);
series.Points.DataBindXY(x.Data, s.Data);
chart.Series.Add(series);
Thank You,
Miguel
You can remove the axis margin with Axis.IsMarginVisible = false.
You can position your charting areas using ChartArea.Position or position the plotting area using ChartArea.InnerPlotPosition

Adding text , image to asp.net chart control

I am using asp.net chart control to display chart on my website , below is the snippet of it:
The issue is i want to add the text and an arrow line on each point , so for instance on the point (60,october) I want to write text at this point: projection was highest and an arrow image.
Is it possible to acheive something like this, any suggestion or assistance will be highly appreciated, below is the code i have used to generate this chart:
double[] yValues = { 15, 60, 12, 13 };
string[] xValues = { "September", "October", "November", "December" };
chart.Width = 500;
chart.Height = 200;
chart.BorderSkin.SkinStyle = BorderSkinStyle.FrameThin1;
ChartArea ca = new ChartArea();
ca.Name = "Default";
ca.AxisX.LineColor = System.Drawing.ColorTranslator.FromHtml("#FEFEFE");
ca.AxisX.LineWidth = 3;
ca.AxisX.MajorGrid.LineDashStyle = ChartDashStyle.Dash;
ca.AxisX.MajorGrid.Enabled = false;
ca.AxisX.MajorTickMark.LineWidth = 2;
ca.AxisX.LabelStyle.Format = "L";
ca.AxisY.LineColor = System.Drawing.ColorTranslator.FromHtml("#FEFEFE");
ca.AxisY.LineWidth = 3;
ca.AxisY.MajorGrid.Enabled = true;
ca.AxisY.MajorTickMark.LineWidth = 2;
ca.AxisY.Title = "yaxis";
chart.ChartAreas.Add(ca);
Legend legend = new Legend();
chart.Legends.Add(legend);
Series series = new Series("Series1");
series.IsValueShownAsLabel = false;
series.MarkerStyle = MarkerStyle.Circle;
series.BorderWidth = 5;
series.ChartType = SeriesChartType.Line;
series.ShadowOffset = 2;
series.XValueType = ChartValueType.String;
series.YValueType = ChartValueType.Double;
series.Font = new System.Drawing.Font("Trebuchet MS", 8);
series.BorderColor = System.Drawing.ColorTranslator.FromHtml("#33CCFF");
series.Color = System.Drawing.ColorTranslator.FromHtml("#33CCFF");
chart.Series.Add(series);
chart.Series["Series1"].Points.DataBindXY(xValues, yValues);
chart.DataManipulator.InsertEmptyPoints(1, System.Web.UI.DataVisualization.Charting.IntervalType.Days, "Series1");
You need to search for the largest data point and use property
datapoint.Label = "projection was highest";
Also easiest way to highlight the point is to use datapoint.MarkerStyle property. You can draw an arrow but I dont think its worth the hassle.

Resources