jFreechart将地图绘制到下一个绘图值(jFreechart Map plot to the next plot value)
我是jfreechart的新手,我无法按顺序绘制值。 我有一系列数字,每个数字超过6个十进制值例如:(5.981412023,2636.51824),从+6.00000000到-6.00000000不等。 这些值取自excel表,它有一个图形(xy散射类型),它看起来与jfreechart创建的不同。 我发现这些值并没有按照我给出的顺序绘制,而是排列和绘制。 例如:如果我给出了像(8,6,2,9,4,7,5)这样的序列,那么该图就会被排列,然后该线看起来就像它所绘制的序列那样(2,4,5,6, 7,8,9)。
有什么方法可以在插入的一系列图中绘制它吗? 抱歉我的英语。
例:
package test; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.ui.ApplicationFrame; public class PlotTest { private XYSeriesCollection dataset; public static void main (String[] args) { new PlotTest(); } public PlotTest () { dataset = new XYSeriesCollection(); XYSeries data = new XYSeries("data"); data.add(3, 2); //Point 1 data.add(1, 1); //Point 2 data.add(4, 1); //Point 3 data.add(2, 2); //Point 4 dataset.addSeries(data); showGraph(); } private void showGraph() { final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); final ApplicationFrame frame = new ApplicationFrame("Title"); frame.setContentPane(chartPanel); frame.pack(); frame.setVisible(true); } private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createScatterPlot( "Title", // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); plot.setRenderer(renderer); return chart; } }
基于上面的例子,我希望程序以1-2-3-4的顺序连接点,这是我将它们添加到我的数据集的顺序。 但是我按照2-4的顺序将它们连接起来,按x值排序。
I am new to jfreechart and i am having trouble plotting the values in sequence. i have series of numbers with each one having more than 6 decimal values example:(5.981412023,2636.51824) and varying from +6.00000000 to -6.00000000. The values are taken from excel sheet and it has a graph(xy scatter type), which doesn't look similar to the one created by jfreechart. I found out that the values are not plotted in the sequence which i gave but its arranged and plotted. example: if i gave the sequence like (8,6,2,9,4,7,5), the plot is arranged and then the line looks like its plotted to this arranged sequence like (2,4,5,6,7,8,9).
Is there any way i can plot it in a sequence of the plots inserted ? sorry about my English.
Example:
package test; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.ui.ApplicationFrame; public class PlotTest { private XYSeriesCollection dataset; public static void main (String[] args) { new PlotTest(); } public PlotTest () { dataset = new XYSeriesCollection(); XYSeries data = new XYSeries("data"); data.add(3, 2); //Point 1 data.add(1, 1); //Point 2 data.add(4, 1); //Point 3 data.add(2, 2); //Point 4 dataset.addSeries(data); showGraph(); } private void showGraph() { final JFreeChart chart = createChart(dataset); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); final ApplicationFrame frame = new ApplicationFrame("Title"); frame.setContentPane(chartPanel); frame.pack(); frame.setVisible(true); } private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createScatterPlot( "Title", // chart title "X", // x axis label "Y", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesLinesVisible(0, true); plot.setRenderer(renderer); return chart; } }
Based on the above example, I want the program to connect the dots in order 1-2-3-4, which is the order I added them to my dataset. But I do get them connected in order 2-4-1-3, sorted by x-value.
原文:https://stackoverflow.com/questions/30593813
最满意答案
您不在两个操作中都设置
@company
实例变量。 你可以使用before_filter
来做,像这样:before_filter :find_company def change_settings @vacation_days = current_company.vacation_days @illnes_days = current_company.illnes_days end def update_settings if @company.update(company_params) redirect_to account_company_path, notice: t('company.settings_changed') else render action: 'change_settings' end end private def company_params params.require(:company).permit(:vacation_days, :illnes_days) end def find_company @company = current_company end
You don't set
@company
instance variable in both your actions. You can do it usingbefore_filter
, like this:before_filter :find_company def change_settings @vacation_days = current_company.vacation_days @illnes_days = current_company.illnes_days end def update_settings if @company.update(company_params) redirect_to account_company_path, notice: t('company.settings_changed') else render action: 'change_settings' end end private def company_params params.require(:company).permit(:vacation_days, :illnes_days) end def find_company @company = current_company end
相关问答
更多-
Ruby on Rails:将参数从其他控制器传递给模型(Ruby on Rails: passing parameters from other controllers to a model)[2023-05-10]
fields_for通常用于将params分配给相关模型,因此它对数据结构做出了一些特定的假设。 如果模型中有profile属性,则可以将profile参数作为params [:user]集合的一部分,这将正确分配属性。 您可以通过命名字段来执行此操作: text_field_tag(user[profile], "val") text_field_tag(user[profile][name], "val") fields_for is generally used for assigning p ... -
自定义RegistrationsController class RegistrationsController < Devise::RegistrationsController private def sign_up_params params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation) end def account_update_par ...
-
如果所有这些过滤器都在params的subhash中,你可以迭代而不包括不需要的参数(例如:action rails和:controller rails添加的:controller参数),这将最有效。 一旦你做完了,你就可以做到 (params[:filters] || {}).inject(Student.all) do |scope, (key, value)| scope.where(key => value) end This will work best if all of these fi ...
-
您不在两个操作中都设置@company实例变量。 你可以使用before_filter来做,像这样: before_filter :find_company def change_settings @vacation_days = current_company.vacation_days @illnes_days = current_company.illnes_days end def update_settings if @company.update(company_para ...
-
Rails params属性 - 使用控制器中的params字段(Rails params attributes - using the params fields in the controller)[2022-06-09]
我会建议更好地修复窗体视图,在这里添加这些数字: <%= link_to_add_association "Add another", f, :ads %> <%= f.fields_for :ads do |ff| %> <%= ff.form_group ::remote do |ad| %> <%= ad.label :remote %> * <%= ad.text_field :remote %> <% end %> <%= ... -
把这样的东西添加到你的application_controller.rb : before_action :store_ref private def store_ref cookies[:ref] = params[:ref] if params[:ref].present? end 像这样的东西给你的用户创建操作: def create @user = User.new(user_params) @user.ref = cookies[:ref] if @user.save ...
-
您正在关注一个处理更复杂案例的示例(您将同一个表连接两次)并且您的解决方案比它需要的更复杂: class User has_many :subscriptions has_many :conferances, though: :subscriptions def subscribed_to?(conference) conferances.include?(conference) end def find_subscription(conference) subscr ...
-
Rails params解释(Rails params explain)[2022-08-20]
嗯, params是一系列key-value对,来自带有页面请求的浏览器。 对于HTTP GET请求, params在URL中编码。 对于这样的请求: http://www.example.com/?foo=1&bar=cat params[:foo]将是"1"而params[:bar]将是"cat" 。 在HTTP/HTML , params实际上只是一系列key-value对,其中key和value是字符串,但Rails有一个特殊的语法,使params成为哈希内部哈希。 对于这样的请求: http:/ ... -
params看起来像一个哈希,但它确实不是。 因此,如果您在处理控制器中的传入数据时需要“增加”参数,请创建一个包含params或其成员的新数据结构。 添加: 也许你在寻找 @codes=Code.get_codes @all = [] for c in @codes @all << params["group_#{c.name}"] end params looks like a hash, but it really isn't. So if you need to "augment" p ...
-
这里有什么问题,你是通过id找到你正在使用find,并且你正在传递applyjobid所以你必须使用find_by_applyjobid 试试这个 def show @jobdetail = Jobdescription.find_by_applyjobid(params[:applyjobid]) end What's wrong here is you are finding by id as you are using find, and you are passing applyjobid ...