How can i display chart from code behind in windows phone - c#

I create a chart in my windows phone app.this is my code XAML
<amq:SerialChart x:Name="line" DataSource="{Binding results}" CategoryValueMemberPath="month"
AxisForeground="White"
PlotAreaBackground="Black"
GridStroke="DarkGray" >
<amq:SerialChart.Graphs>
<amq:LineGraph Title="Sales" ValueMemberPath="actual" Brush="red" StrokeThickness="5" />
</amq:SerialChart.Graphs>
</amq:SerialChart>
How can i write this XAML with c# (code behind only)

How can i write this XAML with c# (code behind only)
In general this is usually not a good idea. But if you must, you would use something along these lines:
var chart = new SerialChart
{
CategoryValueMemberPath = "month",
AxisForeground = new SolidColorBrush(Colors.White),
PlotAreaBackground = new SolidColorBrush(Colors.Black),
GridStroke = new SolidColorBrush(Colors.DarkGray)
};
chart.SetBinding(SerialChart.DataSourceProperty, new Binding("results"));
var lineGraph = new LineGraph
{
Title = "Sales",
ValueMemberPath = "actual",
Brush = new SolidColorBrush(Colors.Red),
StrokeThickness = "5"
};
chart.Graphs.Add(lineGraph);
Then you would just need to add the chart to the page/container using for example stackPanel.Children.Add(chart).

var chart = new SerialChart
{
CategoryValueMemberPath = "month",
AxisForeground = new SolidColorBrush(Colors.White),
PlotAreaBackground = new SolidColorBrush(Colors.Black),
GridStroke = new SolidColorBrush(Colors.DarkGray)
};
chart.SetValue(SerialChart.DataSourceProperty, new Binding("results"));
var lineGraph = new LineGraph
{
Title = "Sales",
ValueMemberPath = "actual",
Brush = new SolidColorBrush(Colors.Red),
StrokeThickness = 5
};
chart.Graphs.Add(lineGraph);

Related

How can i disable series animation in highchart tree map?

I wrote the following code to disable the series animation :
Animation = new Animation{Enabled = false},
But after runing my application , the problem still persists.
My code to display the treemap is as follows:
#{ var chartOptions =
new Highcharts
{
Title = new Title
{
Text = ""
},
Credits = new Credits
{
Enabled = false
},
Series = new List<Series>
{
new TreemapSeries
{
Animation = new Animation{Enabled = false},
LayoutAlgorithm = TreemapSeriesLayoutAlgorithm.Squarified,
AlternateStartingDirection = true,
Levels = new List<TreemapSeriesLevels>
{
new TreemapSeriesLevels
{
Level = 1,
LayoutAlgorithm = TreemapSeriesLevelsLayoutAlgorithm.Squarified,
DataLabels = new TreemapSeriesDataLabels()
{
Enabled = true,
Align = TreemapSeriesDataLabelsAlign.Left,
VerticalAlign = TreemapSeriesDataLabelsVerticalAlign.Top
}
}
},
Data = #ViewBag.resultGreen
,
}
}
};
chartOptions.ID = "chart";
chartOptions.PlotOptions.Series.Animation.Enabled = false;
var renderer = new HighchartsRenderer(chartOptions);
}
#Html.Raw(renderer.RenderHtml())
How can i solve this problems?
I tried to solve this problem by the link below:
How to disable animations on Highcharts Dotnet C# MVC?
The provided answer in the mentioned thread looks to be related to DotNet.Highcharts. If you use the official Highcharts .NET wrapper use the AnimationBool option:
new TreemapSeries
{
AnimationBool = false,
...
}
API Reference:
https://dotnet.highcharts.com/Help/Highcharts/html/class_highsoft_1_1_web_1_1_mvc_1_1_charts_1_1_treemap_series.html#a3b53a65560c6917e7ee52e1779335b2e

UWP equivalent of Android's SpannableString with image inside

Is there a way to implement an image within a TextBlock rather than outside of it? Android has a feature called SpaanableStringBuilder which allows the user to create text with different appearances. Does UWP have something similar?
MyTextBlock.Text = "Google" + ? + "icon";
As Raymond said, in UWP, RichTextBlock is needed for image and text mixing.
With Xaml
<RichTextBlock>
<Paragraph>
<Run Text="Something..."/>
<InlineUIContainer>
<Image Source="your_image_url" Width="20" Height="20"/>
</InlineUIContainer>
<Run Text="Something..."/>
</Paragraph>
</RichTextBlock>
With Code
var richTextBlock = new RichTextBlock();
var para = new Paragraph();
para.Inlines.Add(new Run() { Text = "Something..." });
var imgContainer = new InlineUIContainer();
var img = new Image();
img.Source = new BitmapImage(new Uri("your_image_url"));
imgContainer.Child = img;
para.Inlines.Add(imgContainer);
para.Inlines.Add(new Run() { Text = "Something..." });
richTextBlock.Blocks.Add(para);
Or you could write it this way, which more closely mirrors the XAML.
var richTextBlock = new RichTextBlock()
{
Blocks = {
new Paragraph {
Inlines = {
new Run { Text = "Something" },
new InlineUIContainer {
Child = new Image {
Source = new BitmapImage(new Uri("your_image_url"))
}
},
new Run { Text = "Something..."}
}
}
}
};

