Telerik: How to set CartesianGridLineAnnotation Background color - wpf

So in my application i have chat and i added CartesianGridLineAnnotation:
RadCartesianChart chart;
CartesianGridLineAnnotation cartesianGridLineAnnotation;
cartesianGridLineAnnotation = new CartesianGridLineAnnotation
{
Foreground = Brushes.White,
Background = Brushes.Green,
Axis = chart.VerticalAxis,
Stroke = Brushes.Red,
StrokeThickness = 1,
};
chart.Annotations.Add(...);
So as you can see i try to set Background color but the problem is that i cannot see any change in my CartesianGridLineAnnotation Label.
Other properties when changed look as expected.
Update
This is how i am populate my label:
cartesianGridLineAnnotation.Label = "bla bla";
As you can see i cannot see the backgroud color.

Related

How to set different colors on zoom control in amCharts map (v4)

By setting fill property we can set the background color property of the zoom controls, but the button text color is not a property we can set.
chart.zoomControl.plusButton.background.cornerRadius(5, 5, 5, 5);
chart.zoomControl.plusButton.background.fill = '#014888';
chart.zoomControl.plusButton.background.states.getKey('hover').properties.fill = '#27aad6';
Is there a choice to set it?
I have set it by this way:
chart.zoomControl.plusButton.label.fill = '#ffffff';
chart.zoomControl.minusButton.label.fill = '#ffffff';
chart.set("zoomControl", am5map.ZoomControl.new(root, {
background: am5.Rectangle.new(root, {
// fill: am5.color(0xeb354e),
fillOpacity: 0.9,
strokeOpacity:0
})
}));

How do I set themes for widgets in windows?

with the tutorials on qooxdoo.org I found out how to theme my widgets. This works great for overall styling.
If I configure "label", all my labels become a yellow textcolor. If I configure "button/label", all labels on my buttons become a red textcolor while every other remains yellow. Good so far.
What's not working is if I try to set a textcolor for labels inside a window:
"window/label", "window/pane/label", "window/widget/label" With none of these keys I can change the style for label-widget inside my window.
What is the correct key to give labels as child-elements inside my window a different style?
Thanks a lot
Ricky
A qx.ui.window.Window is a container wich implements RemoteChildrenHandling. That means, that the chain of child controls stops when it comes to the window content.
Depending on what you want to achieve, you can:
add a Label to a Window and set the Label appearance directly
inherit from Window (i.e. a custom Dialog class of your own), add a content label as a childControl of your dialog and adjust the Label color in your theme by using the choosen child control path
The first option would lead to this code:
var win = new qx.ui.window.Window("My Title");
win.setLayout(new qx.ui.layout.VBox(10));
win.add(new qx.ui.basic.Label("My content").set({
appearance: 'custom-label-appearance'
}));
If you've just some appearances for Label objects and you don't want to add the appearance every time, you also could subclass it:
qx.Class.define("my.Label", {
extend: qx.ui.basic.Label,
properties: {
appearance: {
refine: true,
init: 'custom-label-appearance'
}
}
});
var win = new qx.ui.window.Window("My Title");
win.setLayout(new qx.ui.layout.VBox(10));
win.add(new my.Label("My content"));
Here is an example for the second option:
qx.Class.define("my.Dialog", {
extend: qx.ui.window.Window,
construct: function(title, label) {
this.base(arguments, title);
this.setLayout(new qx.ui.layout.Atom());
this.getChildControl('my-label').setValue(label);
},
members: {
//overridden
_createChildControlImpl : function(id)
{
var control;
switch (id)
{
case "my-label":
control = new qx.ui.basic.Label();
this.add(control);
break;
}
return control || this.base(arguments, id);
}
}
});
You can then set the appearance path window/my-label in this case.
Note that both solutions will not keep you away from setting appearances to all labels that you add to the window.

OxyPlot legend items managing

is there any way to manage items in legend? I mean e.q. remove some items from legend but not from whole plot? I know that each serie in plot is linked with one item in legend, but i want to break this rule and put to legend only selected series.
Thanks for your request.
If you don't assign a title to the series (LineSeries, etc), it won't be represented on the legend:
var plotModel = new PlotModel();
plotModel.LegendTitle = "Legend";
plotModel.LegendPosition = LegendPosition.RightBottom;
plotModel.Series.Add(new LineSeries
{
ItemsSource = someItemSource,
Color = OxyColors.Red,
//Title = "title" <- Title commented
});
Starting v2.0.1, the legend doesn't automatically appear and all PlotModel.LegendXxx members have been removed. You now have to manually add one legend:
var plotModel = new PlotModel();
plotModel.Legends.Add(new Legend() {
LegendTitle = "Legend",
LegendPosition = LegendPosition.RightBottom,
});
plotModel.Series.Add(new LineSeries
{
ItemsSource = someItemSource,
Color = OxyColors.Red,
//Title = "title" <- Title commented
});

