WPF DataVisualization Stacked Column Chart Binding - wpf

i will generate Stacked column chart, which will display on the x-axis cities and on the y-axis are count of genders in column. How to binding chart and this data:
List<Cities> Cities = new List<Cities>()
{
new Cities
{
Name = "Paris",
Genders = new Genders()
{
Man = 350000,
Woman = 436000
}
},
new Cities()
{
Name = "London",
Genders = new Genders()
{
Man = 698056,
Woman = 736982
}
}
};
I am trying to generate Series:
int i = 0;
foreach (var city in Cities)
{
Series s1 = new ColumnSeries();
s1.Title = city.Name;
s1.Name = "S"+i;
StackedColumnChart.Series.Add(s1);
i++;
}
i dont know how to binding data. Thanks

you can try to download a trial version of LightningChart with included demonstration examples for WinForms, WPF with Non-bindable, Semibindable and Fully Bindable examples.
You can easily look at the source code examples, e.g. ExampleStackedBars.
In a code behind you can create a field, which will be binded to the chart BarSeriesCollection property:
public static readonly DependencyProperty BarSeriesProperty =
DependencyProperty.Register(
"BarSeries",
typeof(BarSeriesCollection),
typeof(ExampleStackedBars)
);
public BarSeriesCollection BarSeries
{
get { return GetValue(BarSeriesProperty) as BarSeriesCollection; }
set { SetValue(BarSeriesProperty, value); }
}
And after create a new instance and add data to the collection:
BarSeries = new BarSeriesCollection();
GenerateData();
In XAML you can easily bind it using this line:
<lcusb:LightningChartUltimate.ViewXY>
**<lcusb:ViewXY BarSeries="{Binding BarSeries}">**
<lcusb:ViewXY.BarViewOptions>
<lcusb:BarViewOptions BarSpacing="30" Grouping="ByIndexFitWidth" Stacking="Stack" IndexGroupingFitGroupDistance="20"/>
</lcusb:ViewXY.BarViewOptions>
</lcusb:ViewXY>
</lcusb:LightningChartUltimate.ViewXY>
</lcusb:LightningChartUltimate>
or set binding path in the property tree

Example in Sparrow toolkit is for other chart type. i need Stacked bar chart. My graph must in x-axis cities and for each city must be multiple values in column. This is my chart:
<charting:Chart
Grid.Column="0"
Grid.Row="0"
x:Name="StackedColumnChart"
Title="Stacked Column"
Margin="5">
<charting:StackedColumnSeries>
</charting:StackedColumnSeries>
</charting:Chart>
I dont know what is series. Series is columns? How to assign multiple value (in my example genders) to one column?

Related

Can't get custom images to display in Azure Maps as Symbols

I really can't find any good documentation or any good samples on how to do this.
Here is my code. This is running in an Asp.net Core View.
var imageMarker = "https://unpkg.com/leaflet#1.7.1/dist/images/marker-icon.png";
for (var i = 0; i < locationData; i++) {
let imageName = 'image' + i;
map.imageSprite.add(imageName, imageMarker).then(function () {
//Create a data source and add it to the map.
datasource = new atlas.source.DataSource();
map.sources.add(datasource);
//Create a point feature and add it to the data source.
datasource.add(new atlas.data.Feature(new atlas.data.Point(i.longitude, i.latitude), {
name: i.name
}));
//Add a layer for rendering point data as symbols.
map.layers.add(new atlas.layer.SymbolLayer(datasource, null, {
iconOptions: {
//Pass in the id of the custom icon that was loaded into the map resources.
image: imageName,
//Optionally scale the size of the icon.
size: 0.5
},
textOptions: {
//Add some text
textField: name,
//Offset the text so that it appears on top of the icon.
offset: [0, -2]
}
}));
});
}
I'm not getting any errors. The Symbols just don't appear on the map.
The sample linked below works in my map.events.add ready function.
Image Sprite sample
Any help is much appreciated! Thanks!
Here is what ended up working for me. I worked with Microsoft Support on this. locationData contains the image, longitude and latitude. The min and max of both longitude and latitude is passed in as well to set the camera boundry. The biggest issue with my original code was setting iconOptions size to 0.5. The plugin did not like that. It's now set to 1.
function addMarkerSymbols(locationData, min_long, min_lat, max_long, max_lat)
{
map.setCamera({
bounds: [min_long, min_lat, max_long, max_lat],
padding: 50
});
$.each(locationData, function (i, item)
{
map.imageSprite.add('default-icon' + i, item.locationImage);
//Create a data source and add it to the map.
var datasource = new atlas.source.DataSource();
map.sources.add(datasource);
//Add a data set to the data source.
datasource.add(new atlas.data.Feature(new atlas.data.Point([item.longitude, item.latitude]), null));
//Create a symbol layer to render the points.
layer = new atlas.layer.SymbolLayer(datasource, null, {
iconOptions: {
//The map control has built in icons for bar, coffee and restaurant that we can use.
image: 'default-icon' + i,
anchor: 'center',
allowOverlap: true,
size: 1
}
});
map.layers.add(layer);
});
}