NoTextEdit ShapeLock is not working - OpenXML SDK

I am trying to make a TextBox locked by using OpenXML SDK. I've tried this method but the TextBox NoTextEdit is not working.
public DocumentFormat.OpenXml.Presentation.Shape GenerateShape(string StrText)
{
DocumentFormat.OpenXml.Presentation.Shape shape1 = new DocumentFormat.OpenXml.Presentation.Shape();
DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties nonVisualShapeProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties();
DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties nonVisualDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties() { Id = (UInt32Value)3U, Name = "ID",Hidden=true ,Description="Do not Remove" ,MCAttributes=null };
DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties nonVisualShapeDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties();
Drawing.ShapeLocks shapeLocks1 = new Drawing.ShapeLocks() { NoTextEdit = true, NoGrouping = true,NoMove=true,NoSelection=true,NoEditPoints=true ,NoAdjustHandles=true ,NoRotation=true,NoChangeArrowheads=true,NoChangeAspect=true,NoChangeShapeType=true,NoResize=true};
nonVisualShapeDrawingProperties1.Append(shapeLocks1);
ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties1 = new ApplicationNonVisualDrawingProperties();
PlaceholderShape placeholderShape1 = new PlaceholderShape() { Type = PlaceholderValues.SubTitle, Index = (UInt32Value)1U };
applicationNonVisualDrawingProperties1.Append(placeholderShape1);
nonVisualShapeProperties1.Append(nonVisualDrawingProperties1);
nonVisualShapeProperties1.Append(nonVisualShapeDrawingProperties1);
nonVisualShapeProperties1.Append(applicationNonVisualDrawingProperties1);
DocumentFormat.OpenXml.Presentation.ShapeProperties shapeProperties1 = new DocumentFormat.OpenXml.Presentation.ShapeProperties();
DocumentFormat.OpenXml.Presentation.TextBody textBody1 = new DocumentFormat.OpenXml.Presentation.TextBody();
Drawing.BodyProperties bodyProperties1 = new Drawing.BodyProperties();
Drawing.ListStyle listStyle1 = new Drawing.ListStyle();
Drawing.TextShape shp = new Drawing.TextShape();
Drawing.Paragraph paragraph1 = new Drawing.Paragraph();
Drawing.EndParagraphRunProperties endParagraphRunProperties1 = new Drawing.EndParagraphRunProperties() { Language = "en-US" ,Dirty=false };
paragraph1.Append(GenerateRun(StrText));
paragraph1.Append(endParagraphRunProperties1);
textBody1.Append(bodyProperties1);
textBody1.Append(listStyle1);
textBody1.Append(paragraph1);
shape1.Append(nonVisualShapeProperties1);
shape1.Append(shapeProperties1);
shape1.Append(textBody1);
return shape1;
}
public Drawing.Run GenerateRun(string StrText)
{
Drawing.Run run1 = new Drawing.Run();
Drawing.RunProperties runProperties1 = new Drawing.RunProperties() { Language = "en-US", Dirty = false };
runProperties1.SetAttribute(new OpenXmlAttribute("", "smtClean", "", "0"));
Drawing.Text text1 = new Drawing.Text();
text1.Text = StrText;
Drawing.SolidFill solidFill2 = new Drawing.SolidFill();
Drawing.SchemeColor schemeColor = new Drawing.SchemeColor();
string y = System.Drawing.Color.Transparent.ToArgb().ToString("X");
Drawing.RgbColorModelHex rgbColorModelHex2 = new Drawing.RgbColorModelHex() { Val = "FFFFFF" };//Set Font-Color to Blue (Hex "0070C0").
solidFill2.Append(rgbColorModelHex2);
runProperties1.Append(solidFill2);
Color color = new Color() { Val = "365F91", ThemeColor = ThemeColorValues.Accent1, ThemeShade = "BF" };
run1.Append(runProperties1);
run1.Append(text1);
return run1;
}
Everything works fine except editing. Still the user can edit the TextBox values by double clicking it. How can I avoid this ?
Is there any permanent solution to prevent editing ? Please help me to find a better solution.
Thanks in advance
By researching and communications with the MVP team I've pointed out that there is no way to Protect the TextBox from editing.
As Cindy Meister mentioned in the comments,
Are you able to do it in the PowerPoint application user interface? If not, then Open XML cannot do it... If yes, you can.
If you do not want to text to be changed , Just change it as image then lock that by using NoSelection=true/1 and NoMove=true/1 properties. If you enable these properties the user can't either delete nor change it's position.
For your ref: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_powerpoint-mso_windows8-mso_2016/shape-lock-is-not-working/c1705b55-d2aa-4adb-b538-574ed2fc8eca?tm=1579265435636&page=1&rtAction=1579495439869

