I'm hoping to get a quick solution to this.
Here is a snippet of the code that works when creating a series:
Series SeriesABC2 = new Series
{
Name = '#' + HakuAlueet[1],
Data = new Data(
new object[]{
new[] { 300, 440 },
new[] { 400, 540 }
}),
PlotOptionsArearange = new PlotOptionsArearange { Visible = true, LineWidth = 0, FillOpacity = 0.3 },
Type = ChartTypes.Arearange
};
Now the plan is to make this dynamic creating the values in the object "new[] { 300, 440 }, new[] { 400, 540 }" inside .net C#. I'm quite new to C# so I'm not quite sure of the naming convention, but I seem to need to make an array object of an two value arrays. How would I go about this?
I've tried countless ways of managing this but just haven't found a solution that would be acceptable to dotnet.Highcharts. Thanks!
string[] books= source.Select(a => a.bookName).ToArray();
object[] visits = source.Select(a => (object)a.Visits).ToArray();
DotNet.Highcharts.Highcharts chart = new DotNet.Highcharts.Highcharts("chart")
.InitChart(new Chart { DefaultSeriesType = ChartTypes.Bar,
Width = 900
}).SetPlotOptions(new PlotOptions {
Bar = new PlotOptionsBar {
ColorByPoint = true,
DataLabels = new PlotOptionsBarDataLabels {
Enabled = true }
}
}).SetXAxis(new XAxis { Categories = books,
}).SetSeries(new Series
{
Data = new Data(visits),
Name = "User Book Visits"
});
lb_chart.Text = chart.ToHtmlString();
Here source contain data where I am querying some dynamic content. This is working and hope this will also help you.
Related
I am trying to get into more complex Linq queries and right away catch a point I am feeling stuck. I have a following list in DB:
ID ELAPSED TIME APPISRUNNING
1 12 TRUE
2 54 TRUE
3 32 FALSE
Where ELAPSED TIME is TimeSpan and APPISRUNNING is a bool.
I would like to build a chart based on these values (https://github.com/beto-rodriguez/LiveCharts2). Chart build fine with this:
Title = "Analytics";
this.ActivityChartSeries = new ISeries[]
{
new PieSeries<double> { Values = new double[] { 2 }},
new PieSeries<double> { Values = new double[] { 2 }},
new PieSeries<double> { Values = new double[] { 2 }},
new PieSeries<double> { Values = new double[] { 2 }},
new PieSeries<double> { Values = new double[] { 2 }},
};
Now I somehow need to first GroupBy bool and then select a new List? I have tried following:
IEnumerable<DataRecord> dataRecords = await this.DataStore.GetItemsAsync();
this.ActivityChartSeries = dataRecords
.GroupBy(g => g.AppIsRunning)
.Select(m => new
{ // BELOW IS TOTALLY UNCLEAR FOR ME
Values = m.Select(r => r.EngineElapsed.Ticks),
Name = m.Select(r => r.Name),
})
.Select(x =>
new PieSeries<double>
{
Values = new List<double> { x.Values.FirstOrDefault() },
Name = x.Name.FirstOrDefault(),
});
Type of assigned variable:
public IEnumerable<ISeries> ActivityChartSeries
This part is totally unclear for me:
Values = m.Select(r => r.EngineElapsed.Ticks),
Name = m.Select(r => r.Name),
How after GroupBy I can create two types of data? Basically I need
"Application Running" and "Values"
"Application is not Running" and "Values"
EDIT:
Code provided by Somar Zein compiles fine:
var results = activityChartSeries
.GroupBy(a=> a.AppIsRunning)
.Select(item=> new PieSeries<double>{
Name = item.Key ? "Application is Running" : "Application is not Running",
Values = item.Select(x=> Convert.ToDouble(x.ElapsedTime.Ticks)).ToList()
});
However as a result I am getting something like this, why it is reloading in a loop?
Here is result:
enter image description here
EDIT2:
So I have created an example for testing purposes:
Class:
public class DataModel
{
public int Id { get; set; }
public TimeSpan ElapsedTime { get; set; }
public bool AppIsRunning { get; set; }
}
Code:
List<DataModel> records = new List<DataModel>();
records.Add(new DataModel { Id = 1, ElapsedTime = new TimeSpan(1, 20, 30), AppIsRunning = true });
records.Add(new DataModel { Id = 2, ElapsedTime = new TimeSpan(1, 20, 30), AppIsRunning = true });
records.Add(new DataModel { Id = 3, ElapsedTime = new TimeSpan(1, 20, 30), AppIsRunning = true });
records.Add(new DataModel { Id = 4, ElapsedTime = new TimeSpan(1, 20, 30), AppIsRunning = true });
records.Add(new DataModel { Id = 5, ElapsedTime = new TimeSpan(1, 20, 30), AppIsRunning = true });
this.ActivityChartSeries = records
.GroupBy(g => g.AppIsRunning)
.Select(item => new PieSeries<double>
{
Name = item.Key ? "Running" : "Not Running",
Values = new double[] { 2, 4 },
});
I get the same reloading effect, even thou originally provided Example from LiveCharts work fine.
you could try doing something like following:
var results = activityChartSeries
.GroupBy(a=> a.AppIsRunning)
.Select(item=> new PieSeries<double>{
Name = item.Key ? "Application is Running" : "Application is not Running",
Values = item.Select(x=> Convert.ToDouble(x.ElapsedTime.Ticks)).ToList()
});
hope that could be helpful!
I am updating older code but part of it must stay the same. I have now picker that needs to be filled with list.
My list
public List<TimeoutBetweenSentences> FillTimoutOptions()
{
var newListTimeoutBetweenSentenceses = new List<TimeoutBetweenSentences>()
{
new TimeoutBetweenSentences()
{
Position = 0,
Text = "+ 0 sekund",
Value = 0
},
new TimeoutBetweenSentences()
{
Position = 1,
Text = "+ 1 sekunda",
Value = 1
},
new TimeoutBetweenSentences()
{
Position = 2,
Text = "+ 2 sekundy",
Value = 2
},
new TimeoutBetweenSentences()
{
Position = 3,
Text = "+ 3 sekundy",
Value = 3
},
new TimeoutBetweenSentences()
{
Position = 4,
Text = "+ 4 sekundy",
Value = 4
},
new TimeoutBetweenSentences()
{
Position = 5,
Text = "+ 5 sekund",
Value = 5
},
};
return newListTimeoutBetweenSentenceses;
}
List<TimeoutBetweenSentences> allOptions = FillTimoutOptions();
sentencePausesStepper.Items.Add(allOptions.Select(m => m.Text).ToList().ToString());
however this displays just as "System collections" DO zou have any idea?
this is adding an entire list as ONE element
sentencePausesStepper.Items.Add(allOptions.Select(m => m.Text).ToList().ToString());
to add elements of one list to another, use AddRange instead
sentencePausesStepper.Items.AddRange(allOptions.Select(m => m.Text).ToList().ToString());
or better, do this
sentencePausesStepper.ItemsSource = allOptions;
sentencePausesStepper.ItemDisplayBinding = new Binding("Text");
I am using DotNetHighCharts and playing around with the various chart formats. The Pie Chart labels show “Slice” for each slice of the pie. What parameter is used to change this to the actual name of the slice?
I got this figured out. I was using the PlotOptions like this
.SetPlotOptions(new PlotOptions
{
Pie = new PlotOptionsPie
{
DataLabels = new PlotOptionsPieDataLabels
{
Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; }"
}
}
})
However, I wasn’t passing in the names of the datapoint. So I created a namesAndVals object array that was passed into the Data element of the .SetSeries method.
object[] names = new object[] { “Val1", “Val2", “Val3", “Val4" };
object[] vals = new object[] { 11, 12, 13, 14 };
object[,] namesAndVals = new object[4,2];
for (int i = 0; i < names.Count(); i++)
{
namesAndVals[i, 0] = names[i];
namesAndVals[i, 1] = vals[i];
}
If there is a better way to create the final array I’m open to suggestions. Eventually, the gals and names will be driven by a database.
I m facing problem with dotnet highcharts controls the problem is the values in x axis are repeating i.e. 0 0 1 1 2 2 3 3 4 4 5 5. Please help
below is my code.
Javascript code
<div id='ContentAvailabilty_container'></div>
<script type='text/javascript'>
var ContentAvailabilty;
$(document).ready(function() {
ContentAvailabilty = new Highcharts.Chart({
chart: { renderTo:'ContentAvailabilty_container', type: 'bar' },
legend: { enabled: false, layout: 'horizontal' },
plotOptions: { bar: { borderWidth: 0 } },
title: { text: 'Content Availabilty' },
xAxis: { categories: ['#Rest of Published', '#Published Queue', '#Rest of Unpublished', '#Unpublished Queue', '#New Approved'] },
yAxis: { labels: { formatter: function() { return Highcharts.numberFormat(this.value, 0); } }, min: 0, title: { text: '' } },
series: [{ data: [5, 0, 0, 0, 0] }]
});
});
</script>
DOT NET CODE
DotNet.Highcharts.Highcharts currentReport = new DotNet.Highcharts.Highcharts("ContentAvailabilty");
currentReport.InitChart(new Chart { Type = ChartTypes.Bar });
currentReport.SetTitle(new Title { Text = "Content Availabilty" });
currentReport.SetXAxis(new XAxis
{
Categories = new[] { "#Rest of Published", "#Published", "#Rest of Unpublished", "#Unpublished", "#Approved" }
});
currentReport.SetYAxis(new YAxis
{
Title = new XAxisTitle { Text = "" }
, Labels = new XAxisLabels { Formatter = "function() { return Highcharts.numberFormat(this.value, 0); }" }//function to convert 4k to 4000
,Min=0
});
currentReport.SetLegend(new Legend { Enabled = false });
currentReport.SetPlotOptions(new PlotOptions { Bar = new PlotOptionsBar { BorderWidth=0} });
currentReport.SetSeries(new Series[] {
new Series{
Data = new Data( new object[]{ RestofPublished, publishedQueue, Rest_of_UnPublished, UnPublished_Queue, newApproved } )
}
});
ReportContainerLabel.Text = string.Empty;
ReportContainerLabel.Text = currentReport.ToHtmlString();
xAxis : [{categories : []}], // when defining X-Axis
chart.xAxis[0].setCategories(JSON_object); // when parsing data ,from another method ,
if you want to use categories X-Axis or Y-Axis ? .bcoz the code and the chart image confusing me , any way if you want to set the categories by manually , then initially make categories as null , and assigned a array to it by using JQuery , if you loading dynamic data , then there should be a parsed json object or something semilar
I'm currently working on a control which will allow me to assign sizes to placeholders on a page. The control working using various data tables and so is getting quite complex.
I want to make the process of creating a layout as automated as possible.
What I am trying to do is generate a number of gridview rows based on a value being pulled from a datatable.
Here is my code so far
List<GridData> Grids = new List<GridData>();
Grids.Add(new GridData { Size = 1, Title = "Grid_1" });
Grids.Add(new GridData { Size = 2, Title = "Grid_2" });
Grids.Add(new GridData { Size = 3, Title = "Grid_3" });
Grids.Add(new GridData { Size = 4, Title = "Grid_4" });
Grids.Add(new GridData { Size = 5, Title = "Grid_5" });
Grids.Add(new GridData { Size = 6, Title = "Grid_6" });
Grids.Add(new GridData { Size = 7, Title = "Grid_7" });
Grids.Add(new GridData { Size = 8, Title = "Grid_8" });
Grids.Add(new GridData { Size = 9, Title = "Grid_9" });
Grids.Add(new GridData { Size = 10, Title = "Grid_10" });
Grids.Add(new GridData { Size = 11, Title = "Grid_11" });
Grids.Add(new GridData { Size = 12, Title = "Grid_12" });
GV_PlaceHolders.DataSource = from x in db.DT_Layouts2s
where x.LayoutID == int.Parse(DDL_Layouts.SelectedValue.ToString())
select new
{
x.LayoutID,
x.PlaceHolders,
Grids,
};
GV_PlaceHolders.DataBind();
Now the way I want to generate the rows is by calling upon the place holders int value but I have no idea where even start with generating dynamic rows based on a value.
Can anyone point me in the right direction???
Cheers