We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

my chart isn't showing any data.

I'm trying to display the test time it takes to test one of our devices. With the x axis being the months, and y axis being the average time(these values range from 100-1000), and the lines being the year. I can't figure out what I'm doing wrong, but my chart isn't showing any lines it looks just like this: 


My cshtml code looks like this:

@section ControlsSection{

    <div class="control-section">

        <div style="text-align:center">


            @(Html.EJS().Chart("container").ChartArea(area => area.Border(br => br.Color("transparent"))).Series(series =>

       {

           series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line).Width(2).XName("xValue")

           .Marker(mr => mr.Visible(true).Width(10).Height(10)).YName("yValue")

           .DataSource(ViewBag.year2021).Name("2021").Add();

           series.Type(Syncfusion.EJ2.Charts.ChartSeriesType.Line)

           .Width(2).XName("xValue").YName("yValue")

           .Marker(mr => mr.Visible(true).Width(10).Height(10))

           .DataSource(ViewBag.year2022).Name("2022").Add();



       }).PrimaryXAxis(px => px.ValueType(Syncfusion.EJ2.Charts.ValueType.DateTime)

       .MajorGridLines(mg => mg.Width(0))

       .IntervalType(Syncfusion.EJ2.Charts.IntervalType.Months)

       .EdgeLabelPlacement(Syncfusion.EJ2.Charts.EdgeLabelPlacement.Shift).LabelFormat("y")

       ).PrimaryYAxis(py => py.LabelFormat("n1")

       .RangePadding(Syncfusion.EJ2.Charts.ChartRangePadding.None)

       .MajorTickLines(mt => mt.Width(0))

       .MinorTickLines(mt => mt.Width(0))

       .LineStyle(ls => ls.Width(0)).Interval(20).Minimum(0).Maximum(100)

       ).Title("TestTimes").Tooltip(tt => tt.Enable(true)).Render())




        </div>

    </div>


}

My class looks like this:

public class TestTimeModel

    {

        public DateTime xValue;

        public double yValue;


        public string PanelType;

    }

I'm getting my data from the database and I organize it. I have values for each object in the list then I add the lists to the viewbag like this:

ViewBag.year2021 = year2021;

ViewBag.year2022 = year2022;



2 Replies

SB Swetha Babu Syncfusion Team January 11, 2023 03:27 AM UTC

Hi Gideon,


We are validating the reported scenario and update you with further details within one business day(12/1/23).


Regards,

Swetha



SB Swetha Babu Syncfusion Team January 11, 2023 11:01 AM UTC

Hi Gideon,


Thank you for your patience.


We have created a simple MVC application using the database to render the chart to replicate the reported scenario. But, we are unable to reproduce the same. Please find the below tested sample link for your reference.


Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ChartSql775164286


Code snippet:


List<ChartSqlData> data = new List<ChartSqlData>();

string connectionString = null;

SqlDataAdapter adapter = new SqlDataAdapter();

DataSet dataset = new DataSet();

connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\NORTHWND.MDF;Integrated Security=True;";

SqlConnection con = new SqlConnection(connectionString);

con.Open();

string command2 = "SELECT * FROM [Products] WHERE UnitPrice < 10";

SqlCommand cmd1 = new SqlCommand(command2, con);

adapter.SelectCommand = cmd1;

adapter.Fill(dataset);

for (var i = 0; i < dataset.Tables[0].Rows.Count; i++)

{

       string x1 = Convert.ToString(dataset.Tables[0].Rows[i]["ProductName"]);

      double y1 = Convert.ToDouble(dataset.Tables[0].Rows[i]["UnitPrice"]);

       double y2 = Convert.ToDouble(dataset.Tables[0].Rows[i]["UnitsInStock"]);

       data.Add(new ChartSqlData(x1, y1, y2));

}

ViewBag.dataSource = data;



Screenshot:




If the reported scenario still persists, please modify the above sample to replicate the reported scenario. It will be helpful for us to analyze further and assist you better.


Regards,

Swetha


Loader.
Live Chat Icon For mobile
Up arrow icon