WPF TabItem Style screws up the control positions

I created a new TabItem Style which looks the way I wanted. But now it screws up the positions of all the controls which are placed on the TabItem. It moves them from the top left area to the right bottom area of the TabItem. Any help would be highly appreciated. (Yes, I am sure I need the style in C# NOT in XAML)
var functionReturnValue = new Style();
ControlTemplate L_NewControlTemplate = new ControlTemplate(typeof(TabItem));
FrameworkElementFactory L_ElemFactory = new FrameworkElementFactory(typeof(Border));
L_ElemFactory.SetBinding(Border.FocusVisualStyleProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("FocusVisualStyle") });
L_ElemFactory.SetBinding(Border.BackgroundProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("Background") });
L_ElemFactory.SetBinding(Border.BorderBrushProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("BorderBrush") });
L_ElemFactory.SetBinding(Border.BorderThicknessProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("BorderThickness") });
//L_ElemFactory.SetValue(Border.CornerRadiusProperty, new CornerRadius(0,12,0,0));
L_ElemFactory.SetValue(Border.SnapsToDevicePixelsProperty, true);
FrameworkElementFactory L_ContentPresenter = new FrameworkElementFactory(typeof(ContentPresenter));
L_ContentPresenter.SetValue(ContentPresenter.ContentSourceProperty, "Header");
L_ContentPresenter.SetBinding(ContentPresenter.HorizontalAlignmentProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("HorizontalContentAlignment") });
L_ContentPresenter.SetBinding(ContentPresenter.VerticalAlignmentProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("VerticalContentAlignment") });
L_ContentPresenter.SetBinding(ContentPresenter.SnapsToDevicePixelsProperty, new System.Windows.Data.Binding { RelativeSource = System.Windows.Data.RelativeSource.TemplatedParent, Path = new PropertyPath("SnapsToDevicePixels") });
L_ElemFactory.AppendChild(L_ContentPresenter);
L_NewControlTemplate.VisualTree = L_ElemFactory;
Trigger NewTrigger;
//Trigger IsEnabled = true
NewTrigger = new Trigger { Property = TabItem.IsEnabledProperty, Value = true };
NewTrigger.Setters.Add(new Setter(TabItem.ForegroundProperty, F_Foreround));
NewTrigger.Setters.Add(new Setter(TabItem.BackgroundProperty, F_Background));
L_NewControlTemplate.Triggers.Add(NewTrigger);
//Trigger MouseOver
NewTrigger = new Trigger { Property = TabItem.IsMouseOverProperty, Value = true };
NewTrigger.Setters.Add(new Setter(TabItem.ForegroundProperty, F_Foreround));
NewTrigger.Setters.Add(new Setter(TabItem.BackgroundProperty, F_MouseOver));
L_NewControlTemplate.Triggers.Add(NewTrigger);
//Trigger Selected
NewTrigger = new Trigger { Property = TabItem.IsSelectedProperty, Value = true };
NewTrigger.Setters.Add(new Setter(TabItem.ForegroundProperty, F_Foreround));
NewTrigger.Setters.Add(new Setter(TabItem.BackgroundProperty, F_Background));
L_NewControlTemplate.Triggers.Add(NewTrigger);
//Trigger Selected
NewTrigger = new Trigger { Property = TabItem.IsSelectedProperty, Value = false };
NewTrigger.Setters.Add(new Setter(TabItem.BackgroundProperty, L_IsDeActive));
L_NewControlTemplate.Triggers.Add(NewTrigger);
functionReturnValue.Setters.Add(new Setter(TabItem.FocusVisualStyleProperty, null));
functionReturnValue.Setters.Add(new Setter(TabItem.BackgroundProperty, F_Background));
functionReturnValue.Setters.Add(new Setter(TabItem.BorderBrushProperty, Brushes.Green));
functionReturnValue.Setters.Add(new Setter(TabItem.BorderThicknessProperty, new Thickness(0)));
functionReturnValue.Setters.Add(new Setter(TabItem.ForegroundProperty, F_Foreround));
functionReturnValue.Setters.Add(new Setter(TabItem.HorizontalContentAlignmentProperty, System.Windows.HorizontalAlignment.Center));
functionReturnValue.Setters.Add(new Setter(TabItem.VerticalContentAlignmentProperty, System.Windows.VerticalAlignment.Center));
functionReturnValue.Setters.Add(new Setter(TabItem.PaddingProperty, new Thickness(0)));
functionReturnValue.Setters.Add(new Setter(TabItem.MarginProperty, new Thickness(-4, -4, 0, 0)));
functionReturnValue.Setters.Add(new Setter(TabItem.TemplateProperty, L_NewControlTemplate));
return functionReturnValue;
So it turns out your first problem is these two lines:
functionReturnValue.Setters.Add(new Setter(TabItem.HorizontalContentAlignmentProperty, System.Windows.HorizontalAlignment.Center));
functionReturnValue.Setters.Add(new Setter(TabItem.VerticalContentAlignmentProperty, System.Windows.VerticalAlignment.Center));
Just omit those; they're acting on the tab item content, not on the header.
To restyle the header, you have a lot of options.
This will put a 20 unit margin around your content presenter:
L_ContentPresenter.SetValue(ContentPresenter.MarginProperty, new Thickness(20));
20's pretty arbitrary; of course you can use your own values. This will give it 20 unit side margins and 10 unit top/bottom margins:
L_ContentPresenter.SetValue(ContentPresenter.MarginProperty, new Thickness(20, 10, 20, 10));
You could also put a Border or something inside the header control template, surrounding the ContentPresenter, and do something with the padding or margins of that containing control. This kind of thing is infinitely easier to work with in XAML, so I'm not going to the trouble of doing that in C#.
You could have the TabItem style set HeaderTemplate, which is a DataTemplate:
var headerTemplate = new DataTemplate();
var label = new FrameworkElementFactory(typeof(Label));
label.SetBinding(Label.ContentProperty, new Binding());
label.SetValue(Label.MarginProperty, new Thickness(16, 12, 16, 12));
headerTemplate.VisualTree = label;
functionReturnValue.Setters.Add(new Setter(TabItem.HeaderTemplateProperty, headerTemplate));
In closing, I'd like to reiterate that whatever you need to do at runtime to Styles, you can do more easily and far more maintainably in XAML than in C#.