Creating Images in WPF without XAML and dispaying

I am trying to create a WPF Chart in c# code and saving it to file without displaying it on screen. This will be in a WCF Service where data is sent to the service, an image is created and and path to the image is returned.
So far I have got the image to save to file and the data on the X & Y axis is displayed but the columns on the graph are not drawn.
Does anyone know why the columns on the chart are not drawing... here is my code:
public void DoWork()
{
var newThread = new Thread(CreateImage);
newThread.SetApartmentState(ApartmentState.STA);
newThread.Start();
}
public void CreateImage()
{
var grid = new Grid {Width = 800, Height = 600, Background = new SolidColorBrush(Colors.LightBlue)};
var chart = new Chart();
grid.Children.Add(chart);
var renderTarget = new RenderTargetBitmap((int)grid.Width, (int)grid.Height, 96d, 96d, PixelFormats.Default);
var barSeries = new BarSeries
{
Title = "Fruit in Cupboard",
ItemsSource = new[]
{
new KeyValuePair<string, int>("Oranges", 18),
new KeyValuePair<string, int>("Apples", 15),
new KeyValuePair<string, int>("Melons", 2),
new KeyValuePair<string, int>("Pineapples", 4),
new KeyValuePair<string, int>("Plums", 25)
},
IndependentValueBinding = new Binding("Key"),
DependentValueBinding = new Binding("Value")
};
chart.Series.Add(barSeries);
grid.Measure(new Size(grid.Width, grid.Height));
grid.Arrange(new Rect(new Size(grid.Width, grid.Height)));
grid.UpdateLayout();
renderTarget.Render(grid);
var png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(renderTarget));
using (Stream stm = File.Create(string.Format(#"C:/Images/{0}.png", Guid.NewGuid())))
{
png.Save(stm);
}
}
I had exactly this problem with Telerik's RadChart. The explanation was as you wrote in your comment above - the series was being animated in and the snapshot was being taken before they were visible.
My solution was to set the value of the ChartArea.EnableAnimations property to false before rendering it. I am not familiar with the WPF Toolkit Chart but it is likely that there is a similar setting that you can use to disable the animations.
Note that there is a further, related issue with Telerik's BarSeries - it is necessary to set the opacity of the bars to 1. See the Telerik documentation for details.

Force rendering of a WPF control in memory

I have the following code:
void Test()
{
currentImage.Source = GetBitmap();
RenderTargetBitmap rtb = new RenderTargetBitmap(100, 100, 96.0, 96.0, PixelFormats.Default);
rtb.Render(currentImage);
}
This code is supposed to render currentImage, which is an Image control in my xaml to a RenderTargetBitmap.
It doesn't work, rtb returns a blank image, the problem is currentImage didn't render itself yet and so this behavior is expected, I think...
To workaround this problem, I wrote this code:
void Test()
{
currentImage.Source = GetBitmap();
this.Dispatcher.BeginInvoke((Action)delegate()
{
RenderTargetBitmap rtb = new RenderTargetBitmap(100, 100, 96.0, 96.0, PixelFormats.Default);
rtb.Render(currentImage);
}, System.Windows.Threading.DispatcherPriority.Render, null);
}
Basically, I wait for currentImage to be rendered and then I can get it properly rendered to my RenderTargetBitmap.
Is there any way to make it work without using this workaround? Force the Image control to render in memory maybe?
thanks!
use a ViewBox to render in memory
Grid grid = new System.Windows.Controls.Grid() { Background = Brushes.Blue, Width = 200, Height = 200 };
Viewbox viewbox = new Viewbox();
viewbox.Child = grid; //control to render
viewbox.Measure(new System.Windows.Size(200, 200));
viewbox.Arrange(new Rect(0, 0, 200, 200));
viewbox.UpdateLayout();
RenderTargetBitmap render = new RenderTargetBitmap(200, 200, 150, 150, PixelFormats.Pbgra32);
render.Render(viewbox);
I think this is a BETTER answer . The viewbox didn't work completely as expected, and it turned out to be an unnecessary overhead.
Here is a copy of that answer (instead of just link)
You need to force a render of the item, or wait for the item to be rendered. You can then use the ActualHeight and ActualWidth properties.
To force a render:
MenuItem item = new MenuItem();
item.Header = "bling";
item.Icon = someIcon;
//Force render
item.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
item.Arrange(new Rect(item.DesiredSize));
In this example the MenuItem has not been given an explicit height or width. However, forcing the render will render it taking the supplied header text and icon into consideration.

Resources