Sign in to follow this  
sethm

revenueChart.chartType(newcharttype) not working

Recommended Posts

I have a working msline chart built from data straight from a database that is working great. I am trying to find a way to convert it to other types of charts (column2d, and pie2d). I have tried .chartType()  as refereneced here:

 

http://www.fusioncharts.com/dev/usage-guide/how-to-guides/change-chart-properties-at-runtime.html 

 

but it says:

 

"FusionCharts.Charts.Chart does not contain a definition for 'chartType' and no extension method 'chartType' accepting a first argument of type 'FusionCharts.Charts.Chart' could be found (are you missing a using directive or an assembly reference?)"

 

I do not believe I am missing a reference. 

 

I have also tried altering the reference when I use .Render(). This changes the chart to the correct chart but it loses all color and many of the labels and headers. 

 

        FusionCharts.Charts.Chart myFusionChart = new FusionCharts.Charts.Chart
            ("msline", "myChart", "600", "350", "xml", xmlData.ToString()); // Initialize the chart.
        Literal1.Text = myFusionChart.Render();
 
I replace the middle line with one of the following two lines. 
 
            ("column2D", "myChart", "600", "350", "xml", xmlData.ToString()); //////Bar graph but it is not showing time periods at the bottom or color
 
             ("pie2d", "myChart", "600", "350", "xml", xmlData.ToString());//////Pie graph but it is not showing time periods or color
 
Not sure what I am doing wrong. Any help would be very much appreciated. 
 
Thank you,
Seth

Share this post


Link to post
Share on other sites

Hi,

 

Welcome to FusionCharts Forum!!!

 

As per your requirement, it seems that you want the chart type to change using ASP.NET wrapper.

 

So sharing a sample from our end having similar use case: https://www.dropbox.com/s/93tco8q9ud6p1zu/ASP.NET%20Sample_Dropdown.rar?dl=0

 

Check and confirm if it helps.

Edited by Vishalika

Share this post


Link to post
Share on other sites

Thank you for the example. Your example works when I leave the data hard coded into the string. However, I am struggling to get it to work with the data coming straight from the database. 
 
I noticed that the formatting for your string was much different than what I had. So I tried mine as well as yours and simply replaced the hardcoded parts with variables from the database. 
 
Below is my code reworked with your string formatting.
 
 public void getChart()

    {
        String data;
 
        data = "{\"chart\":{\"caption\":\"" + Label.Text + "\",\"xaxisname\":\"Period\",\"yaxisname\":\"Numbers\",\"subCaption:\"" + SubLabel.Text + "\",\"numberprefix\":\"$\",\"showvalues\":\"1\",\"animation\":\"0\"},";
 
        SqlConnection MySql = new SqlConnection(DatabaseConnectionString);
        SqlConnection MySql3 = new SqlConnection(DatabaseConnectionString);
 
        SqlCommand cmd = new SqlCommand("selectMultipleNpsScores " + PeriodType.SelectedValue + ", '" + StartDatepicker.SelectedValue + "', '" + endDatePicker.SelectedValue + "', '" + Questions.SelectedValue + "', '" + CalculationType.SelectedValue + "', 0", MySql);
        SqlCommand cmd2 = new SqlCommand("SelectQuestionTextByQuestionID '" + Questions.SelectedValue + "'", MySql2);
        SqlCommand cmd3 = new SqlCommand("selectMultipleNpsScores " + PeriodType.SelectedValue + ", '" + StartDatepicker.SelectedValue + "', '" + endDatePicker.SelectedValue + "', '" + Questions.SelectedValue + "', '" + CalculationType.SelectedValue + "', 1", MySql3);
        
        cmd.Connection.Open();
        cmd3.Connection.Open();
 
        SqlDataReader DBValues = cmd.ExecuteReader();
        SqlDataReader DBValues3 = cmd3.ExecuteReader();
 
        while (DBValues.Read() && DBValues3.Read())
        {
            data = data + "\"data\":[{\"label\":" + DBValues["description"].ToString() + "\",\"value\":\"" + DBValues3["actionValue"].ToString() + "\"},";
        }
        data = data + "],\"trendlines\":[{\"line\":[{\"startvalue\":\"700000\",\"istrendzone\":\"1\",\"valueonright\":\"1\",\"tooltext\":\"AYAN\",\"endvalue\":\"900000\",\"color\":\"009933\",\"displayvalue\":\"Target\",\"showontop\":\"1\",\"thickness\":\"5\"}]}],\"styles\":{\"definition\":[{\"name\":\"CanvasAnim\",\"type\":\"animation\",\"param\":\"_xScale\",\"start\":\"0\",\"duration\":\"1\"}],\"application\":[{\"toobject\":\"Canvas\",\"styles\":\"CanvasAnim\"}]}}";
        
        DBValues.Close();
        DBValues3.Close();
 
        FusionCharts.Charts.Chart column = new FusionCharts.Charts.Chart();
        column.SetChartParameter(FusionCharts.Charts.Chart.ChartParameter.chartId, "myChart");
        column.SetChartParameter(FusionCharts.Charts.Chart.ChartParameter.chartType, ChartType.SelectedValue);
        column.SetChartParameter(FusionCharts.Charts.Chart.ChartParameter.chartWidth, "600");
        column.SetChartParameter(FusionCharts.Charts.Chart.ChartParameter.chartHeight, "400");
        column.SetData(data, FusionCharts.Charts.Chart.DataFormat.xml);
 
        Literal1.Text = column.Render();
    }
 
 
 
 
 
