Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900