Click here to Skip to main content
13,139,569 members (53,194 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi,
I developed an application that was showing trend of event for period of years and i want to using CanvasJS to visualize the trend.
The Data's are return in a DataTable containing Years and Values. I declare the DataTable as public parameter and convert it to JQUERY String using stringBuilder then pass the Jquery as datapoints: ['<%=this.mDataTableJquery%>']
This did not work for me, i have been on this for three(3) weeks now with no result. I need any technical assistance to get this to work.

Thank you

What I have tried:

unit of my code:

mData = ConnectAll.GetDataObject("Select sum(totalg9) as Total from tbl_htc2 group by months");
try
{
var JSONString = new StringBuilder();
if (mData.Rows.Count > 0)
{
JSONString.Append("[");
for (int i = 0; i < mData.Rows.Count; i++)
{
JSONString.Append("{");
for (int j = 0; j < mData.Columns.Count; j++)
{
if (j < mData.Columns.Count - 1)
{
JSONString.Append("\"" + mData.Columns[j].ColumnName.ToString() + "\":" + "\"" + mData.Rows[i][j].ToString() + "\",");
}
else if (j == mData.Columns.Count - 1)
{
JSONString.Append("\"" + mData.Columns[j].ColumnName.ToString() + "\":" + "\"" + mData.Rows[i][j].ToString() + "\"");
}
}
if (i == mData.Rows.Count - 1)
{
JSONString.Append("}");
}
else
{
JSONString.Append("},");
}
}
JSONString.Append("]");
}



Response.Redirect(string.Format("~/data_load/monthly_trend.aspx?mData={0}", JSONString.ToString()));

The page that render the chart :



window.onload = function () {
var mTD = ' &lt;%=this.DT%>'
var chart = new CanvasJS.Chart("chartContainer",
{
title: {
text: "Trend Analysis"
},
axisY: {
// minimum: 50,
maximum: 300,
interval:50
},
axisX: {
// minimum: 50,
maximum: 200
//interval:-10
},
data: [
{
type: "column",
dataPoints: [
mTD
]
}
]
});

chart.render();
}
Posted 13-Sep-17 5:09am
Comments
j snooze 13-Sep-17 17:54pm
   
I don't know that I would do it this way. putting the data points in the querystring of a URL seems limiting, why not put the points in a list in a hidden field and post it to the chart page, then you can parse it and put the values in an array which is what the canvasjs seems to want per their documentation(https://canvasjs.com/editor/?id=https://canvasjs.com/example/gallery/overview/zooming-panning/) if you view the code they are just filling up and array and setting the datasource of the chart to that array. Maybe try that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 13 Sep 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100