0

I Am trying to make a chart.

This works:

@model List<MyApp.Models.SystemModel>
    @{var myChart = new Chart(width: 600, height: 400)
        .AddTitle("Chart Title")
        .AddSeries(
        name: "Employee",
        xValue: Model[0].HistoryValues.Select(x => x.LastUpdateSTR).ToArray(),
        yValues: Model[0].
               HistoryValues.Select(x => x.ServerPerformance).ToArray())
        .Write();
    }

However I don't want to go on Model[0] I want to go on every model object that I have in my list.

Ive tried this:

@model List<MyApp.Models.SystemModel>
<div id="Chart col-md-6">
    @{ var myChart = new Chart(width: 600, height: 400)
        .AddTitle("ServerPerformance")
        .AddSeries(
            name: "ServerPerformance",
            xValue: Model.Select(y => y.HistoryValues.Select(x => x.LastUpdateSTR)).ToArray(),
            yValues: Model.Select(y => y.HistoryValues.Select(x => x.ServerPerformance)).ToArray()
        )
        .Write();                             
    }
</div>

But that gave an outOfrangeException:

Data points binding error. Only 1 Y values can be set for this data series

It is clear to me that my linq code is not correct, Ive tried with some other methods as .foreach() but that gave me an even bigger headache.

How can i do this?

EDIT:

i tried this in my controller.

var myChart = new Chart(width: 600, height: 400)
                                                                                                  .AddTitle("ServerPerformance")
    .AddSeries(
      name: "ServerPerformance",
      xValue: model.Select(y => y.HistoryValues.Select(x => x.LastUpdateSTR)).ToArray(),
     yValues: model.Select(y => y.HistoryValues.Select(x => x.ServerPerformance)).ToArray());

X and Y values are null.

MODEL:

public string GuidId { get; set; }
public bool EverythingOffline { get; set; }
public bool ServerOnline { get; set; }
public long ServerPerformance { get; set; }
public string DomainName { get; set; }
public string Url { get; set; }
public string ErrorMessage { get; set; }
public long DomainId { get; set; }
public Guid Id { get; set; }
public bool DatabaseOnline { get; set; }
public bool Passed { get; set; }
public long Databaseperformance { get; set; }
public DateTime LastUpdate { get; set; }

public string LastUpdateSTR { get; set; }

public long SoldTicketsLastUpdate { get; set; }
public long SoldTicketsLastThirtyMin { get; set; }
public long SoldTicketsLastFifteenMin { get; set; }

public DateTime LastUpdateDate { get; set; }
public double LastUpdateDateMinutes { get; set; }

public DateTime SoldTitcketsDate { get; set; }

public List<SystemModel> HistoryValues { get; set; }
6
  • try this Model.HistoryValues.Select(x => x.LastUpdateSTR).ToArray() Commented Apr 1, 2016 at 9:10
  • 2
    why dont you move the logic into controller where you build a list of array's and assign them into model properties and then use it by just saying something simple as Model.xValues and Model.yValues Commented Apr 1, 2016 at 9:11
  • @Kartikeya Khosla Model is a list of my model object Check Edits Commented Apr 1, 2016 at 9:12
  • What type is your Model? IEnumerable? Commented Apr 1, 2016 at 9:15
  • Can you post your model code? Commented Apr 1, 2016 at 9:15

1 Answer 1

1

If your model is a list, and every element of this list has list HistoryValues you should be able to select all values by this code

xValue: model.SelectMany(y => y.HistoryValues).Select(x => x.LastUpdateSTR).ToArray(),
yValues: model.SelectMany(y => y.HistoryValues).Select(x => x.ServerPerformance).ToArray()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.