Instead of loading the chart it simply puts up "Chart..."  and the page does not seem to actually be loading anything. 
Edited by sethm

Share this post


Link to post
Share on other sites

Also, I realized that even when I leave your hard coded string in the "Pie" option does not work. It loads the chart but the actual pie is not there. It just has some lines and labels. 

Share this post


Link to post
Share on other sites

Thank you Moonmi Sonowal for your response. That is actually where I referenced in creating my code. I used that page to create a working line chart but I am unable to convert it into any of the other graphs. When I try to it loses color and many of the labels. IS there something I am missing? 

 

The version I have above is basically what I had working before with your reference except I changed it to include the type of string that Vishalikas example used so that I could attempt to use the SetChartParameters() functions. 

Edited by sethm

Share this post


Link to post
Share on other sites

Just in case it is needed. Here is my code that I created using the same reference that Moonmi Sonowal referenced. Again, it works great for turning my database data into a linegraph but I am unable to convert it to any of the other graphs. 

 

    public void getLineChart()
    {
        StringBuilder xmlData = new StringBuilder(); //Create `xmlData` StringBuilder for storing data as string.
 
        xmlData.Append("<chart caption='" + Label.Text + "' subCaption='" + SubLabel.Text + "' showBorder='1' formatNumberScale='0' rotatelabels='1' showvalues='0'>");
 
        xmlData.AppendFormat("<categories>");  //Initialize the `<categories>` element.
 
        SqlConnection MySql = new SqlConnection(DatabaseConnectionString);
        SqlCommand cmd = new SqlCommand("selectMultipleNpsScores " + PeriodType.SelectedValue + ", '" + StartDatepicker.SelectedValue + "', '" + endDatePicker.SelectedValue + "', '" + Questions.SelectedValue + "', '" + CalculationType.SelectedValue + "', 0", MySql);
 
        cmd.Connection.Open();
 
        SqlDataReader DBValues = cmd.ExecuteReader();
 
        //Iterate through the data in the variable and add the periods as
        //labels to the `<category>` element. Append this data to the `xmlData` object.
        while (DBValues.Read())
        {
            xmlData.AppendFormat("<category label='{0}'/>", DBValues["description"].ToString());
        }
 
        DBValues.Close();
        xmlData.AppendFormat("</categories>");
 
        SqlCommand cmd2 = new SqlCommand("SelectQuestionTextByQuestionID '" + Questions.SelectedValue + "'", MySql);
 
        SqlDataReader DBValues2 = cmd2.ExecuteReader();
 
        SqlConnection MySql4 = new SqlConnection(DatabaseConnectionString);
        SqlCommand cmd4 = new SqlCommand("selectMultipleNpsScores " + PeriodType.SelectedValue + ", '" + StartDatepicker.SelectedValue + "', '" + endDatePicker.SelectedValue + "', '" + Questions.SelectedValue + "', '" + CalculationType.SelectedValue + "', 1", MySql4);
        
        cmd4.Connection.Open();
        SqlDataReader DBValues4 = cmd4.ExecuteReader();
 
        while (DBValues2.Read()) // Append this data to the `xmlData` object.
        {
            //these are the names of the lines
            xmlData.AppendFormat("<dataset seriesName='{0}'>", DBValues2["questionText"].ToString());
 
            while (DBValues4.Read())
            {
                xmlData.AppendFormat("<set value='{0}'/>", DBValues4["actionValue"].ToString()); //This is the data in the graph 
            }
            xmlData.AppendFormat("</dataset>");
        }
        DBValues4.Close();
        DBValues2.Close();
 
        xmlData.AppendFormat("</chart>"); //Close the `<chart>` element.
 
        FusionCharts.Charts.Chart myFusionChart = new FusionCharts.Charts.Chart
            ("msline", "myChart", "600", "350", "xml", xmlData.ToString()); // Initialize the chart.
        //("column2D", "myChart", "600", "350", "xml", xmlData.ToString()); //////Bar graph but it is not showing time periods at the bottom or color
        //("pie2d", "myChart", "600", "350", "xml", xmlData.ToString());//////Pie graph but it is not showing time periods or color
        Literal1.Text = myFusionChart.Render(); // Render the chart.
    }
Edited by sethm

Share this post


Link to post
Share on other sites

I actually am starting to think that it could have to do with the name of the chart such as ("msline" vs "line", or "column2d") I found that if I put "mscolumn2d" then I see the labels of the graph (however the color is still missing). Is a page that tells what chart names to use with specific syntax? 

Thank you again for all of your help! 

Share this post


Link to post
Share on other sites

I feel a bit foolish. It turns out that I just did not have a theme chosen for my charts. So that solves my overall issue.

However, pie charts are still blanked out when I change it to a pie chart. It is being created with them same code as the other charts and so it can not be the theme issue again.

 

Is there any reason why this might be? 

 

Thanks again! 

Edited by sethm

Share this post


Link to post
Share on other sites

I am still struggling with creating a Pie chart from a database. Does it need a different syntax perhaps for the string? I have been spending days on this and I feel like I am getting nowhere.

Any help would be very much appreciated. 

Thank you!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this