Update chart properties in Open XML

I am recently trying to create a bar chart in excel using Open XML and C#.
Below is portion of the script that helped me to create a bar chart in excel.
// Add a new drawing to the worksheet.
DrawingsPart drawingsPart = worksheetPart.AddNewPart<DrawingsPart>();
worksheetPart.Worksheet.Append(new DocumentFormat.OpenXml.Spreadsheet.Drawing() { Id = worksheetPart.GetIdOfPart(drawingsPart) });
worksheetPart.Worksheet.Save();
// Add a new chart and set the chart language to English-US.
ChartPart chartPart = drawingsPart.AddNewPart<ChartPart>();
chartPart.ChartSpace = new ChartSpace();
chartPart.ChartSpace.Append(new EditingLanguage() { Val = new StringValue("en-US") });
Drawing.Charts.Chart chart = chartPart.ChartSpace.AppendChild<Drawing.Charts.Chart>(new Drawing.Charts.Chart());
addChartTitle(chart, chartTitleText);
// Create a new clustered column chart.
PlotArea plotArea = chart.AppendChild<PlotArea>(new PlotArea());
Layout layout = plotArea.AppendChild<Layout>(new Layout());
addBarchart(plotArea);
addCategoryAxis(plotArea);
// Add the Value Axis.
ValueAxis valAx = plotArea.AppendChild<ValueAxis>(new ValueAxis(new AxisId() { Val = new UInt32Value(48672768u) },
new Scaling(new Orientation() { Val = new EnumValue<DocumentFormat.OpenXml.Drawing.Charts.OrientationValues>(DocumentFormat.OpenXml.Drawing.Charts.OrientationValues.MinMax) }),
new AxisPosition() { Val = new EnumValue<AxisPositionValues>(AxisPositionValues.Left) }, new MajorGridlines(), new DocumentFormat.OpenXml.Drawing.Charts.NumberingFormat()
{ FormatCode = new StringValue("General"), SourceLinked = new BooleanValue(true) }, new TickLabelPosition() { Val = new EnumValue<TickLabelPositionValues> (TickLabelPositionValues.NextTo) },
new CrossingAxis() { Val = new UInt32Value(48650112U) }, new Crosses() { Val = new EnumValue<CrossesValues>(CrossesValues.AutoZero) }, new CrossBetween() { Val = new EnumValue<CrossBetweenValues>(CrossBetweenValues.Between) }));
But unfortunately when I tried to edit the colors of bars, I couldn't make it successful. Please help me create a chart and to update chart properties using Open XML and C#.

Categories