locked
A couple of questions on a chart control RRS feed

  • Question

  • User240536124 posted

    My weekend project. Pretty happy to get this far. I was tasked with duplicating a chart from the actual data, so I tried a chart control for my first time. The data this was built on looks like this:

    1 7/13/2018 2:15:00 PM 0 psi 94.0
    2 7/13/2018 2:15:01 PM 0 psi 94.0
    3 7/13/2018 2:15:02 PM 213 psi 94.1
    4 7/13/2018 2:15:03 PM 640 psi 94.1
    5 7/13/2018 2:15:04 PM 731 psi 94.1
    6 7/13/2018 2:15:05 PM 822 psi 94.1
    7 7/13/2018 2:15:07 PM 946 psi 94.1

    Chart: Top picture is the one I had to duplicate. Bottom ones are what I generated with asp.net:

    charts

    The code I generated the charts with:

    System.DateTime x = new System.DateTime(2008, 11, 21);
    Chart1.DataSource = enumerableTable;
    Chart1.Series[0].Points.AddXY(x.ToOADate(), "tstamp");
    Chart1.Series[0].YValueMembers = "pressure";
    Chart1.Series[0].IsValueShownAsLabel = false;

    Data is pulled from MySql database.

    Couple of questions for someone more experienced with charting.

    1) The bottom chart, instead of showing the time stamp, shows 200, 400, 600, etc. How can I get the time from the timestamp column to show up? I had the devil getting it this close, because it did not like the time series*.

    2) The second chart on the right is a temperature chart. It is so zoomed out, you can hardly see the temp rise like in the chart above it. Best way to zoom in on the data and make it look like the chart above it, given the data I have to work with? Seems to be about 400 to 1,200 rows of data per chart.

    Thanks

    I did fix this error with the above code, though: "asp.net Series data points do not support values of type System.TimeSpan"  If someone is searching on this error.

    Sunday, July 22, 2018 9:03 PM

Answers

  • User409696431 posted

    You are showing a chart with y axis from 0 to 100, and comparing it to a chart with y axis from 93.5 to 95.5.   Change your axis range.

     IsStartedFromZero property on the y-axis changes the labeling algorithm so that the chart recalculates values for the Y-axis labels based on the minimum value in your dataset and the maximum value in your dataset.

    Chart1.ChartAreas[0].AxisY.IsStartedFromZero = false;

    Or hard code a min and max Y value, done easily in Design View

    <asp:ChartArea ... >
             <AxisY Title="Some Title" Minimum="93" Maximum="100" Interval="1"> </AxisY>

    .. or whatever you want to set it to.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 23, 2018 2:34 AM
  • User-330142929 posted

    Hi Jay8anks,

    As far as I know, the chart control in asp.net support system.timespan. I think you could assign the XValueType.

    I try to bind the following datatable to chart and it works.

    DataTable dt = new DataTable();
    
                dt.Columns.AddRange(new DataColumn[] { new DataColumn("Id"), new DataColumn("Name"),new DataColumn("Price") });
    
                dt.Rows.Add(new TimeSpan(12,36,39), "Peach", 12);
    
                dt.Rows.Add(new TimeSpan(12, 37, 39), "Apple", 15);
    
                dt.Rows.Add(new TimeSpan(12, 38, 39), "Grape", 18);
    
                dt.Rows.Add(new TimeSpan(13, 23, 12), "Pear", 23);
    
                dt.Rows.Add(new TimeSpan(13, 24, 12), "Mango", 24);
    
                dt.Rows.Add(new TimeSpan(13, 25, 12), "banana", 18);
    
                dt.Rows.Add(new TimeSpan(13, 26, 12), "Apricot", 29);
    
                dt.Rows.Add(new TimeSpan(13, 28, 12), "Berry", 34);
    
                return dt;

    result

     

    In addition,as KathyW says, the second question is about the Y-asix range. You could change the range of Y-axis by referring to the following Guide.

    Feel free to let me know if you have any questions

    Best Regards

    Abraham

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 23, 2018 7:40 AM

All replies

  • User409696431 posted

    You are showing a chart with y axis from 0 to 100, and comparing it to a chart with y axis from 93.5 to 95.5.   Change your axis range.

     IsStartedFromZero property on the y-axis changes the labeling algorithm so that the chart recalculates values for the Y-axis labels based on the minimum value in your dataset and the maximum value in your dataset.

    Chart1.ChartAreas[0].AxisY.IsStartedFromZero = false;

    Or hard code a min and max Y value, done easily in Design View

    <asp:ChartArea ... >
             <AxisY Title="Some Title" Minimum="93" Maximum="100" Interval="1"> </AxisY>

    .. or whatever you want to set it to.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 23, 2018 2:34 AM
  • User-330142929 posted

    Hi Jay8anks,

    As far as I know, the chart control in asp.net support system.timespan. I think you could assign the XValueType.

    I try to bind the following datatable to chart and it works.

    DataTable dt = new DataTable();
    
                dt.Columns.AddRange(new DataColumn[] { new DataColumn("Id"), new DataColumn("Name"),new DataColumn("Price") });
    
                dt.Rows.Add(new TimeSpan(12,36,39), "Peach", 12);
    
                dt.Rows.Add(new TimeSpan(12, 37, 39), "Apple", 15);
    
                dt.Rows.Add(new TimeSpan(12, 38, 39), "Grape", 18);
    
                dt.Rows.Add(new TimeSpan(13, 23, 12), "Pear", 23);
    
                dt.Rows.Add(new TimeSpan(13, 24, 12), "Mango", 24);
    
                dt.Rows.Add(new TimeSpan(13, 25, 12), "banana", 18);
    
                dt.Rows.Add(new TimeSpan(13, 26, 12), "Apricot", 29);
    
                dt.Rows.Add(new TimeSpan(13, 28, 12), "Berry", 34);
    
                return dt;

    result

     

    In addition,as KathyW says, the second question is about the Y-asix range. You could change the range of Y-axis by referring to the following Guide.

    Feel free to let me know if you have any questions

    Best Regards

    Abraham

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 23, 2018 7:40 AM
  • User240536124 posted

    Thanks guys. I'm pretty good at searching through forums and figuring stuff out, but I'm so new to charting I didn't know all the terminology to search on. And for some reason, I seem to understand forum posts better than msdn documentation. :)

    I actually am working from codebehind, so I didn't have some of the datasource options that you show in your screen shots. Took me a bit to figure out how to manually add them, but I actually got the time to start showing up.

    I discovered that no matter what I did, the time wasn't showing up on the Xaxis. Here was my biggest problem. There wasn't any binding between the time data I was pulling from the db and the chart. When I added the below line, it finally started showing up (imagine that!). Your answers helped me in formatting it, so all is good:

    Chart1.Series[0].XValueMember = "tstamp";

    Thanks again.

    Monday, July 23, 2018 3:03 PM