Bind the values of a grid record to a form and a window

Although there are several ways to load the values of a record into a form within a window, in the specific case of using binding from a grid to a form (for example, to display the detail of the record) how to bind the same values to a form within a window (for example: to edit the record)?
FIDDLE: https://fiddle.sencha.com/#view/editor&fiddle/1stv
Pass the record in as part of the VM data:
var janela = Ext.create('APP.MyWindow', {
animateTarget: btn.getEl(),
viewModel: {
data: { users: selectedRow }
}
}).show();

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

How to set combox value on form from grid with nested data? Extjs 4.2 Mvc

I have a grid that pops up an edit form with combobox. Before I show the view I load the combobox store. Then I set the values of the form using form.loadRecord(record);. This loads the primary record ok. But how do I load the associated data value that is tied to the combobox so the combobox's value is set correctly.
I know I can use setValue manually, but I guess I was thinking could be handled via a load form.
If my form has 3 fields lets say firstName lastName and then a combobox of ContactType. The firstName and lastName are in my primary record with ContactType being the associated record. If I change values in fields lastName or firstName a change is detected and the record is marked as dirty. If I change the combobox value the record is not marked as dirty. I am guessing because they are two different models. How to make it one record. I would think having a combobox on a form that has its values set from a record in a grid is common but I can't find any examples of best way to accomplish this.
Here is some code.
My json looks like this. Primary record has firstName lastName hasOne associated record is ContactType
{
"__ENTITIES":[
{
"__KEY":"289",
"__STAMP":12,
"ID":289,
"firstName":"a",
"middleName":"",
"lastName":"asd",
"ContactType":{
"__KEY":"2",
"__STAMP":4,
"ID":2,
"name":"Home"
}
}
]
}
Controller list function,edit function and updatefunction, fires when grid row is clicked
list: function () {
var mystore = this.getStore('Contacts')
mystore.proxy.extraParams = { $expand: 'ContactType'};
mystore.load({
params: {
},
callback: function(r,options,success) {
// debugger;
} //callback
}); //store.load
editContact: function (grid, record) {
//load store for combobox
var store = this.getStore('ContactTypes');
store.load({
params: {
},
callback: function(r,options,success) {
// debugger;
} //callback
}); //store.load
var view = Ext.widget('contactsedit');
var form = view.down('form')
//load primary record
form.loadRecord(record);
//load associated record
form.loadRecord(record.getContactType());
updateContact: function (button) {
var win = button.up('window'),
form = win.down('form'),
record = form.getRecord(),
values = form.getValues(),
store = this.getStore('Contacts')
if (form.getForm().isValid()) {
if (this.addnew == true) {
store.add(values);
} else {
record.set(values);
}
store.sync();
win.close();
}
}
The loadRecord(record.getContactType) is a getter to the associated data. I am able to get the associated data but not sure how to make it set the value in the combobox or how to get it to act as one record and detect changes automatically.
My Contacts Model
Ext.define('SimplyFundraising.model.Contact', {
extend : 'Wakanda.model',
requires:[
'SimplyFundraising.model.ContactType'
],
fields: ['firstName', 'middleName','lastName','ContactType.name'],
associations: [
{
type: 'hasOne',
model: 'SimplyFundraising.model.ContactType',
name: 'ContactTypes',
getterName: 'getContactType',
associationKey: 'ContactType'
}
]
});
ContactType model
Ext.define('SimplyFundraising.model.ContactType', {
extend : 'Wakanda.model',
fields: ['__KEY','name',]
});
Is this the proper way to set a value for a combobox in a form with nested data?
Should I not use associations and just put all fields in my Contact Model ie add all ContactType fields to Contact model, then data should be in the same record and change tracking would work. But this seems counter to the MVC pattern and counter to the reason for associations.
How do you guys handle this scenario, any examples would be great!
Thanks,
Dan
if your form is loading the values correctly, then all you need to do is this:
Extjs4, How to set displayField in combo editor?

RavenDB model questions

I'm considering using RavenDb for a new project we're doing at our company.
The project will consist of entities that have a set of dynamic properties based on the labels that a user might attach to them.
Example:
Entity called Image has:
Id
Name
Size
We want to use Labels (just another entity in the system) to allow the users to create specific properties for an image.
A label consists of a name, and might have a parent label.
If the user creates two Labels:
House
Car
The House label has the following properties:
Location
Color
Size
The Car label has the following properties:
Brand
Color
Engine type
Total doors
(These labels and properties must be managed by the user with special edit screens in our application).
When a user then creates an Image and assigns a specific label to that image, all the properties from that label must be present on the new image.
There can be multiple Labels attached to one Image. The Labels should be queried separately in order to show them in the GUI.
My question is:
I know how to do this in SQL. But I'm a bit concerned about the performance when there might be 300000 images with all kinds of properties. Especially when we want to search for those properties.
Can anyone give me a jump start (or an already existing tutorial) for this kind of setup? I'm not sure on how to model my entities for this kind of data.
Thnx!
Not quite sure what you mean by "Labels should be queried separately in order to show them in the GUI." but a document for each image with the properties from each label stored directly would be a starting point.
E.g.
public class Image
{
public string Id { get; set; }
public string Name { get; set; }
public Dictionary<string, Dictionary<string, object>> LabelProperties { get; set; }
}
You can then populate this as follows:
var img1 = new Image
{
Name = "Image1",
LabelProperties = new Dictionary<string, Dictionary<string, object>>
{
{
"Car",
new Dictionary<string, object>
{
{ "Brand", "GM"},
{ "Color", "Blue"},
{ "Engine type", "Big"},
{ "Total doors", 4}
}
},
{
"House",
new Dictionary<string, object>
{
{ "Location", "Downtown"},
{ "Color", "Blue"},
{ "Size", 240}
}
}
}
};
This then ends up looking quite nicely structure JSON in the db:
{
"Name": "Image1",
"LabelProperties": {
"Car": {
"Brand": "GM",
"Color": "Blue",
"Engine type": "Big",
"Total doors": 4
},
"House": {
"Location": "Downtown",
"Color": "Blue",
"Size": 240
}
}
}
You could then query this using dynamic indexes. E.g. to find all images that contain a blue house:
var blueHouses = session.Query<Image>()
.Customize(x => x.WaitForNonStaleResults())
.Where(x => Equals(x.LabelProperties["House"]["Color"], "Blue"));
Console.WriteLine("--- All Images Containing a House of Color Blue");
foreach (var item in blueHouses)
{
Console.WriteLine("{0} | {1}", item.Id, item.Name);
}
If you want to query on the labels themselves an index might be required. See the gist for the full example.

Resources